/[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 2373 by jan, Sun Oct 3 20:49:24 2004 UTC revision 2620 by jonathan, Fri May 6 14:19:23 2005 UTC
# Line 53  from Thuban.Model.table import DBFTable, Line 53  from Thuban.Model.table import DBFTable,
53  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
54       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE
55    
   
56  def filenames_equal(name1, name2):  def filenames_equal(name1, name2):
57      """Return true if the filenames name1 and name2 are equal.      """Return true if the filenames name1 and name2 are equal.
58    
# Line 124  class LoadSessionTest(support.FileLoadTe Line 123  class LoadSessionTest(support.FileLoadTe
123                  print a != b and "***************" or ""                  print a != b and "***************" or ""
124                  print a                  print a
125                  print b                  print b
126    
127          self.assertEquals(el1, el2,          self.assertEquals(el1, el2,
128                            "loaded file not equivalent to the saved file")                            "loaded file not equivalent to the saved file")
129    
# Line 664  class TestRasterLayer(LoadSessionTest): Line 664  class TestRasterLayer(LoadSessionTest):
664          title="single map&layer">          title="single map&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"
667                  title="My RasterLayer"/>                  title="My RasterLayer" opacity="0.4" masktype="alpha"/>
668      </map>      </map>
669  </session>  </session>
670  '''  '''
# Line 681  class TestRasterLayer(LoadSessionTest): Line 681  class TestRasterLayer(LoadSessionTest):
681          layer = map.Layers()[0] # one layer in the sample          layer = map.Layers()[0] # one layer in the sample
682    
683          eq(layer.Title(), "My RasterLayer")          eq(layer.Title(), "My RasterLayer")
684            eq(layer.Opacity(), 0.4)
685            eq(layer.MaskType(), layer.MASK_ALPHA)
686    
687          self.failIf(layer.Visible())          self.failIf(layer.Visible())
688          self.failUnless(filenames_equal(layer.GetImageFilename(),          self.failUnless(filenames_equal(layer.GetImageFilename(),
689                                          os.path.join(self.temp_dir(),                                          os.path.join(self.temp_dir(),
# Line 980  class TestLoadError(LoadSessionTest): Line 983  class TestLoadError(LoadSessionTest):
983          else:          else:
984              self.fail("Missing filetype attribute doesn't raise LoadError")              self.fail("Missing filetype attribute doesn't raise LoadError")
985    
986    class Shapefile_CallBack:
987    
988        def __init__(self, params):
989            """Initialize the callback return values.
990              
991               params must be a dictionary of the potential CB modes (keys),
992               with lists of tuples of return values as values.
993               Depending on the test the callback can be called multiple,
994               each time a return value is poped from the list
995            """
996    
997            self.params = params
998    
999    
1000        def s_cb(self, filename, mode = None, second_try= 0):
1001            if self.params.has_key(mode):
1002                return self.params[mode].pop(0)
1003            else:
1004                raise LoadError
1005            
1006    class TestAltPath(LoadSessionTest):
1007    
1008        """Test the various cases in the alternative path feature.
1009    
1010           The test checks the reasonable cases:
1011           - First recognition of a path error, fixed with user interaction.
1012           - First recognition of a path error, load cancelled.
1013           - Path error fixed from list, confirmed by user.
1014           - Path error fixed from list, changed by user.
1015           - Path error fixed from list, cancelled by user.
1016           - Path error wrongly fixed from list, manual fix forced.
1017        """
1018    
1019        file_contents = '''\
1020    <?xml version="1.0" encoding="UTF-8"?>
1021    <!DOCTYPE session SYSTEM "thuban-1.1.dtd">
1022    <session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="AltPath Test session">
1023        <fileshapesource filetype="shapefile" id="D1108450956" filename="../../Data/iceland/political.shp"/>
1024        <fileshapesource filetype="shapefile" id="D1108900076" filename="../Data/iceland/roads-line.shp"/>
1025        <fileshapesource filetype="shapefile" id="D1108947244" filename="../../Data/iceland/cultural_landmark-point.shp"/>
1026        <map title="not the iceland map">
1027            <layer title="political" stroke_width="1" shapestore="D1108450956" visible="true" stroke="#000000" fill="#c0c0c0"/>
1028            <layer title="roads-line" stroke_width="1" shapestore="D1108900076" visible="true" stroke="#000000" fill="None"/>
1029            <layer title="something else" stroke_width="1" shapestore="D1108947244" visible="true" stroke="#000000" fill="None"/>
1030        </map>
1031    </session>
1032    '''
1033    
1034        def checkSession(self, session):
1035            """Check if session has been loaded successfully."""
1036            
1037            eq = self.assertEquals
1038    
1039            map = session.Maps()[0]
1040            layers = map.Layers()
1041    
1042            eq("AltPath Test session", session.Title())
1043            eq("not the iceland map", map.Title())
1044            eq(3,len(layers))
1045            eq("political",layers[0].Title())
1046            eq("roads-line",layers[1].Title())
1047            eq("something else",layers[2].Title())
1048    
1049        def test_01_single_path_error_fix(self):
1050            """Test single file path error fix."""
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.2373  
changed lines
  Added in v.2620

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26