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 |
|
|
1040 |
|
def test_02_path_error_fix_from_list(self): |
1041 |
|
"""Test single file path error fix.""" |
1042 |
|
# This represents the usual case for "from_list" |
1043 |
|
s_cb = Shapefile_CallBack({ |
1044 |
|
"search": [("../Data/iceland/roads-line.shp",1)], |
1045 |
|
"check": [(os.path.abspath("../Data/iceland/roads-line.shp"),1)] |
1046 |
|
}) |
1047 |
|
self.session = load_session(self.filename(), |
1048 |
|
shapefile_callback =s_cb.s_cb) |
1049 |
|
|
1050 |
|
def test_03_single_path_error_cancelled(self): |
1051 |
|
"""Test alternative path cancelled.""" |
1052 |
|
s_cb = Shapefile_CallBack({ |
1053 |
|
"search": [(None,0)], |
1054 |
|
"check": [(None, None)]}) |
1055 |
|
self.assertRaises(LoadCancelled, |
1056 |
|
load_session, self.filename(), None, s_cb.s_cb) |
1057 |
|
|
1058 |
|
def test_04_path_error_fix_from_list_cancelled(self): |
1059 |
|
"""Test alternative path from list cancelled.""" |
1060 |
|
s_cb = Shapefile_CallBack({ |
1061 |
|
"search": [("../Data/iceland/roads-line.shp",1)], |
1062 |
|
"check": [(None,1)] |
1063 |
|
}) |
1064 |
|
self.assertRaises(LoadCancelled, |
1065 |
|
load_session, self.filename(), None, s_cb.s_cb) |
1066 |
|
|
1067 |
|
def test_05_path_error_fix_from_list_changed(self): |
1068 |
|
"""Test alternative path from list changed.""" |
1069 |
|
s_cb = Shapefile_CallBack({ |
1070 |
|
"search": [("../Data/iceland/roads-line.shp",1)], |
1071 |
|
"check": [("../Data/iceland/roads-line.shp",0)] |
1072 |
|
}) |
1073 |
|
self.session = load_session(self.filename(), |
1074 |
|
shapefile_callback =s_cb.s_cb) |
1075 |
|
|
1076 |
|
def test_06_path_error_fix_from_list_fails(self): |
1077 |
|
"""Test alternative path recovery from list.""" |
1078 |
|
s_cb = Shapefile_CallBack({ |
1079 |
|
"search": [("../wrong/iceland/roads-line.shp",1), |
1080 |
|
("../Data/iceland/roads-line.shp",0)], |
1081 |
|
"check": [(None,None)] |
1082 |
|
}) |
1083 |
|
self.session = load_session(self.filename(), |
1084 |
|
shapefile_callback =s_cb.s_cb) |
1085 |
|
self.assertRaises(IndexError, |
1086 |
|
s_cb.s_cb, None, "search") |
1087 |
|
|
1088 |
|
|
1089 |
|
|
1090 |
if __name__ == "__main__": |
if __name__ == "__main__": |
1091 |
support.run_tests() |
support.run_tests() |