/[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 1970 by bh, Mon Nov 24 18:36:00 2003 UTC revision 2456 by frank, Wed Dec 15 09:44:34 2004 UTC
# Line 1  Line 1 
1  # Copyright (c) 2002, 2003 by Intevation GmbH  # Copyright (c) 2002, 2003, 2004 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 50  from Thuban.Model.postgisdb import Conne Line 50  from Thuban.Model.postgisdb import Conne
50  from Thuban.Model.table import DBFTable, MemoryTable, \  from Thuban.Model.table import DBFTable, MemoryTable, \
51       FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \       FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \
52       table_to_dbf       table_to_dbf
53    from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
54         ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE
55    
56    
57  def filenames_equal(name1, name2):  def filenames_equal(name1, name2):
# 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 159  class ClassificationTest(LoadSessionTest Line 162  class ClassificationTest(LoadSessionTest
162                  props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1])                  props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1])
163                  props.SetFill(                  props.SetFill(
164                      parse_color(data[CLASSES][i][GROUP_PROPS][2]))                      parse_color(data[CLASSES][i][GROUP_PROPS][2]))
165                    if len(data[CLASSES][i][GROUP_PROPS]) > 3:
166                        props.SetSize(data[CLASSES][i][GROUP_PROPS][3])
167    
168                  if data[CLASSES][i][GROUP_TYPE] == "default":                  if data[CLASSES][i][GROUP_TYPE] == "default":
169                      g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL])                      g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL])
# Line 182  class TestSingleLayer(LoadSessionTest): Line 187  class TestSingleLayer(LoadSessionTest):
187      # want to test whether the loading code handles that correctly.      # want to test whether the loading code handles that correctly.
188      file_contents = '''\      file_contents = '''\
189  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
190  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
191  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
192          title="Stra\xc3\x9fen &amp; Landmarken">          title="Stra\xc3\x9fen &amp; Landmarken">
193      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
194          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 274  class TestNonAsciiColumnName(LoadSession Line 279  class TestNonAsciiColumnName(LoadSession
279    
280      file_contents = '''\      file_contents = '''\
281  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
282  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
283  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
284          title="Non ASCII column name test">          title="Non ASCII column name test">
285      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
286          filename="TestNonAsciiColumnName.shp"/>          filename="TestNonAsciiColumnName.shp"/>
# Line 351  class TestLayerVisibility(LoadSessionTes Line 356  class TestLayerVisibility(LoadSessionTes
356    
357      file_contents = '''\      file_contents = '''\
358  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
359  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
360  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
361          title="single map&amp;layer">          title="single map&amp;layer">
362      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
363          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 385  class TestLayerVisibility(LoadSessionTes Line 390  class TestLayerVisibility(LoadSessionTes
390          self.check_format()          self.check_format()
391    
392    
393    class TestSymbolSize(ClassificationTest):
394    
395        file_contents = '''\
396    <?xml version="1.0" encoding="UTF-8"?>
397    <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
398    <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session">
399        <fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/>
400        <map title="Iceland map">
401            <layer title="cultural_landmark-point" stroke_width="1" shapestore="D813968480" visible="true" stroke="#000000" fill="#000000">
402                <classification field="CLPTLABEL" field_type="string">
403                    <clnull label="">
404                        <cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/>
405                    </clnull>
406                    <clpoint label="" value="RUINS">
407                        <cldata stroke="#000000" stroke_width="1" size="6" fill="#ffffff"/>
408                    </clpoint>
409                    <clpoint label="" value="FARM">
410                        <cldata stroke="#000000" stroke_width="1" size="9" fill="#ffff00"/>
411                    </clpoint>
412                </classification>
413            </layer>
414        </map>
415    </session>
416    '''
417    
418        def test(self):
419            """Test that the size attribute for point symbols is correctly
420            loaded for a layer."""
421            eq = self.assertEquals
422            session = load_session(self.filename())
423            self.session = session
424    
425            map = session.Maps()[0] # only one map in the sample
426    
427            expected = [("cultural_landmark-point", 2,
428                            [("default", (), "",
429                                ("#000000", 1, "#000000", 3)),
430                             ("single", "RUINS", "",
431                                ("#000000", 1, "#ffffff", 6)),
432                             ("single", "FARM", "",
433                                ("#000000", 1, "#ffff00", 9))])]
434    
435            self.TestLayers(map.Layers(), expected)
436    
437            self.check_format()
438    
439    
440  class TestClassification(ClassificationTest):  class TestClassification(ClassificationTest):
441    
442      file_contents = '''\      file_contents = '''\
443  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
444  <!DOCTYPE session SYSTEM "thuban.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
445  <session title="single map&amp;layer">  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
446          <map title="Test Map">          title="single map&amp;layer">
447                  <projection>      <fileshapesource filetype="shapefile" id="D138389860"
448                          <parameter value="zone=26"/>          filename="../../Data/iceland/political.shp"/>
449                          <parameter value="proj=utm"/>      <fileshapesource filetype="shapefile" id="D138504492"
450                          <parameter value="ellps=clrk66"/>          filename="../../Data/iceland/political.shp"/>
451                  </projection>      <map title="Test Map">
452                  <layer title="My Layer" stroke_width="1" fill="None"          <projection name="">
453                      filename="../../Data/iceland/political.shp"              <parameter value="zone=26"/>
454                      stroke="#000000">              <parameter value="proj=utm"/>
455                <parameter value="ellps=clrk66"/>
456            </projection>
457            <layer shapestore="D138389860" visible="true" stroke="#000000"
458                    title="My Layer" stroke_width="1" fill="None">
459              <classification field="POPYREG" field_type="string">              <classification field="POPYREG" field_type="string">
460                  <clnull>                  <clnull label="">
461                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
462                  </clnull>                  </clnull>
463                  <clpoint value="1">                  <clpoint label="" value="1">
464                      <cldata stroke="#000000" stroke_width="2" fill="None"/>                      <cldata stroke="#000000" stroke_width="2" fill="None"/>
465                  </clpoint>                  </clpoint>
466                  <clpoint value="1">                  <clpoint label="" value="1">
467                      <cldata stroke="#000000" stroke_width="10" fill="None"/>                      <cldata stroke="#000000" stroke_width="10" fill="None"/>
468                  </clpoint>                  </clpoint>
469                  <clpoint value="\xc3\xa4\xc3\xb6\xc3\xbc"                  <clpoint label="\xc3\x9cml\xc3\xa4uts"
470                           label="\xc3\x9cml\xc3\xa4uts">                          value="\xc3\xa4\xc3\xb6\xc3\xbc">
471                      <cldata fill="None" stroke="#000000" stroke_width="1"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
472                  </clpoint>                  </clpoint>
473              </classification>              </classification>
474          </layer>          </layer>
475                  <layer title="My Layer 2" stroke_width="1" fill="None"          <layer shapestore="D138504492" visible="true" stroke="#000000"
476                      filename="../../Data/iceland/political.shp"                  title="My Layer 2" stroke_width="2" fill="None">
                     stroke="#000000">  
477              <classification field="AREA" field_type="double">              <classification field="AREA" field_type="double">
478                  <clnull>                  <clnull label="">
479                      <cldata stroke="#000000" stroke_width="2" fill="None"/>                      <cldata stroke="#000000" stroke_width="2" fill="None"/>
480                  </clnull>                  </clnull>
481                  <clrange min="0" max="1">                  <clrange label="" range="[0;1[">
482                      <cldata stroke="#111111" stroke_width="1" fill="None"/>                      <cldata stroke="#111111" stroke_width="1" fill="None"/>
483                  </clrange>                  </clrange>
484                  <clpoint value=".5">                  <clpoint label="" value="0.5">
485                      <cldata stroke="#000000" stroke_width="1" fill="#111111"/>                      <cldata stroke="#000000" stroke_width="1" fill="#111111"/>
486                  </clpoint>                  </clpoint>
487                  <clrange min="-1" max="0">                  <clrange label="" range="[-1;0[">
488                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
489                  </clrange>                  </clrange>
490                  <clpoint value="-.5">                  <clpoint label="" value="-0.5">
491                      <cldata stroke="#000000" stroke_width="1" fill="None"/>                      <cldata stroke="#000000" stroke_width="1" fill="None"/>
492                  </clpoint>                  </clpoint>
493              </classification>              </classification>
494          </layer>          </layer>
495          </map>      </map>
496  </session>  </session>
497  '''  '''
498    
# Line 471  class TestClassification(ClassificationT Line 526  class TestClassification(ClassificationT
526    
527          self.TestLayers(map.Layers(), expected)          self.TestLayers(map.Layers(), expected)
528    
529            self.check_format()
530    
531    
532  class TestLabels(ClassificationTest):  class TestLabels(ClassificationTest):
533    
534      file_contents = '''\      file_contents = '''\
535  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
536  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
537  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
538          title="single map&amp;layer">          title="single map&amp;layer">
539      <fileshapesource filetype="shapefile" id="D1"      <fileshapesource filetype="shapefile" id="D1"
540          filename="../../Data/iceland/political.shp"/>          filename="../../Data/iceland/political.shp"/>
# Line 524  class TestLayerProjection(LoadSessionTes Line 581  class TestLayerProjection(LoadSessionTes
581    
582      file_contents = '''\      file_contents = '''\
583  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
584  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
585  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
586          title="single map&amp;layer">          title="single map&amp;layer">
587      <fileshapesource filetype="shapefile" id="D2"      <fileshapesource filetype="shapefile" id="D2"
588          filename="../../Data/iceland/roads-line.shp"/>          filename="../../Data/iceland/roads-line.shp"/>
# Line 602  class TestRasterLayer(LoadSessionTest): Line 659  class TestRasterLayer(LoadSessionTest):
659    
660      file_contents = '''\      file_contents = '''\
661  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
662  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
663  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
664          title="single map&amp;layer">          title="single map&amp;layer">
665      <map title="Test Map">      <map title="Test Map">
666          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"          <rasterlayer visible="false" filename="../../Data/iceland/island.tif"
# Line 636  class TestRasterLayer(LoadSessionTest): Line 693  class TestRasterLayer(LoadSessionTest):
693  class TestJoinedTable(LoadSessionTest):  class TestJoinedTable(LoadSessionTest):
694    
695      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
696  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
697  <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">
698      <fileshapesource filetype="shapefile" id="D137227612"      <fileshapesource filetype="shapefile" id="D137227612"
699          filename="../../Data/iceland/roads-line.shp"/>          filename="../../Data/iceland/roads-line.shp"/>
700      <filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140"      <filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140"
# Line 681  class TestJoinedTable(LoadSessionTest): Line 738  class TestJoinedTable(LoadSessionTest):
738          self.check_format()          self.check_format()
739    
740    
741    class TestLabelLayer(LoadSessionTest):
742    
743        # Note that the labels deliberately contain non-ascii characters to
744        # test whether they're supported correctly.
745    
746        file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
747    <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
748    <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session">
749        <fileshapesource filetype="shapefile" id="D145265052"
750            filename="../../Data/iceland/political.shp"/>
751        <fileshapesource filetype="shapefile" id="D145412868"
752            filename="../../Data/iceland/cultural_landmark-point.shp"/>
753        <map title="Iceland map">
754            <projection name="Unknown">
755                <parameter value="zone=26"/>
756                <parameter value="proj=utm"/>
757                <parameter value="ellps=clrk66"/>
758            </projection>
759            <layer shapestore="D145265052" visible="true" stroke="#000000"
760                    title="political" stroke_width="1" fill="#c0c0c0">
761                <projection name="Geographic">
762                    <parameter value="proj=latlong"/>
763                    <parameter value="to_meter=0.017453"/>
764                    <parameter value="ellps=clrk66"/>
765                </projection>
766            </layer>
767            <layer shapestore="D145412868" visible="true" stroke="#000000"
768                    title="landmarks" stroke_width="1" fill="#ffff00">
769                <projection name="Geographic">
770                    <parameter value="proj=latlong"/>
771                    <parameter value="to_meter=0.017453"/>
772                    <parameter value="ellps=clrk66"/>
773                </projection>
774            </layer>
775            <labellayer>
776                <label x="-21.5" y="64.25" text="RUINS"
777                    halign="left" valign="center"/>
778                <label x="-15.125" y="64.75" text="H\xc3\xbctte"
779                    halign="right" valign="top"/>
780            </labellayer>
781        </map>
782    </session>
783    '''
784    
785        def test(self):
786            """Test loading a session with a label layer"""
787            session = load_session(self.filename())
788            self.session = session
789    
790            label_layer = self.session.Maps()[0].LabelLayer()
791            expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER),
792                               (-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP),
793                               ]
794            for label, values in zip(label_layer.Labels(), expected_labels):
795                self.assertEquals((label.x, label.y, label.text, label.halign,
796                                   label.valign),
797                                  values)
798            self.check_format()
799    
800    
801  class TestPostGISLayer(LoadSessionTest):  class TestPostGISLayer(LoadSessionTest):
802    
803      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
804  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
805  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
806          title="unnamed session">          title="unnamed session">
807      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"
808          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>
809      <dbshapesource tablename="landmarks" id="D143149420" dbconn="D142684948"/>      <dbshapesource id="D143149420" dbconn="D142684948"
810            tablename="landmarks_point_id" id_column="point_id"
811            geometry_column="the_geom" />
812      <map title="unnamed map">      <map title="unnamed map">
813          <layer shapestore="D143149420" visible="true" stroke="#000000"          <layer shapestore="D143149420" visible="true" stroke="#000000"
814                  title="landmarks" stroke_width="1" fill="None"/>                  title="landmarks" stroke_width="1" fill="None"/>
# Line 734  class TestPostGISLayer(LoadSessionTest): Line 852  class TestPostGISLayer(LoadSessionTest):
852  class TestPostGISLayerPassword(LoadSessionTest):  class TestPostGISLayerPassword(LoadSessionTest):
853    
854      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>      file_contents = '''<?xml version="1.0" encoding="UTF-8"?>
855  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
856  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
857          title="unnamed session">          title="unnamed session">
858      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"      <dbconnection port="%(port)s" host="%(host)s" user="%(user)s"
859          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>          dbtype="postgis" id="D142684948" dbname="%(dbname)s"/>
# Line 829  class TestLoadError(LoadSessionTest): Line 947  class TestLoadError(LoadSessionTest):
947    
948      file_contents = '''\      file_contents = '''\
949  <?xml version="1.0" encoding="UTF-8"?>  <?xml version="1.0" encoding="UTF-8"?>
950  <!DOCTYPE session SYSTEM "thuban-1.0.dtd">  <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
951  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"  <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"
952          title="single map&amp;layer">          title="single map&amp;layer">
953      <fileshapesource id="D1" filename="../../Data/iceland/political.shp"/>      <fileshapesource id="D1" filename="../../Data/iceland/political.shp"/>
954      <map title="Test Map">      <map title="Test Map">
# Line 857  class TestLoadError(LoadSessionTest): Line 975  class TestLoadError(LoadSessionTest):
975              # LoadError really was about the missing attribute              # LoadError really was about the missing attribute
976              self.assertEquals(str(value),              self.assertEquals(str(value),
977                "Element "                "Element "
978                "(u'http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd',"                "(u'http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd',"
979                " u'fileshapesource') requires an attribute 'filetype'")                " u'fileshapesource') requires an attribute 'filetype'")
980          else:          else:
981              self.fail("Missing filetype attribute doesn't raise LoadError")              self.fail("Missing filetype attribute doesn't raise LoadError")
982    
983    class Shapefile_CallBack:
984    
985        def __init__(self, params):
986            """Initialize the callback return values.
987              
988               params must be a dictionary of the potential CB modes (keys),
989               with lists of tuples of return values as values.
990               Depending on the test the callback can be called multiple,
991               each time a return value is poped from the list
992            """
993    
994            self.params = params
995    
996    
997        def s_cb(self, filename, mode = None, second_try= 0):
998            if self.params.has_key(mode):
999                return self.params[mode].pop(0)
1000            else:
1001                raise LoadError
1002            
1003    class TestAltPath(LoadSessionTest):
1004    
1005        """Test the various cases in the alternative path feature.
1006    
1007           The test checks the reasonable cases:
1008           - First recognition of a path error, fixed with user interaction.
1009           - First recognition of a path error, load cancelled.
1010           - Path error fixed from list, confirmed by user.
1011           - Path error fixed from list, changed by user.
1012           - Path error fixed from list, cancelled by user.
1013           - Path error wrongly fixed from list, manual fix forced.
1014        """
1015    
1016        file_contents = '''\
1017    <?xml version="1.0" encoding="UTF-8"?>
1018    <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
1019    <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="AltPath Test session">
1020        <fileshapesource filetype="shapefile" id="D1108450956" filename="../../Data/iceland/political.shp"/>
1021        <fileshapesource filetype="shapefile" id="D1108900076" filename="../Data/iceland/roads-line.shp"/>
1022        <fileshapesource filetype="shapefile" id="D1108947244" filename="../../Data/iceland/cultural_landmark-point.shp"/>
1023        <map title="not the iceland map">
1024            <layer title="political" stroke_width="1" shapestore="D1108450956" visible="true" stroke="#000000" fill="#c0c0c0"/>
1025            <layer title="roads-line" stroke_width="1" shapestore="D1108900076" visible="true" stroke="#000000" fill="None"/>
1026            <layer title="something else" stroke_width="1" shapestore="D1108947244" visible="true" stroke="#000000" fill="None"/>
1027        </map>
1028    </session>
1029    '''
1030    
1031        def checkSession(self, session):
1032            """Check if session has been loaded successfully."""
1033            
1034            eq = self.assertEquals
1035    
1036            map = session.Maps()[0]
1037            layers = map.Layers()
1038    
1039            eq("AltPath Test session", session.Title())
1040            eq("not the iceland map", map.Title())
1041            eq(3,len(layers))
1042            eq("political",layers[0].Title())
1043            eq("roads-line",layers[1].Title())
1044            eq("something else",layers[2].Title())
1045    
1046        def test_01_single_path_error_fix(self):
1047            """Test single file path error fix."""
1048            
1049            eq = self.assertEquals
1050            
1051            # The usual initial case
1052            s_cb = Shapefile_CallBack({
1053                        "search": [("../Data/iceland/roads-line.shp",0)],
1054                        "check": [(None, None)]})
1055            self.session = load_session(self.filename(),
1056                                        shapefile_callback =s_cb.s_cb)
1057            self.checkSession(self.session)
1058            
1059        def test_02_path_error_fix_from_list(self):
1060            """Test single file path error fix."""
1061            # This represents the usual case for "from_list"
1062            s_cb = Shapefile_CallBack({
1063                    "search": [("../Data/iceland/roads-line.shp",1)],
1064                    "check": [(os.path.abspath("../Data/iceland/roads-line.shp"),1)]
1065                   })
1066            self.session = load_session(self.filename(),
1067                                        shapefile_callback =s_cb.s_cb)
1068            self.checkSession(self.session)
1069    
1070        def test_03_single_path_error_cancelled(self):
1071            """Test alternative path cancelled."""
1072            s_cb = Shapefile_CallBack({
1073                        "search": [(None,0)],
1074                        "check": [(None, None)]})
1075            self.assertRaises(LoadCancelled,
1076                                load_session, self.filename(), None, s_cb.s_cb)
1077    
1078        def test_04_path_error_fix_from_list_cancelled(self):
1079            """Test alternative path from list cancelled."""
1080            s_cb = Shapefile_CallBack({
1081                    "search": [("../Data/iceland/roads-line.shp",1)],
1082                    "check": [(None,1)]
1083                   })
1084            self.assertRaises(LoadCancelled,
1085                                load_session, self.filename(), None, s_cb.s_cb)
1086    
1087        def test_05_path_error_fix_from_list_changed(self):
1088            """Test alternative path from list changed."""
1089            s_cb = Shapefile_CallBack({
1090                    "search": [("../Data/iceland/roads-line.shp",1)],
1091                    "check": [("../Data/iceland/roads-line.shp",0)]
1092                   })
1093            self.session = load_session(self.filename(),
1094                                        shapefile_callback =s_cb.s_cb)
1095            self.checkSession(self.session)
1096    
1097        def test_06_path_error_fix_from_list_fails(self):
1098            """Test alternative path recovery from list."""
1099            s_cb = Shapefile_CallBack({
1100                    "search": [("../wrong/iceland/roads-line.shp",1),
1101                                ("../Data/iceland/roads-line.shp",0)],
1102                    "check": [(None,None)]
1103                   })
1104            self.session = load_session(self.filename(),
1105                                        shapefile_callback =s_cb.s_cb)
1106            self.assertRaises(IndexError,
1107                                s_cb.s_cb, None, "search")
1108            
1109    
1110    
1111  if __name__ == "__main__":  if __name__ == "__main__":
1112      support.run_tests()      support.run_tests()

Legend:
Removed from v.1970  
changed lines
  Added in v.2456

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26