7 |
|
|
8 |
""" |
""" |
9 |
Test loading a thuban session from a file |
Test loading a thuban session from a file |
10 |
|
|
11 |
|
The tests in this file (test_load.py) are always be the tests for the |
12 |
|
current version of the thuban file format. Tests for older versions can |
13 |
|
be found in the version specific test modules, e.g. test_load_0_2 for |
14 |
|
files created by Thuban 0.2. |
15 |
|
|
16 |
|
Maintenance of the test cases: |
17 |
|
|
18 |
|
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 |
20 |
|
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 |
22 |
|
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 |
24 |
|
version. |
25 |
""" |
""" |
26 |
|
|
27 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
34 |
import support |
import support |
35 |
support.initthuban() |
support.initthuban() |
36 |
|
|
37 |
|
from xmlsupport import sax_eventlist |
38 |
|
from Thuban.Model.save import save_session |
39 |
from Thuban.Model.load import load_session, parse_color |
from Thuban.Model.load import load_session, parse_color |
|
from Thuban.Model.session import Session |
|
|
from Thuban.Model.map import Map |
|
|
from Thuban.Model.layer import Layer |
|
|
from Thuban.Model.proj import Projection |
|
40 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
|
|
|
|
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, FIELDTYPE_STRING |
|
|
|
|
41 |
from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\ |
from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\ |
42 |
ClassGroupSingleton, ClassGroupDefault |
ClassGroupSingleton, ClassGroupDefault |
43 |
|
|
44 |
|
|
45 |
def filenames_equal(name1, name2): |
def filenames_equal(name1, name2): |
46 |
"""Return true if the filenames name1 and name2 are equal. |
"""Return true if the filenames name1 and name2 are equal. |
47 |
|
|
54 |
return os.path.normpath(name1) == os.path.normpath(name2) |
return os.path.normpath(name1) == os.path.normpath(name2) |
55 |
|
|
56 |
|
|
57 |
contents_single_map = '''\ |
|
58 |
|
class LoadSessionTest(support.FileLoadTestCase): |
59 |
|
|
60 |
|
"""Base class for .thuban file loading tests |
61 |
|
|
62 |
|
Basically the same as the FileLoadTestCase, except that all tests |
63 |
|
use the '.thuban' extension by default and that setUp and tearDown |
64 |
|
handle sessions. |
65 |
|
""" |
66 |
|
|
67 |
|
file_extension = ".thuban" |
68 |
|
|
69 |
|
def setUp(self): |
70 |
|
"""Create the test files""" |
71 |
|
support.FileLoadTestCase.setUp(self) |
72 |
|
self.session = None |
73 |
|
|
74 |
|
def tearDown(self): |
75 |
|
if self.session is not None: |
76 |
|
self.session.Destroy() |
77 |
|
self.session = None |
78 |
|
|
79 |
|
def check_format(self): |
80 |
|
"""Check whether the file we loaded from matches the one that |
81 |
|
would be written. Call this from each test case after loading |
82 |
|
the session |
83 |
|
""" |
84 |
|
filename = self.temp_file_name(self.id() + ".roundtrip.thuban") |
85 |
|
save_session(self.session, filename) |
86 |
|
el1 = sax_eventlist(filename = filename) |
87 |
|
el2 = sax_eventlist(filename = self.filename()) |
88 |
|
self.assertEquals(el1, el2) |
89 |
|
|
90 |
|
|
91 |
|
class ClassificationTest(LoadSessionTest): |
92 |
|
|
93 |
|
""" |
94 |
|
Base class for tests that do some detailed checking of classifications |
95 |
|
""" |
96 |
|
|
97 |
|
def TestLayers(self, layers, expected): |
98 |
|
TITLE = 0 |
99 |
|
NUM_GROUPS = 1 |
100 |
|
CLASSES = 2 |
101 |
|
GROUP_TYPE = 0 |
102 |
|
GROUP_DATA = 1 |
103 |
|
GROUP_LABEL = 2 |
104 |
|
GROUP_PROPS = 3 |
105 |
|
|
106 |
|
eq = self.assertEquals |
107 |
|
|
108 |
|
eq(len(layers), len(expected)) |
109 |
|
|
110 |
|
for layer, data in zip(layers, expected): |
111 |
|
eq(layer.Title(), data[TITLE]) |
112 |
|
|
113 |
|
clazz = layer.GetClassification() |
114 |
|
eq(clazz.GetNumGroups(), data[NUM_GROUPS]) |
115 |
|
eq(clazz.GetNumGroups() + 1, len(data[CLASSES])) |
116 |
|
|
117 |
|
i = 0 |
118 |
|
for group in clazz: |
119 |
|
props = ClassGroupProperties() |
120 |
|
props.SetLineColor( |
121 |
|
parse_color(data[CLASSES][i][GROUP_PROPS][0])) |
122 |
|
props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1]) |
123 |
|
props.SetFill( |
124 |
|
parse_color(data[CLASSES][i][GROUP_PROPS][2])) |
125 |
|
|
126 |
|
if data[CLASSES][i][GROUP_TYPE] == "default": |
127 |
|
g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL]) |
128 |
|
elif data[CLASSES][i][GROUP_TYPE] == "range": |
129 |
|
g = ClassGroupRange(data[CLASSES][i][GROUP_DATA][0], |
130 |
|
data[CLASSES][i][GROUP_DATA][1], |
131 |
|
props, data[CLASSES][i][GROUP_LABEL]) |
132 |
|
elif data[CLASSES][i][GROUP_TYPE] == "single": |
133 |
|
g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA], |
134 |
|
props, data[CLASSES][i][GROUP_LABEL]) |
135 |
|
|
136 |
|
eq(group, g) |
137 |
|
|
138 |
|
i += 1 |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
class TestSingleLayer(LoadSessionTest): |
143 |
|
|
144 |
|
file_contents = '''\ |
145 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
146 |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
147 |
<session title="single map&layer"> |
<session title="single map&layer"> |
148 |
<map title="Test Map"> |
<map title="Test Map"> |
149 |
<projection> |
<projection name="Unknown"> |
150 |
<parameter value="zone=26"/> |
<parameter value="zone=26"/> |
151 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
152 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
153 |
</projection> |
</projection> |
154 |
<layer title="My Layer" stroke_width="1" fill="None" |
<layer title="My Layer" stroke_width="1" fill="None" |
155 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
156 |
stroke="#000000"/> |
stroke="#000000" visible="true"/> |
157 |
</map> |
</map> |
158 |
</session> |
</session> |
159 |
''' |
''' |
160 |
|
|
161 |
contents_classified_map_v0_2 = '''\ |
def test(self): |
162 |
|
"""Load a session with a single map with a single layer""" |
163 |
|
eq = self.assertEquals |
164 |
|
session = load_session(self.filename()) |
165 |
|
self.session = session |
166 |
|
|
167 |
|
# Check the title |
168 |
|
eq(session.Title(), "single map&layer") |
169 |
|
|
170 |
|
# the session has one map. |
171 |
|
maps = session.Maps() |
172 |
|
eq(len(maps), 1) |
173 |
|
|
174 |
|
# Check the map's attributes |
175 |
|
map = maps[0] |
176 |
|
eq(map.Title(), "Test Map") |
177 |
|
|
178 |
|
# the map has a single layer |
179 |
|
layers = map.Layers() |
180 |
|
eq(len(layers), 1) |
181 |
|
|
182 |
|
# Check the layer attributes |
183 |
|
layer = layers[0] |
184 |
|
eq(layer.Title(), "My Layer") |
185 |
|
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
186 |
|
os.path.join(self.temp_dir(), |
187 |
|
os.pardir, os.pardir, |
188 |
|
"Data", "iceland", |
189 |
|
"political.shp"))) |
190 |
|
eq(layer.GetClassification().GetDefaultFill(), Color.Transparent) |
191 |
|
eq(layer.GetClassification().GetDefaultLineColor().hex(), "#000000") |
192 |
|
eq(layer.Visible(), True) |
193 |
|
|
194 |
|
self.check_format() |
195 |
|
|
196 |
|
self.session.Destroy() |
197 |
|
self.session = None |
198 |
|
|
199 |
|
|
200 |
|
class TestLayerVisibility(LoadSessionTest): |
201 |
|
|
202 |
|
file_contents = '''\ |
203 |
|
<?xml version="1.0" encoding="UTF-8"?> |
204 |
|
<!DOCTYPE session SYSTEM "thuban.dtd"> |
205 |
|
<session title="single map&layer"> |
206 |
|
<map title="Test Map"> |
207 |
|
<projection name="Unknown"> |
208 |
|
<parameter value="zone=26"/> |
209 |
|
<parameter value="proj=utm"/> |
210 |
|
<parameter value="ellps=clrk66"/> |
211 |
|
</projection> |
212 |
|
<layer title="My Layer" stroke_width="1" fill="None" |
213 |
|
filename="../../Data/iceland/political.shp" |
214 |
|
stroke="#000000" visible="false"> |
215 |
|
</layer> |
216 |
|
</map> |
217 |
|
</session> |
218 |
|
''' |
219 |
|
|
220 |
|
def test(self): |
221 |
|
"""Test that the visible flag is correctly loaded for a layer.""" |
222 |
|
eq = self.assertEquals |
223 |
|
session = load_session(self.filename()) |
224 |
|
self.session = session |
225 |
|
maps = session.Maps() |
226 |
|
eq(len(maps), 1) |
227 |
|
map = maps[0] |
228 |
|
layers = map.Layers() |
229 |
|
eq(len(layers), 1) |
230 |
|
layer = layers[0] |
231 |
|
|
232 |
|
eq(layer.Visible(), False) |
233 |
|
|
234 |
|
self.check_format() |
235 |
|
|
236 |
|
|
237 |
|
class TestClassification(ClassificationTest): |
238 |
|
|
239 |
|
file_contents = '''\ |
240 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
241 |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
242 |
<session title="single map&layer"> |
<session title="single map&layer"> |
286 |
</session> |
</session> |
287 |
''' |
''' |
288 |
|
|
289 |
contents_test_labels = '''\ |
def test(self): |
290 |
|
"""Load a Thuban session with a map and classified layers.""" |
291 |
|
session = load_session(self.filename()) |
292 |
|
self.session = session |
293 |
|
|
294 |
|
map = self.session.Maps()[0] # only one map in the sample |
295 |
|
|
296 |
|
expected = [("My Layer", 2, |
297 |
|
[("default", (), "", |
298 |
|
("#000000", 1, "None")), |
299 |
|
("single", "1", "", |
300 |
|
("#000000", 2, "None")), |
301 |
|
("single", "1", "", |
302 |
|
("#000000", 10, "None"))]), |
303 |
|
("My Layer 2", 4, |
304 |
|
[("default", (), "", |
305 |
|
("#000000", 2, "None")), |
306 |
|
("range", (0, 1), "", |
307 |
|
("#111111", 1, "None")), |
308 |
|
("single", .5, "", |
309 |
|
("#000000", 1, "#111111")), |
310 |
|
("range", (-1, 0), "", |
311 |
|
("#000000", 1, "None")), |
312 |
|
("single", -.5, "", |
313 |
|
("#000000", 1, "None"))])] |
314 |
|
|
315 |
|
self.TestLayers(map.Layers(), expected) |
316 |
|
|
317 |
|
|
318 |
|
class TestLabels(ClassificationTest): |
319 |
|
|
320 |
|
file_contents = '''\ |
321 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
322 |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
323 |
<session title="single map&layer"> |
<session title="single map&layer"> |
324 |
<map title="Test Map"> |
<map title="Test Map"> |
325 |
<projection> |
<projection name="Unknown"> |
326 |
<parameter value="zone=26"/> |
<parameter value="zone=26"/> |
327 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
328 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
329 |
</projection> |
</projection> |
330 |
<layer title="My Layer" stroke_width="1" fill="None" |
<layer title="My Layer" stroke_width="1" fill="None" |
331 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
332 |
stroke="#000000"> |
stroke="#000000" visible="true"> |
333 |
<classification field="POPYREG" field_type="string"> |
<classification field="POPYREG" field_type="string"> |
334 |
<clnull label="hallo"> |
<clnull label="hallo"> |
335 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
343 |
</session> |
</session> |
344 |
''' |
''' |
345 |
|
|
346 |
contents_test_layer_projection = '''\ |
def test(self): |
347 |
|
"""Load a session and test for reading the group labels.""" |
348 |
|
eq = self.assertEquals |
349 |
|
session = load_session(self.filename()) |
350 |
|
self.session = session |
351 |
|
|
352 |
|
map = self.session.Maps()[0] # only one map in the sample |
353 |
|
|
354 |
|
expected = [("My Layer", 1, |
355 |
|
[("default", (), "hallo", |
356 |
|
("#000000", 1, "None")), |
357 |
|
("single", "1", "welt", |
358 |
|
("#000000", 2, "None"))])] |
359 |
|
|
360 |
|
self.TestLayers(map.Layers(), expected) |
361 |
|
self.check_format() |
362 |
|
|
363 |
|
|
364 |
|
class TestLayerProjection(LoadSessionTest): |
365 |
|
|
366 |
|
file_contents = '''\ |
367 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
368 |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
<!DOCTYPE session SYSTEM "thuban.dtd"> |
369 |
<session title="single map&layer"> |
<session title="single map&layer"> |
370 |
<map title="Test Map"> |
<map title="Test Map"> |
371 |
<projection> |
<projection name="Unknown"> |
372 |
<parameter value="zone=26"/> |
<parameter value="zone=26"/> |
373 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
374 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
375 |
</projection> |
</projection> |
376 |
<layer title="My Layer" stroke_width="1" fill="None" |
<layer title="My Layer" stroke_width="1" fill="None" |
377 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
378 |
stroke="#000000"> |
stroke="#000000" visible="true"> |
379 |
<projection name="hello"> |
<projection name="hello"> |
380 |
<parameter value="zone=13"/> |
<parameter value="zone=13"/> |
381 |
<parameter value="proj=tmerc"/> |
<parameter value="proj=tmerc"/> |
392 |
</layer> |
</layer> |
393 |
<layer title="My Layer" stroke_width="1" fill="None" |
<layer title="My Layer" stroke_width="1" fill="None" |
394 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
395 |
stroke="#000000"> |
stroke="#000000" visible="true"> |
396 |
<projection> |
<projection name="Unknown"> |
397 |
<parameter value="proj=lcc"/> |
<parameter value="proj=lcc"/> |
398 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
399 |
</projection> |
</projection> |
402 |
</session> |
</session> |
403 |
''' |
''' |
404 |
|
|
405 |
contents_test_visible = '''\ |
def test(self): |
406 |
<?xml version="1.0" encoding="UTF-8"?> |
"""Test loading layers with projections""" |
|
<!DOCTYPE session SYSTEM "thuban.dtd"> |
|
|
<session title="single map&layer"> |
|
|
<map title="Test Map"> |
|
|
<projection> |
|
|
<parameter value="zone=26"/> |
|
|
<parameter value="proj=utm"/> |
|
|
<parameter value="ellps=clrk66"/> |
|
|
</projection> |
|
|
<layer title="My Layer" stroke_width="1" fill="None" |
|
|
filename="../../Data/iceland/political.shp" |
|
|
stroke="#000000" visible="false"> |
|
|
</layer> |
|
|
</map> |
|
|
</session> |
|
|
''' |
|
|
|
|
|
class LoadSessionTest(unittest.TestCase, support.FileTestMixin): |
|
|
|
|
|
def setUp(self): |
|
|
"""Create the test files""" |
|
|
file = open(self.temp_file_name("load_singlelayer.thuban"), "w") |
|
|
file.write(contents_single_map) |
|
|
file.close() |
|
|
|
|
|
file = open(self.temp_file_name("load_classified_v0_2.thuban"), "w") |
|
|
file.write(contents_classified_map_v0_2) |
|
|
file.close() |
|
|
|
|
|
file = open(self.temp_file_name("load_labels.thuban"), "w") |
|
|
file.write(contents_test_labels) |
|
|
file.close() |
|
|
|
|
|
file = open(self.temp_file_name("load_layerproj.thuban"), "w") |
|
|
file.write(contents_test_layer_projection) |
|
|
file.close() |
|
|
|
|
|
file = open(self.temp_file_name("load_visible.thuban"), "w") |
|
|
file.write(contents_test_visible) |
|
|
file.close() |
|
|
|
|
|
self.session = None |
|
|
|
|
|
def tearDown(self): |
|
|
if self.session is not None: |
|
|
self.session.Destroy() |
|
|
self.session = None |
|
|
|
|
|
def testSingleLayer(self): |
|
|
"""Load a session with a single map with a single layer""" |
|
|
eq = self.assertEquals |
|
|
session = load_session(self.temp_file_name("load_singlelayer.thuban")) |
|
|
self.session = session |
|
|
|
|
|
# Check the title |
|
|
eq(session.Title(), "single map&layer") |
|
|
|
|
|
# the session has one map. |
|
|
maps = session.Maps() |
|
|
eq(len(maps), 1) |
|
|
|
|
|
# Check the map's attributes |
|
|
map = maps[0] |
|
|
eq(map.Title(), "Test Map") |
|
|
|
|
|
# the map has a single layer |
|
|
layers = map.Layers() |
|
|
eq(len(layers), 1) |
|
|
|
|
|
# Check the layer attributes |
|
|
layer = layers[0] |
|
|
eq(layer.Title(), "My Layer") |
|
|
self.failUnless(filenames_equal(layer.filename, |
|
|
os.path.join(self.temp_dir(), |
|
|
os.pardir, os.pardir, |
|
|
"Data", "iceland", |
|
|
"political.shp"))) |
|
|
eq(layer.GetClassification().GetDefaultFill(), Color.Transparent) |
|
|
eq(layer.GetClassification().GetDefaultLineColor().hex(), "#000000") |
|
|
eq(layer.Visible(), True) |
|
|
|
|
|
self.session.Destroy() |
|
|
self.session = None |
|
|
|
|
|
def testLayerVisibility(self): |
|
|
"""Test that the visible flag is correctly loaded for a layer.""" |
|
|
|
|
|
eq = self.assertEquals |
|
|
session = load_session(self.temp_file_name("load_visible.thuban")) |
|
|
self.session = session |
|
|
maps = session.Maps() |
|
|
eq(len(maps), 1) |
|
|
map = maps[0] |
|
|
layers = map.Layers() |
|
|
eq(len(layers), 1) |
|
|
layer = layers[0] |
|
|
|
|
|
eq(layer.Visible(), False) |
|
|
|
|
|
def testClassification(self): |
|
|
"""Load a session with a map and classified layers.""" |
|
|
|
|
|
session = load_session(self.temp_file_name("load_classified_v0_2.thuban")) |
|
|
self.session = session |
|
|
|
|
|
map = self.session.Maps()[0] # only one map in the sample |
|
|
|
|
|
expected = [("My Layer", 2, |
|
|
[("default", (), "", |
|
|
("#000000", 1, "None")), |
|
|
("single", "1", "", |
|
|
("#000000", 2, "None")), |
|
|
("single", "1", "", |
|
|
("#000000", 10, "None"))]), |
|
|
("My Layer 2", 4, |
|
|
[("default", (), "", |
|
|
("#000000", 2, "None")), |
|
|
("range", (0, 1), "", |
|
|
("#111111", 1, "None")), |
|
|
("single", .5, "", |
|
|
("#000000", 1, "#111111")), |
|
|
("range", (-1, 0), "", |
|
|
("#000000", 1, "None")), |
|
|
("single", -.5, "", |
|
|
("#000000", 1, "None"))])] |
|
|
|
|
|
self.TestLayers(map.Layers(), expected) |
|
|
|
|
|
def TestLayers(self, layers, expected): |
|
|
|
|
|
TITLE = 0 |
|
|
NUM_GROUPS = 1 |
|
|
CLASSES = 2 |
|
|
GROUP_TYPE = 0 |
|
|
GROUP_DATA = 1 |
|
|
GROUP_LABEL = 2 |
|
|
GROUP_PROPS = 3 |
|
|
|
|
|
eq = self.assertEquals |
|
|
|
|
|
eq(len(layers), len(expected)) |
|
|
|
|
|
for layer, data in zip(layers, expected): |
|
|
eq(layer.Title(), data[TITLE]) |
|
|
|
|
|
clazz = layer.GetClassification() |
|
|
eq(clazz.GetNumGroups(), data[NUM_GROUPS]) |
|
|
eq(clazz.GetNumGroups() + 1, len(data[CLASSES])) |
|
|
|
|
|
i = 0 |
|
|
for group in clazz: |
|
|
|
|
|
props = ClassGroupProperties() |
|
|
props.SetLineColor( |
|
|
parse_color(data[CLASSES][i][GROUP_PROPS][0])) |
|
|
props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1]) |
|
|
props.SetFill( |
|
|
parse_color(data[CLASSES][i][GROUP_PROPS][2])) |
|
|
|
|
|
if data[CLASSES][i][GROUP_TYPE] == "default": |
|
|
g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL]) |
|
|
elif data[CLASSES][i][GROUP_TYPE] == "range": |
|
|
g = ClassGroupRange(data[CLASSES][i][GROUP_DATA][0], |
|
|
data[CLASSES][i][GROUP_DATA][1], |
|
|
props, data[CLASSES][i][GROUP_LABEL]) |
|
|
elif data[CLASSES][i][GROUP_TYPE] == "single": |
|
|
g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA], |
|
|
props, data[CLASSES][i][GROUP_LABEL]) |
|
|
|
|
|
eq(group, g) |
|
|
|
|
|
i += 1 |
|
|
|
|
|
def testLabels(self): |
|
|
"""Load a session and test for reading the group labels.""" |
|
|
|
|
|
eq = self.assertEquals |
|
|
session = load_session(self.temp_file_name("load_labels.thuban")) |
|
|
self.session = session |
|
|
|
|
|
map = self.session.Maps()[0] # only one map in the sample |
|
|
|
|
|
expected = [("My Layer", 1, |
|
|
[("default", (), "hallo", |
|
|
("#000000", 1, "None")), |
|
|
("single", "1", "welt", |
|
|
("#000000", 2, "None"))])] |
|
|
|
|
|
self.TestLayers(map.Layers(), expected) |
|
|
|
|
|
def testLayerProjection(self): |
|
407 |
eq = self.assertEquals |
eq = self.assertEquals |
408 |
neq = self.assertNotEqual |
neq = self.assertNotEqual |
409 |
|
|
410 |
session = load_session(self.temp_file_name("load_layerproj.thuban")) |
session = load_session(self.filename()) |
411 |
self.session = session |
self.session = session |
412 |
|
|
413 |
map = self.session.Maps()[0] # only one map in the sample |
map = self.session.Maps()[0] # only one map in the sample |
429 |
eq(proj.GetParameter("proj"), "lcc") |
eq(proj.GetParameter("proj"), "lcc") |
430 |
eq(proj.GetParameter("ellps"), "clrk66") |
eq(proj.GetParameter("ellps"), "clrk66") |
431 |
|
|
432 |
if __name__ == "__main__": |
self.check_format() |
433 |
unittest.main() |
|
434 |
|
|
435 |
|
class TestRasterLayer(LoadSessionTest): |
436 |
|
|
437 |
|
file_contents = '''\ |
438 |
|
<?xml version="1.0" encoding="UTF-8"?> |
439 |
|
<!DOCTYPE session SYSTEM "thuban.dtd"> |
440 |
|
<session title="single map&layer"> |
441 |
|
<map title="Test Map"> |
442 |
|
<rasterlayer title="My RasterLayer" |
443 |
|
filename="../../Data/iceland/island.tif" |
444 |
|
visible="false"> |
445 |
|
</rasterlayer> |
446 |
|
</map> |
447 |
|
</session> |
448 |
|
''' |
449 |
|
|
450 |
|
def test(self): |
451 |
|
eq = self.assertEquals |
452 |
|
neq = self.assertNotEqual |
453 |
|
|
454 |
|
session = load_session(self.filename()) |
455 |
|
self.session = session |
456 |
|
|
457 |
|
map = self.session.Maps()[0] # only one map in the sample |
458 |
|
|
459 |
|
layer = map.Layers()[0] # one layer in the sample |
460 |
|
|
461 |
|
eq(layer.Title(), "My RasterLayer") |
462 |
|
self.failIf(layer.Visible()) |
463 |
|
self.failUnless(filenames_equal(layer.GetImageFilename(), |
464 |
|
os.path.join(self.temp_dir(), |
465 |
|
os.pardir, os.pardir, |
466 |
|
"Data", "iceland", |
467 |
|
"island.tif"))) |
468 |
|
self.check_format() |
469 |
|
|
470 |
|
if __name__ == "__main__": |
471 |
|
unittest.main() |