/[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 2104 by bh, Fri Mar 12 12:19:15 2004 UTC revision 2688 by frank, Fri Jun 30 12:27:20 2006 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002, 2003, 2004 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 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, \
# Line 53  from Thuban.Model.table import DBFTable, Line 54  from Thuban.Model.table import DBFTable,
54  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
55       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE       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.
59    
# Line 124  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 162  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 172  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 198  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 212  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 220  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 235  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 290  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 365  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 388  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 = '''\
# Line 399  class TestClassification(ClassificationT Line 459  class TestClassification(ClassificationT
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 423  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 443  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 461  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 473  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 495  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 545  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 561  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 615  class TestRasterLayer(LoadSessionTest): Line 699  class TestRasterLayer(LoadSessionTest):
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 632  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 657  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 707  class TestLabelLayer(LoadSessionTest): Line 799  class TestLabelLayer(LoadSessionTest):
799              <parameter value="proj=utm"/>              <parameter value="proj=utm"/>
800              <parameter value="ellps=clrk66"/>              <parameter value="ellps=clrk66"/>
801          </projection>          </projection>
802          <layer shapestore="D145265052" visible="true" stroke="#000000"          <layer shapestore="D145265052" visible="true" title="political">
                 title="political" stroke_width="1" fill="#c0c0c0">  
803              <projection name="Geographic">              <projection name="Geographic">
804                  <parameter value="proj=latlong"/>                  <parameter value="proj=latlong"/>
805                  <parameter value="to_meter=0.017453"/>                  <parameter value="to_meter=0.017453"/>
806                  <parameter value="ellps=clrk66"/>                  <parameter value="ellps=clrk66"/>
807              </projection>              </projection>
808                <classification>
809                    <clnull label="">
810                        <cldata stroke="#000000" stroke_width="1" fill="#c0c0c0"/>
811                    </clnull>
812                </classification>
813          </layer>          </layer>
814          <layer shapestore="D145412868" visible="true" stroke="#000000"          <layer shapestore="D145412868" visible="true" title="landmarks">
                 title="landmarks" stroke_width="1" fill="#ffff00">  
815              <projection name="Geographic">              <projection name="Geographic">
816                  <parameter value="proj=latlong"/>                  <parameter value="proj=latlong"/>
817                  <parameter value="to_meter=0.017453"/>                  <parameter value="to_meter=0.017453"/>
818                  <parameter value="ellps=clrk66"/>                  <parameter value="ellps=clrk66"/>
819              </projection>              </projection>
820                <classification>
821                    <clnull label="">
822                        <cldata size="5" stroke="#000000" stroke_width="1" fill="#ffff00"/>
823                    </clnull>
824                </classification>
825          </layer>          </layer>
826          <labellayer>          <labellayer>
827              <label x="-21.5" y="64.25" text="RUINS"              <label x="-21.5" y="64.25" text="RUINS"
# Line 740  class TestLabelLayer(LoadSessionTest): Line 840  class TestLabelLayer(LoadSessionTest):
840    
841          label_layer = self.session.Maps()[0].LabelLayer()          label_layer = self.session.Maps()[0].LabelLayer()
842          expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),          expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),
843                             (-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP),                             (-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):          for label, values in zip(label_layer.Labels(), expected_labels):
847              self.assertEquals((label.x, label.y, label.text, label.halign,              self.assertEquals((label.x, label.y, label.text, label.halign,
# Line 931  class TestLoadError(LoadSessionTest): Line 1032  class TestLoadError(LoadSessionTest):
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.2104  
changed lines
  Added in v.2688

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26