/[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 2446 by frank, Mon Dec 13 11:52:34 2004 UTC
# Line 980  class TestLoadError(LoadSessionTest): Line 980  class TestLoadError(LoadSessionTest):
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="Thuban sample 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 test_01_single_path_error_fix(self):
1032            """Test single file path error fix."""
1033            # The usual initial case
1034            s_cb = Shapefile_CallBack({
1035                        "search": [("../Data/iceland/roads-line.shp",0)],
1036                        "check": [(None, None)]})
1037            self.session = load_session(self.filename(),
1038                                        shapefile_callback =s_cb.s_cb)
1039            self.session.Destroy()
1040            self.session = None
1041    
1042        def test_02_path_error_fix_from_list(self):
1043            """Test single file path error fix."""
1044            # This represents the usual case for "from_list"
1045            s_cb = Shapefile_CallBack({
1046                    "search": [("../Data/iceland/roads-line.shp",1)],
1047                    "check": [(os.path.abspath("../Data/iceland/roads-line.shp"),1)]
1048                   })
1049            self.session = load_session(self.filename(),
1050                                        shapefile_callback =s_cb.s_cb)
1051            self.session.Destroy()
1052            self.session = None
1053    
1054        def test_03_single_path_error_cancelled(self):
1055            """Test alternative path cancelled."""
1056            s_cb = Shapefile_CallBack({
1057                        "search": [(None,0)],
1058                        "check": [(None, None)]})
1059            self.assertRaises(LoadCancelled,
1060                                load_session, self.filename(), None, s_cb.s_cb)
1061    
1062        def test_04_path_error_fix_from_list_cancelled(self):
1063            """Test alternative path from list cancelled."""
1064            s_cb = Shapefile_CallBack({
1065                    "search": [("../Data/iceland/roads-line.shp",1)],
1066                    "check": [(None,1)]
1067                   })
1068            self.assertRaises(LoadCancelled,
1069                                load_session, self.filename(), None, s_cb.s_cb)
1070    
1071        def test_05_path_error_fix_from_list_changed(self):
1072            """Test alternative path from list changed."""
1073            s_cb = Shapefile_CallBack({
1074                    "search": [("../Data/iceland/roads-line.shp",1)],
1075                    "check": [("../Data/iceland/roads-line.shp",0)]
1076                   })
1077            self.session = load_session(self.filename(),
1078                                        shapefile_callback =s_cb.s_cb)
1079            self.session.Destroy()
1080            self.session = None
1081    
1082        def test_06_path_error_fix_from_list_fails(self):
1083            """Test alternative path recovery from list."""
1084            s_cb = Shapefile_CallBack({
1085                    "search": [("../wrong/iceland/roads-line.shp",1),
1086                                ("../Data/iceland/roads-line.shp",0)],
1087                    "check": [(None,None)]
1088                   })
1089            self.session = load_session(self.filename(),
1090                                        shapefile_callback =s_cb.s_cb)
1091            self.assertRaises(IndexError,
1092                                s_cb.s_cb, None, "search")
1093            
1094            self.session.Destroy()
1095            self.session = None
1096    
1097    
1098  if __name__ == "__main__":  if __name__ == "__main__":
1099      support.run_tests()      support.run_tests()

Legend:
Removed from v.2373  
changed lines
  Added in v.2446

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26