/[thuban]/branches/WIP-pyshapelib-bramz/test/test_load.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/test_load.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1976 by bh, Tue Nov 25 14:26:08 2003 UTC revision 2688 by frank, Fri Jun 30 12:27:20 2006 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002, 2003 by Intevation GmbH  # Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 16  files created by Thuban 0.2. Line 16  files created by Thuban 0.2.
16  Maintenance of the test cases:  Maintenance of the test cases:
17    
18  When during a development period the file format is changed with respect  When during a development period the file format is changed with respect
19  to the last released version for the first, the tests here should be  to the last released version for the first time, the tests here should
20  copied to the version specific test file. The round-trip tests which  be copied to the version specific test file.  The round-trip tests which
21  save the session again and compare the XML files should not be copied  save the session again and compare the XML files should not be copied
22  over as they only make sense here to make sure th that the files checked  over as they only make sense here to make sure th that the files checked
23  here are actually ones that may have been written by the current thuban  here are actually ones that may have been written by the current thuban
# Line 40  from xmlsupport import sax_eventlist Line 40  from xmlsupport import sax_eventlist
40  import dbflib  import dbflib
41  import shapelib  import shapelib
42    
43    from Thuban import internal_from_unicode
44  from Thuban.Model.save import save_session  from Thuban.Model.save import save_session
45  from Thuban.Model.load import load_session, parse_color, LoadError, \  from Thuban.Model.load import load_session, parse_color, LoadError, \
46       LoadCancelled       LoadCancelled
47  from Thuban.Model.color import Transparent  from Thuban.Model.color import Transparent
48  from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\  from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\
49      ClassGroupSingleton, ClassGroupDefault      ClassGroupSingleton, ClassGroupPattern, ClassGroupDefault
50  from Thuban.Model.postgisdb import ConnectionError  from Thuban.Model.postgisdb import ConnectionError
51  from Thuban.Model.table import DBFTable, MemoryTable, \  from Thuban.Model.table import DBFTable, MemoryTable, \
52       FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \       FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \
53       table_to_dbf       table_to_dbf
54    from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
55         ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE
56    
57  def filenames_equal(name1, name2):  def filenames_equal(name1, name2):
58      """Return true if the filenames name1 and name2 are equal.      """Return true if the filenames name1 and name2 are equal.
# Line 87  class LoadSessionTest(support.FileLoadTe Line 89  class LoadSessionTest(support.FileLoadTe
89          self.session = None          self.session = None
90    
91    
92      dtd = "http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"      dtd = "http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
93      thubanids = [((dtd, n), (None, "id")) for n in      thubanids = [((dtd, n), (None, "id")) for n in
94                   ["fileshapesource", "filetable", "jointable",                   ["fileshapesource", "filetable", "jointable",
95                    "derivedshapesource"]]                    "derivedshapesource"]]
# Line 97  class LoadSessionTest(support.FileLoadTe Line 99  class LoadSessionTest(support.FileLoadTe
99                       ("jointable", "right"),                       ("jointable", "right"),
100                       ("derivedshapesource", "table"),                       ("derivedshapesource", "table"),
101                       ("derivedshapesource", "shapesource")]]                       ("derivedshapesource", "shapesource")]]
102      filenames = [((dtd, n), (None, m)) for n, m in  
103                   [("fileshapesource", "filename"),      # The filenames in the tests should be understandable on all
104                    ("rasterlayer", "filename"),      # currently supported platforms so filenames is an empty list
105                    ("filetable", "filename")]]      filenames = []
106    
107      del n, m, dtd      del n, m, dtd
108    
109      def check_format(self):      def check_format(self):
# Line 121  class LoadSessionTest(support.FileLoadTe Line 124  class LoadSessionTest(support.FileLoadTe
124                  print a != b and "***************" or ""                  print a != b and "***************" or ""
125                  print a                  print a
126                  print b                  print b
127    
128          self.assertEquals(el1, el2,          self.assertEquals(el1, el2,
129                            "loaded file not equivalent to the saved file")                            "loaded file not equivalent to the saved file")
130    
# Line 159  class ClassificationTest(LoadSessionTest Line 163  class ClassificationTest(LoadSessionTest
163                  props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1])                  props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1])
164                  props.SetFill(                  props.SetFill(
165                      parse_color(data[CLASSES][i][GROUP_PROPS][2]))                      parse_color(data[CLASSES][i][GROUP_PROPS][2]))
166                    if len(data[CLASSES][i][GROUP_PROPS]) > 3:
167                        props.SetSize(data[CLASSES][i][GROUP_PROPS][3])
168    
169                  if data[CLASSES][i][GROUP_TYPE] == "default":                  if data[CLASSES][i][GROUP_TYPE] == "default":
170                      g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL])                      g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL])
# Line 169  class ClassificationTest(LoadSessionTest Line 175  class ClassificationTest(LoadSessionTest
175                  elif data[CLASSES][i][GROUP_TYPE] == "single":                  elif data[CLASSES][i][GROUP_TYPE] == "single":
176                      g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA],                      g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA],
177                                            props, data[CLASSES][i][GROUP_LABEL])                                            props, data[CLASSES][i][GROUP_LABEL])
178                    elif data[CLASSES][i][GROUP_TYPE] == "pattern":
179                        g = ClassGroupPattern(data[CLASSES][i][GROUP_DATA],
180                                              props, data[CLASSES][i][GROUP_LABEL])
181    
182                  eq(group, g)                  eq(group, g)
183    
# Line 182  class TestSingleLayer(LoadSessionTest): Line 191  class TestSingleLayer(LoadSessionTest):
191      # want to test whether the loading code handles that correctly.      # want to test whether the loading code handles that correctly.
192      file_contents = '''\      file_contents = '''\
193  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
194  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
195  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
196          title="Stra\xc3\x9fen &amp; Landmarken">          title="Stra\xc3\x9fen &amp; Landmarken">
197      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
198          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 195  class TestSingleLayer(LoadSessionTest): Line 204  class TestSingleLayer(LoadSessionTest):
204              <parameter value="units=m"/>              <parameter value="units=m"/>
205              <parameter value="zone=27"/>              <parameter value="zone=27"/>
206          </projection>          </projection>
207          <layer shapestore="D1" visible="true"          <layer shapestore="D1" visible="true" title="K\xc3\xbcste">
208                  stroke="#000000" title="K\xc3\xbcste" stroke_width="1"              <classification>
209                  fill="None"/>                  <clnull label="">
210                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
211                    </clnull>
212                </classification>
213            </layer>
214      </map>      </map>
215  </session>  </session>
216  '''  '''
# Line 209  class TestSingleLayer(LoadSessionTest): Line 222  class TestSingleLayer(LoadSessionTest):
222          self.session = session          self.session = session
223    
224          # Check the title          # Check the title
225          eq(session.Title(), "Stra\xdfen & Landmarken")          eq(session.Title(), internal_from_unicode(u"Stra\xdfen & Landmarken"))
226    
227          # the session has one map.          # the session has one map.
228          maps = session.Maps()          maps = session.Maps()
# Line 217  class TestSingleLayer(LoadSessionTest): Line 230  class TestSingleLayer(LoadSessionTest):
230    
231          # Check the map's attributes          # Check the map's attributes
232          map = maps[0]          map = maps[0]
233          eq(map.Title(), "\xdcbersicht")          eq(map.Title(), internal_from_unicode(u"\xdcbersicht"))
234          proj = map.GetProjection()          proj = map.GetProjection()
235          eq(proj.GetName(), "WGS 84 / UTM zone 27N")          eq(proj.GetName(), "WGS 84 / UTM zone 27N")
236          eq(proj.EPSGCode(), "32627")          eq(proj.EPSGCode(), "32627")
# Line 232  class TestSingleLayer(LoadSessionTest): Line 245  class TestSingleLayer(LoadSessionTest):
245    
246          # Check the layer attributes          # Check the layer attributes
247          layer = layers[0]          layer = layers[0]
248          eq(layer.Title(), "K\xfcste")          eq(layer.Title(), internal_from_unicode(u"K\xfcste"))
249          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),          self.failUnless(filenames_equal(layer.ShapeStore().FileName(),
250                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
251                                                       os.pardir, os.pardir,                                                       os.pardir, os.pardir,
# Line 274  class TestNonAsciiColumnName(LoadSession Line 287  class TestNonAsciiColumnName(LoadSession
287    
288      file_contents = '''\      file_contents = '''\
289  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
290  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
291  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
292          title="Non ASCII column name test">          title="Non ASCII column name test">
293      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
294          filename="TestNonAsciiColumnName.shp"/>          filename="TestNonAsciiColumnName.shp"/>
# Line 287  class TestNonAsciiColumnName(LoadSession Line 300  class TestNonAsciiColumnName(LoadSession
300              <parameter value="units=m"/>              <parameter value="units=m"/>
301              <parameter value="zone=27"/>              <parameter value="zone=27"/>
302          </projection>          </projection>
303          <layer shapestore="D1" visible="true"          <layer shapestore="D1" visible="true" title="layer">
                 stroke="#000000" title="layer" stroke_width="1"  
                 fill="None">  
304              <classification field="Fl\xc3\xa4che" field_type="double">              <classification field="Fl\xc3\xa4che" field_type="double">
305                  <clnull label="">                  <clnull label="">
306                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
# Line 351  class TestLayerVisibility(LoadSessionTes Line 362  class TestLayerVisibility(LoadSessionTes
362    
363      file_contents = '''\      file_contents = '''\
364  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
365  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
366  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
367          title="single map&amp;layer">          title="single map&amp;layer">
368      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
369          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 362  class TestLayerVisibility(LoadSessionTes Line 373  class TestLayerVisibility(LoadSessionTes
373              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
374              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
375          </projection>          </projection>
376          <layer shapestore="D1" visible="false" stroke="#000000"          <layer shapestore="D1" visible="false" title="My Layer">
377                  title="My Layer" stroke_width="1" fill="None"/>              <classification>
378                    <clnull label="">
379                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
380                    </clnull>
381                </classification>
382            </layer>
383      </map>      </map>
384  </session>  </session>
385  '''  '''
# Line 385  class TestLayerVisibility(LoadSessionTes Line 401  class TestLayerVisibility(LoadSessionTes
401          self.check_format()          self.check_format()
402    
403    
404    class TestSymbolSize(ClassificationTest):
405    
406        file_contents = '''\
407    <?xml version="1.0" encoding="UTF-8"?>
408    <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
409    <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session">
410        <fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/>
411        <map title="Iceland map">
412            <layer title="cultural_landmark-point" shapestore="D813968480" visible="true">
413                <classification field="CLPTLABEL" field_type="string">
414                    <clnull label="">
415                        <cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/>
416                    </clnull>
417                    <clpoint label="" value="RUINS">
418                        <cldata stroke="#000000" stroke_width="1" size="6" fill="#ffffff"/>
419                    </clpoint>
420                    <clpoint label="" value="FARM">
421                        <cldata stroke="#000000" stroke_width="1" size="9" fill="#ffff00"/>
422                    </clpoint>
423                </classification>
424            </layer>
425        </map>
426    </session>
427    '''
428    
429        def test(self):
430            """Test that the size attribute for point symbols is correctly
431            loaded for a layer."""
432            eq = self.assertEquals
433            session = load_session(self.filename())
434            self.session = session
435    
436            map = session.Maps()[0] # only one map in the sample
437    
438            expected = [("cultural_landmark-point", 2,
439                            [("default", (), "",
440                                ("#000000", 1, "#000000", 3)),
441                             ("single", "RUINS", "",
442                                ("#000000", 1, "#ffffff", 6)),
443                             ("single", "FARM", "",
444                                ("#000000", 1, "#ffff00", 9))])]
445    
446            self.TestLayers(map.Layers(), expected)
447    
448            self.check_format()
449    
450    
451  class TestClassification(ClassificationTest):  class TestClassification(ClassificationTest):
452    
453      file_contents = '''\      file_contents = '''\
454  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
455  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
456  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
457          title="single map&amp;layer">          title="single map&amp;layer">
458      <fileshapesource filetype="shapefile" id="D138389860"      <fileshapesource filetype="shapefile" id="D138389860"
459          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
460      <fileshapesource filetype="shapefile" id="D138504492"      <fileshapesource filetype="shapefile" id="D138504492"
461          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
462        <fileshapesource filetype="shapefile" id="D123456789"
463            filename="../../Data/iceland/cultural_landmark-point.shp"/>
464      <map title="Test Map">      <map title="Test Map">
465          <projection name="">          <projection name="">
466              <parameter value="zone=26"/>              <parameter value="zone=26"/>
467              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
468              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
469          </projection>          </projection>
470          <layer shapestore="D138389860" visible="true" stroke="#000000"          <layer shapestore="D138389860" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
471              <classification field="POPYREG" field_type="string">              <classification field="POPYREG" field_type="string">
472                  <clnull label="">                  <clnull label="">
473                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
# Line 420  class TestClassification(ClassificationT Line 484  class TestClassification(ClassificationT
484                  </clpoint>                  </clpoint>
485              </classification>              </classification>
486          </layer>          </layer>
487          <layer shapestore="D138504492" visible="true" stroke="#000000"          <layer shapestore="D138504492" visible="true" title="My Layer 2">
                 title="My Layer 2" stroke_width="2" fill="None">  
488              <classification field="AREA" field_type="double">              <classification field="AREA" field_type="double">
489                  <clnull label="">                  <clnull label="">
490                      <cldata stroke="#000000" stroke_width="2" fill="None"/>                      <cldata stroke="#000000" stroke_width="2" fill="None"/>
# Line 440  class TestClassification(ClassificationT Line 503  class TestClassification(ClassificationT
503                  </clpoint>                  </clpoint>
504              </classification>              </classification>
505          </layer>          </layer>
506            <layer shapestore="D123456789" visible="true" title="My Layer 3">
507                <classification field="CLPTLABEL" field_type="string">
508                    <clnull label="">
509                        <cldata stroke="#000000" size="5" stroke_width="2" fill="None"/>
510                    </clnull>
511                    <clpoint label="" value="FARM">
512                        <cldata stroke="#111111" size="5" stroke_width="1" fill="None"/>
513                    </clpoint>
514                    <clpattern label="" pattern="BUI">
515                        <cldata stroke="#000000" size="5" stroke_width="1" fill="None"/>
516                    </clpattern>
517                </classification>
518            </layer>
519      </map>      </map>
520  </session>  </session>
521  '''  '''
# Line 458  class TestClassification(ClassificationT Line 534  class TestClassification(ClassificationT
534                              ("#000000", 2, "None")),                              ("#000000", 2, "None")),
535                           ("single", "1", "",                           ("single", "1", "",
536                              ("#000000", 10, "None")),                              ("#000000", 10, "None")),
537                           ("single", "\xe4\xf6\xfc", "\xdcml\xe4uts",                           ("single", internal_from_unicode(u"\xe4\xf6\xfc"),
538                              internal_from_unicode(u"\xdcml\xe4uts"),
539                              ("#000000", 1, "None"))]),                              ("#000000", 1, "None"))]),
540                       ("My Layer 2", 4,                       ("My Layer 2", 4,
541                           [("default", (), "",                           [("default", (), "",
# Line 470  class TestClassification(ClassificationT Line 547  class TestClassification(ClassificationT
547                            ("range", (-1, 0), "",                            ("range", (-1, 0), "",
548                              ("#000000", 1, "None")),                              ("#000000", 1, "None")),
549                            ("single", -.5, "",                            ("single", -.5, "",
550                              ("#000000", 1, "None"))])]                              ("#000000", 1, "None"))]),
551                         ("My Layer 3", 2,
552                             [("default", (), "",
553                                ("#000000", 2, "None")),
554                              ("single", "FARM", "",
555                                ("#111111", 1, "None")),
556                              ("pattern", "BUI", "",
557                                ("#000000", 1, "None"))]),
558                        ]
559    
560          self.TestLayers(map.Layers(), expected)          self.TestLayers(map.Layers(), expected)
561    
# Line 481  class TestLabels(ClassificationTest): Line 566  class TestLabels(ClassificationTest):
566    
567      file_contents = '''\      file_contents = '''\
568  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
569  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
570  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
571          title="single map&amp;layer">          title="single map&amp;layer">
572      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
573          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 492  class TestLabels(ClassificationTest): Line 577  class TestLabels(ClassificationTest):
577              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
578              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
579          </projection>          </projection>
580          <layer shapestore="D1" visible="true" stroke="#000000"          <layer shapestore="D1" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
581              <classification field="POPYREG" field_type="string">              <classification field="POPYREG" field_type="string">
582                  <clnull label="hallo">                  <clnull label="hallo">
583                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
# Line 529  class TestLayerProjection(LoadSessionTes Line 613  class TestLayerProjection(LoadSessionTes
613    
614      file_contents = '''\      file_contents = '''\
615  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
616  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
617  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
618          title="single map&amp;layer">          title="single map&amp;layer">
619      <fileshapesource filetype="shapefile" id="D2"      <fileshapesource filetype="shapefile" id="D2"
620          filename="../../Data/iceland/roads-line.shp"/>          filename="../../Data/iceland/roads-line.shp"/>
# Line 542  class TestLayerProjection(LoadSessionTes Line 626  class TestLayerProjection(LoadSessionTes
626              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
627              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
628          </projection>          </projection>
629          <layer shapestore="D4" visible="true" stroke="#000000"          <layer shapestore="D4" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
630              <projection name="hello">              <projection name="hello">
631                  <parameter value="zone=13"/>                  <parameter value="zone=13"/>
632                  <parameter value="proj=tmerc"/>                  <parameter value="proj=tmerc"/>
# Line 558  class TestLayerProjection(LoadSessionTes Line 641  class TestLayerProjection(LoadSessionTes
641                  </clpoint>                  </clpoint>
642              </classification>              </classification>
643          </layer>          </layer>
644          <layer shapestore="D2" visible="true" stroke="#000000"          <layer shapestore="D2" visible="true" title="My Layer">
                 title="My Layer" stroke_width="1" fill="None">  
645              <projection name="Unknown">              <projection name="Unknown">
646                  <parameter value="proj=lcc"/>                  <parameter value="proj=lcc"/>
647                  <parameter value="lat_1=10"/>                  <parameter value="lat_1=10"/>
648                  <parameter value="lat_2=20"/>                  <parameter value="lat_2=20"/>
649                  <parameter value="ellps=clrk66"/>                  <parameter value="ellps=clrk66"/>
650              </projection>              </projection>
651                <classification>
652                    <clnull label="">
653                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
654                    </clnull>
655                </classification>
656          </layer>          </layer>
657      </map>      </map>
658  </session>  </session>
# Line 607  class TestRasterLayer(LoadSessionTest): Line 694  class TestRasterLayer(LoadSessionTest):
694    
695      file_contents = '''\      file_contents = '''\
696  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
697  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
698  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
699          title="single map&amp;layer">          title="single map&amp;layer">
700      <map title="Test Map">      <map title="Test Map">
701          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"
702                  title="My RasterLayer"/>                  title="My RasterLayer" opacity="0.4" masktype="alpha"/>
703      </map>      </map>
704  </session>  </session>
705  '''  '''
# Line 629  class TestRasterLayer(LoadSessionTest): Line 716  class TestRasterLayer(LoadSessionTest):
716          layer = map.Layers()[0] # one layer in the sample          layer = map.Layers()[0] # one layer in the sample
717    
718          eq(layer.Title(), "My RasterLayer")          eq(layer.Title(), "My RasterLayer")
719            eq(layer.Opacity(), 0.4)
720            eq(layer.MaskType(), layer.MASK_ALPHA)
721    
722          self.failIf(layer.Visible())          self.failIf(layer.Visible())
723          self.failUnless(filenames_equal(layer.GetImageFilename(),          self.failUnless(filenames_equal(layer.GetImageFilename(),
724                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
# Line 641  class TestRasterLayer(LoadSessionTest): Line 731  class TestRasterLayer(LoadSessionTest):
731  class TestJoinedTable(LoadSessionTest):  class TestJoinedTable(LoadSessionTest):
732    
733      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
734  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
735  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" title="A Joined Table session">  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="A Joined Table session">
736      <fileshapesource filetype="shapefile" id="D137227612"      <fileshapesource filetype="shapefile" id="D137227612"
737          filename="../../Data/iceland/roads-line.shp"/>          filename="../../Data/iceland/roads-line.shp"/>
738      <filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140"      <filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140"
# Line 654  class TestJoinedTable(LoadSessionTest): Line 744  class TestJoinedTable(LoadSessionTest):
744      <derivedshapesource table="D136169900" shapesource="D137227612"      <derivedshapesource table="D136169900" shapesource="D137227612"
745          id="D136170932"/>          id="D136170932"/>
746      <map title="Test Map">      <map title="Test Map">
747          <layer shapestore="D136170932" visible="true" stroke="#000000"          <layer shapestore="D136170932" visible="true" title="My Layer">
748                  title="My Layer" stroke_width="1" fill="None"/>              <classification>
749                    <clnull label="">
750                        <cldata stroke="#000000" stroke_width="1" fill="None"/>
751                    </clnull>
752                </classification>
753            </layer>
754      </map>      </map>
755  </session>  </session>
756  '''  '''
# Line 686  class TestJoinedTable(LoadSessionTest): Line 781  class TestJoinedTable(LoadSessionTest):
781          self.check_format()          self.check_format()
782    
783    
784    class TestLabelLayer(LoadSessionTest):
785    
786        # Note that the labels deliberately contain non-ascii characters to
787        # test whether they're supported correctly.
788    
789        file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
790    <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
791    <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session">
792        <fileshapesource filetype="shapefile" id="D145265052"
793            filename="../../Data/iceland/political.shp"/>
794        <fileshapesource filetype="shapefile" id="D145412868"
795            filename="../../Data/iceland/cultural_landmark-point.shp"/>
796        <map title="Iceland map">
797            <projection name="Unknown">
798                <parameter value="zone=26"/>
799                <parameter value="proj=utm"/>
800                <parameter value="ellps=clrk66"/>
801            </projection>
802            <layer shapestore="D145265052" visible="true" title="political">
803                <projection name="Geographic">
804                    <parameter value="proj=latlong"/>
805                    <parameter value="to_meter=0.017453"/>
806                    <parameter value="ellps=clrk66"/>
807                </projection>
808                <classification>
809                    <clnull label="">
810                        <cldata stroke="#000000" stroke_width="1" fill="#c0c0c0"/>
811                    </clnull>
812                </classification>
813            </layer>
814            <layer shapestore="D145412868" visible="true" title="landmarks">
815                <projection name="Geographic">
816                    <parameter value="proj=latlong"/>
817                    <parameter value="to_meter=0.017453"/>
818                    <parameter value="ellps=clrk66"/>
819                </projection>
820                <classification>
821                    <clnull label="">
822                        <cldata size="5" stroke="#000000" stroke_width="1" fill="#ffff00"/>
823                    </clnull>
824                </classification>
825            </layer>
826            <labellayer>
827                <label x="-21.5" y="64.25" text="RUINS"
828                    halign="left" valign="center"/>
829                <label x="-15.125" y="64.75" text="H\xc3\xbctte"
830                    halign="right" valign="top"/>
831            </labellayer>
832        </map>
833    </session>
834    '''
835    
836        def test(self):
837            """Test loading a session with a label layer"""
838            session = load_session(self.filename())
839            self.session = session
840    
841            label_layer = self.session.Maps()[0].LabelLayer()
842            expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),
843                               (-15.125, 64.75, internal_from_unicode(u"H\xfctte"),
844                                ALIGN_RIGHT, ALIGN_TOP),
845                               ]
846            for label, values in zip(label_layer.Labels(), expected_labels):
847                self.assertEquals((label.x, label.y, label.text, label.halign,
848                                   label.valign),
849                                  values)
850            self.check_format()
851    
852    
853  class TestPostGISLayer(LoadSessionTest):  class TestPostGISLayer(LoadSessionTest):
854    
855      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
856  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
857  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
858          title="unnamed session">          title="unnamed session">
859      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"
860          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>
861      <dbshapesource tablename="landmarks" id="D143149420" dbconn="D142684948"/>      <dbshapesource id="D143149420" dbconn="D142684948"
862            tablename="landmarks_point_id" id_column="point_id"
863            geometry_column="the_geom" />
864      <map title="unnamed map">      <map title="unnamed map">
865          <layer shapestore="D143149420" visible="true" stroke="#000000"          <layer shapestore="D143149420" visible="true" stroke="#000000"
866                  title="landmarks" stroke_width="1" fill="None"/>                  title="landmarks" stroke_width="1" fill="None"/>
# Line 739  class TestPostGISLayer(LoadSessionTest): Line 904  class TestPostGISLayer(LoadSessionTest):
904  class TestPostGISLayerPassword(LoadSessionTest):  class TestPostGISLayerPassword(LoadSessionTest):
905    
906      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
907  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
908  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
909          title="unnamed session">          title="unnamed session">
910      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"
911          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>
# Line 834  class TestLoadError(LoadSessionTest): Line 999  class TestLoadError(LoadSessionTest):
999    
1000      file_contents = '''\      file_contents = '''\
1001  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
1002  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
1003  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
1004          title="single map&amp;layer">          title="single map&amp;layer">
1005      <fileshapesource id="D1" filename="../../Data/iceland/political.shp"/>      <fileshapesource id="D1" filename="../../Data/iceland/political.shp"/>
1006      <map title="Test Map">      <map title="Test Map">
# Line 862  class TestLoadError(LoadSessionTest): Line 1027  class TestLoadError(LoadSessionTest):
1027              # LoadError really was about the missing attribute              # LoadError really was about the missing attribute
1028              self.assertEquals(str(value),              self.assertEquals(str(value),
1029                "Element "                "Element "
1030                "(u'http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd',"                "(u'http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd',"
1031                " u'fileshapesource') requires an attribute 'filetype'")                " u'fileshapesource') requires an attribute 'filetype'")
1032          else:          else:
1033              self.fail("Missing filetype attribute doesn't raise LoadError")              self.fail("Missing filetype attribute doesn't raise LoadError")
1034    
1035    class Shapefile_CallBack:
1036    
1037        def __init__(self, params):
1038            """Initialize the callback return values.
1039              
1040               params must be a dictionary of the potential CB modes (keys),
1041               with lists of tuples of return values as values.
1042               Depending on the test the callback can be called multiple,
1043               each time a return value is poped from the list
1044            """
1045    
1046            self.params = params
1047    
1048    
1049        def s_cb(self, filename, mode = None, second_try= 0):
1050            if self.params.has_key(mode):
1051                return self.params[mode].pop(0)
1052            else:
1053                raise LoadError
1054            
1055    class TestAltPath(LoadSessionTest):
1056    
1057        """Test the various cases in the alternative path feature.
1058    
1059           The test checks the reasonable cases:
1060           - First recognition of a path error, fixed with user interaction.
1061           - First recognition of a path error, load cancelled.
1062           - Path error fixed from list, confirmed by user.
1063           - Path error fixed from list, changed by user.
1064           - Path error fixed from list, cancelled by user.
1065           - Path error wrongly fixed from list, manual fix forced.
1066        """
1067    
1068        file_contents = '''\
1069    <?xml version="1.0" encoding="UTF-8"?>
1070    <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
1071    <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="AltPath Test session">
1072        <fileshapesource filetype="shapefile" id="D1108450956" filename="../../Data/iceland/political.shp"/>
1073        <fileshapesource filetype="shapefile" id="D1108900076" filename="../Data/iceland/roads-line.shp"/>
1074        <fileshapesource filetype="shapefile" id="D1108947244" filename="../../Data/iceland/cultural_landmark-point.shp"/>
1075        <map title="not the iceland map">
1076            <layer title="political" stroke_width="1" shapestore="D1108450956" visible="true" stroke="#000000" fill="#c0c0c0"/>
1077            <layer title="roads-line" stroke_width="1" shapestore="D1108900076" visible="true" stroke="#000000" fill="None"/>
1078            <layer title="something else" stroke_width="1" shapestore="D1108947244" visible="true" stroke="#000000" fill="None"/>
1079        </map>
1080    </session>
1081    '''
1082    
1083        def checkSession(self, session):
1084            """Check if session has been loaded successfully."""
1085            
1086            eq = self.assertEquals
1087    
1088            map = session.Maps()[0]
1089            layers = map.Layers()
1090    
1091            eq("AltPath Test session", session.Title())
1092            eq("not the iceland map", map.Title())
1093            eq(3,len(layers))
1094            eq("political",layers[0].Title())
1095            eq("roads-line",layers[1].Title())
1096            eq("something else",layers[2].Title())
1097    
1098        def test_01_single_path_error_fix(self):
1099            """Test single file path error fix."""
1100            # The usual initial case
1101            s_cb = Shapefile_CallBack({
1102                        "search": [("../Data/iceland/roads-line.shp",0)],
1103                        "check": [(None, None)]})
1104            self.session = load_session(self.filename(),
1105                                        shapefile_callback =s_cb.s_cb)
1106            self.checkSession(self.session)
1107            
1108        def test_02_path_error_fix_from_list(self):
1109            """Test single file path error fix."""
1110            # This represents the usual case for "from_list"
1111            s_cb = Shapefile_CallBack({
1112                    "search": [("../Data/iceland/roads-line.shp",1)],
1113                    "check": [(os.path.abspath("../Data/iceland/roads-line.shp"),1)]
1114                   })
1115            self.session = load_session(self.filename(),
1116                                        shapefile_callback =s_cb.s_cb)
1117            self.checkSession(self.session)
1118    
1119        def test_03_single_path_error_cancelled(self):
1120            """Test alternative path cancelled."""
1121            s_cb = Shapefile_CallBack({
1122                        "search": [(None,0)],
1123                        "check": [(None, None)]})
1124            self.assertRaises(LoadCancelled,
1125                                load_session, self.filename(), None, s_cb.s_cb)
1126    
1127        def test_04_path_error_fix_from_list_cancelled(self):
1128            """Test alternative path from list cancelled."""
1129            s_cb = Shapefile_CallBack({
1130                    "search": [("../Data/iceland/roads-line.shp",1)],
1131                    "check": [(None,1)]
1132                   })
1133            self.assertRaises(LoadCancelled,
1134                                load_session, self.filename(), None, s_cb.s_cb)
1135    
1136        def test_05_path_error_fix_from_list_changed(self):
1137            """Test alternative path from list changed."""
1138            s_cb = Shapefile_CallBack({
1139                    "search": [("../Data/iceland/roads-line.shp",1)],
1140                    "check": [("../Data/iceland/roads-line.shp",0)]
1141                   })
1142            self.session = load_session(self.filename(),
1143                                        shapefile_callback =s_cb.s_cb)
1144            self.checkSession(self.session)
1145    
1146        def test_06_path_error_fix_from_list_fails(self):
1147            """Test alternative path recovery from list."""
1148            s_cb = Shapefile_CallBack({
1149                    "search": [("../wrong/iceland/roads-line.shp",1),
1150                                ("../Data/iceland/roads-line.shp",0)],
1151                    "check": [(None,None)]
1152                   })
1153            self.session = load_session(self.filename(),
1154                                        shapefile_callback =s_cb.s_cb)
1155            self.assertRaises(IndexError,
1156                                s_cb.s_cb, None, "search")
1157            
1158    
1159    
1160  if __name__ == "__main__":  if __name__ == "__main__":
1161      support.run_tests()      support.run_tests()

Legend:
Removed from v.1976  
changed lines
  Added in v.2688

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26