40 |
|
|
41 |
from Thuban.Model.save import save_session |
from Thuban.Model.save import save_session |
42 |
from Thuban.Model.load import load_session, parse_color, LoadError |
from Thuban.Model.load import load_session, parse_color, LoadError |
43 |
from Thuban.Model.color Transparent |
from Thuban.Model.color import Transparent |
44 |
from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\ |
from Thuban.Model.classification import ClassGroupProperties, ClassGroupRange,\ |
45 |
ClassGroupSingleton, ClassGroupDefault |
ClassGroupSingleton, ClassGroupDefault |
46 |
|
|
80 |
self.session = None |
self.session = None |
81 |
|
|
82 |
|
|
83 |
dtd = "http://thuban.intevation.org/dtds/thuban-0.8.dtd" |
dtd = "http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" |
84 |
thubanids = [((dtd, n), (None, "id")) for n in |
thubanids = [((dtd, n), (None, "id")) for n in |
85 |
["fileshapesource", "filetable", "jointable", |
["fileshapesource", "filetable", "jointable", |
86 |
"derivedshapesource"]] |
"derivedshapesource"]] |
150 |
if data[CLASSES][i][GROUP_TYPE] == "default": |
if data[CLASSES][i][GROUP_TYPE] == "default": |
151 |
g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL]) |
g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL]) |
152 |
elif data[CLASSES][i][GROUP_TYPE] == "range": |
elif data[CLASSES][i][GROUP_TYPE] == "range": |
153 |
g = ClassGroupRange(data[CLASSES][i][GROUP_DATA][0], |
g = ClassGroupRange((data[CLASSES][i][GROUP_DATA][0], |
154 |
data[CLASSES][i][GROUP_DATA][1], |
data[CLASSES][i][GROUP_DATA][1]), |
155 |
props, data[CLASSES][i][GROUP_LABEL]) |
props, data[CLASSES][i][GROUP_LABEL]) |
156 |
elif data[CLASSES][i][GROUP_TYPE] == "single": |
elif data[CLASSES][i][GROUP_TYPE] == "single": |
157 |
g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA], |
g = ClassGroupSingleton(data[CLASSES][i][GROUP_DATA], |
167 |
|
|
168 |
file_contents = '''\ |
file_contents = '''\ |
169 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
170 |
<!DOCTYPE session SYSTEM "thuban-0.8.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
171 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" |
172 |
title="single map&layer"> |
title="single map&layer"> |
173 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
174 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
228 |
|
|
229 |
file_contents = '''\ |
file_contents = '''\ |
230 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
231 |
<!DOCTYPE session SYSTEM "thuban-0.8.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
232 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" |
233 |
title="single map&layer"> |
title="single map&layer"> |
234 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
235 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
287 |
<clpoint value="1"> |
<clpoint value="1"> |
288 |
<cldata stroke="#000000" stroke_width="10" fill="None"/> |
<cldata stroke="#000000" stroke_width="10" fill="None"/> |
289 |
</clpoint> |
</clpoint> |
290 |
|
<clpoint value="\xc3\xa4\xc3\xb6\xc3\xbc" |
291 |
|
label="\xc3\x9cml\xc3\xa4uts"> |
292 |
|
<cldata fill="None" stroke="#000000" stroke_width="1"/> |
293 |
|
</clpoint> |
294 |
</classification> |
</classification> |
295 |
</layer> |
</layer> |
296 |
<layer title="My Layer 2" stroke_width="1" fill="None" |
<layer title="My Layer 2" stroke_width="1" fill="None" |
325 |
|
|
326 |
map = self.session.Maps()[0] # only one map in the sample |
map = self.session.Maps()[0] # only one map in the sample |
327 |
|
|
328 |
expected = [("My Layer", 2, |
expected = [("My Layer", 3, |
329 |
[("default", (), "", |
[("default", (), "", |
330 |
("#000000", 1, "None")), |
("#000000", 1, "None")), |
331 |
("single", "1", "", |
("single", "1", "", |
332 |
("#000000", 2, "None")), |
("#000000", 2, "None")), |
333 |
("single", "1", "", |
("single", "1", "", |
334 |
("#000000", 10, "None"))]), |
("#000000", 10, "None")), |
335 |
|
("single", "\xe4\xf6\xfc", "\xdcml\xe4uts", |
336 |
|
("#000000", 1, "None"))]), |
337 |
("My Layer 2", 4, |
("My Layer 2", 4, |
338 |
[("default", (), "", |
[("default", (), "", |
339 |
("#000000", 2, "None")), |
("#000000", 2, "None")), |
353 |
|
|
354 |
file_contents = '''\ |
file_contents = '''\ |
355 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
356 |
<!DOCTYPE session SYSTEM "thuban-0.8.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
357 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" |
358 |
title="single map&layer"> |
title="single map&layer"> |
359 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
360 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
401 |
|
|
402 |
file_contents = '''\ |
file_contents = '''\ |
403 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
404 |
<!DOCTYPE session SYSTEM "thuban-0.8.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
405 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" |
406 |
title="single map&layer"> |
title="single map&layer"> |
407 |
<fileshapesource filetype="shapefile" id="D2" |
<fileshapesource filetype="shapefile" id="D2" |
408 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
475 |
|
|
476 |
file_contents = '''\ |
file_contents = '''\ |
477 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
478 |
<!DOCTYPE session SYSTEM "thuban-0.8.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
479 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" |
480 |
title="single map&layer"> |
title="single map&layer"> |
481 |
<map title="Test Map"> |
<map title="Test Map"> |
482 |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
509 |
class TestJoinedTable(LoadSessionTest): |
class TestJoinedTable(LoadSessionTest): |
510 |
|
|
511 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
512 |
<!DOCTYPE session SYSTEM "thuban-0.8.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
513 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd" title="A Joined Table session"> |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" title="A Joined Table session"> |
514 |
<fileshapesource filetype="shapefile" id="D137227612" |
<fileshapesource filetype="shapefile" id="D137227612" |
515 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
516 |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
517 |
title="Some Title"/> |
title="Some Title"/> |
518 |
<jointable leftcolumn="RDLNTYPE" right="D136171140" |
<jointable id="D136169900" title="Joined" |
519 |
title="Joined" rightcolumn="RDTYPE" id="D136169900" left="D137227612"/> |
right="D136171140" left="D137227612" |
520 |
|
leftcolumn="RDLNTYPE" rightcolumn="RDTYPE" |
521 |
|
jointype="LEFT OUTER"/> |
522 |
<derivedshapesource table="D136169900" shapesource="D137227612" |
<derivedshapesource table="D136169900" shapesource="D137227612" |
523 |
id="D136170932"/> |
id="D136170932"/> |
524 |
<map title="Test Map"> |
<map title="Test Map"> |
550 |
# FIXME: The tests shouldn't assume a certain order of the tables |
# FIXME: The tests shouldn't assume a certain order of the tables |
551 |
self.assertEquals(tables[0].Title(), "Some Title") |
self.assertEquals(tables[0].Title(), "Some Title") |
552 |
self.assertEquals(tables[1].Title(), "Joined") |
self.assertEquals(tables[1].Title(), "Joined") |
553 |
|
self.assertEquals(tables[1].JoinType(), "LEFT OUTER") |
554 |
self.check_format() |
self.check_format() |
555 |
|
|
556 |
|
|
558 |
|
|
559 |
file_contents = '''\ |
file_contents = '''\ |
560 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
561 |
<!DOCTYPE session SYSTEM "thuban-0.8.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
562 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.8.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd" |
563 |
title="single map&layer"> |
title="single map&layer"> |
564 |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
565 |
<map title="Test Map"> |
<map title="Test Map"> |
582 |
try: |
try: |
583 |
self.session = load_session(self.filename()) |
self.session = load_session(self.filename()) |
584 |
except LoadError, value: |
except LoadError, value: |
585 |
pass |
# Check the actual messge in value to make sure the |
586 |
|
# LoadError really was about the missing attribute |
587 |
|
self.assertEquals(str(value), |
588 |
|
"Element " |
589 |
|
"(u'http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd'," |
590 |
|
" u'fileshapesource') requires an attribute 'filetype'") |
591 |
else: |
else: |
592 |
self.fail("Missing filetype attribute doesn't raise LoadError") |
self.fail("Missing filetype attribute doesn't raise LoadError") |
593 |
|
|