/[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 2458 by frank, Wed Dec 15 09:58:30 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="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            # The usual initial case
1049            s_cb = Shapefile_CallBack({
1050                        "search": [("../Data/iceland/roads-line.shp",0)],
1051                        "check": [(None, None)]})
1052            self.session = load_session(self.filename(),
1053                                        shapefile_callback =s_cb.s_cb)
1054            self.checkSession(self.session)
1055            
1056        def test_02_path_error_fix_from_list(self):
1057            """Test single file path error fix."""
1058            # This represents the usual case for "from_list"
1059            s_cb = Shapefile_CallBack({
1060                    "search": [("../Data/iceland/roads-line.shp",1)],
1061                    "check": [(os.path.abspath("../Data/iceland/roads-line.shp"),1)]
1062                   })
1063            self.session = load_session(self.filename(),
1064                                        shapefile_callback =s_cb.s_cb)
1065            self.checkSession(self.session)
1066    
1067        def test_03_single_path_error_cancelled(self):
1068            """Test alternative path cancelled."""
1069            s_cb = Shapefile_CallBack({
1070                        "search": [(None,0)],
1071                        "check": [(None, None)]})
1072            self.assertRaises(LoadCancelled,
1073                                load_session, self.filename(), None, s_cb.s_cb)
1074    
1075        def test_04_path_error_fix_from_list_cancelled(self):
1076            """Test alternative path from list cancelled."""
1077            s_cb = Shapefile_CallBack({
1078                    "search": [("../Data/iceland/roads-line.shp",1)],
1079                    "check": [(None,1)]
1080                   })
1081            self.assertRaises(LoadCancelled,
1082                                load_session, self.filename(), None, s_cb.s_cb)
1083    
1084        def test_05_path_error_fix_from_list_changed(self):
1085            """Test alternative path from list changed."""
1086            s_cb = Shapefile_CallBack({
1087                    "search": [("../Data/iceland/roads-line.shp",1)],
1088                    "check": [("../Data/iceland/roads-line.shp",0)]
1089                   })
1090            self.session = load_session(self.filename(),
1091                                        shapefile_callback =s_cb.s_cb)
1092            self.checkSession(self.session)
1093    
1094        def test_06_path_error_fix_from_list_fails(self):
1095            """Test alternative path recovery from list."""
1096            s_cb = Shapefile_CallBack({
1097                    "search": [("../wrong/iceland/roads-line.shp",1),
1098                                ("../Data/iceland/roads-line.shp",0)],
1099                    "check": [(None,None)]
1100                   })
1101            self.session = load_session(self.filename(),
1102                                        shapefile_callback =s_cb.s_cb)
1103            self.assertRaises(IndexError,
1104                                s_cb.s_cb, None, "search")
1105            
1106    
1107    
1108  if __name__ == "__main__":  if __name__ == "__main__":
1109      support.run_tests()      support.run_tests()

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26