1 |
# Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH |
# Copyright (c) 2002, 2003, 2004, 2005, 2007 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
37 |
from Thuban.Model.data import DerivedShapeStore, SHAPETYPE_ARC |
from Thuban.Model.data import DerivedShapeStore, SHAPETYPE_ARC |
38 |
|
|
39 |
from Thuban.Model.classification import ClassGroupSingleton, ClassGroupRange, \ |
from Thuban.Model.classification import ClassGroupSingleton, ClassGroupRange, \ |
40 |
ClassGroupProperties |
ClassGroupPattern, ClassGroupProperties |
41 |
|
|
42 |
from Thuban.Model.range import Range |
from Thuban.Model.range import Range |
43 |
|
|
66 |
class SaveSessionTest(unittest.TestCase, support.FileTestMixin, |
class SaveSessionTest(unittest.TestCase, support.FileTestMixin, |
67 |
xmlsupport.ValidationTest): |
xmlsupport.ValidationTest): |
68 |
|
|
69 |
dtd = "http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
dtd = "http://thuban.intevation.org/dtds/thuban-1.2.1.dtd" |
70 |
thubanids = [((dtd, n), (None, "id")) for n in |
thubanids = [((dtd, n), (None, "id")) for n in |
71 |
["fileshapesource", "filetable", "jointable", |
["fileshapesource", "filetable", "jointable", |
72 |
"derivedshapesource", "dbshapesource", "dbconnection"]] |
"derivedshapesource", "dbshapesource", "dbconnection"]] |
112 |
file.close() |
file.close() |
113 |
self.compare_xml(written_contents, |
self.compare_xml(written_contents, |
114 |
'<?xml version="1.0" encoding="UTF-8"?>\n' |
'<?xml version="1.0" encoding="UTF-8"?>\n' |
115 |
'<!DOCTYPE session SYSTEM "thuban-1.1.dtd">\n' |
'<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd">\n' |
116 |
'<session title="empty session" ' |
'<session title="empty session" ' |
117 |
'xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd">' |
'xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd">' |
118 |
'\n</session>\n') |
'\n</session>\n') |
119 |
|
|
120 |
self.validate_data(written_contents) |
self.validate_data(written_contents) |
142 |
written_contents = file.read() |
written_contents = file.read() |
143 |
file.close() |
file.close() |
144 |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
145 |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd"> |
146 |
<session title="single map&layer" |
<session title="single map&layer" |
147 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd"> |
148 |
<fileshapesource id="D1" |
<fileshapesource id="D1" |
149 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
150 |
filetype="shapefile"/> |
filetype="shapefile"/> |
210 |
written_contents = file.read() |
written_contents = file.read() |
211 |
file.close() |
file.close() |
212 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
213 |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd"> |
214 |
<session title="single map&layer" |
<session title="single map&layer" |
215 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd"> |
216 |
<fileshapesource id="D1" |
<fileshapesource id="D1" |
217 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
218 |
filetype="shapefile"/> |
filetype="shapefile"/> |
282 |
written_contents = file.read() |
written_contents = file.read() |
283 |
file.close() |
file.close() |
284 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
285 |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd"> |
286 |
<session title="single map&layer" |
<session title="single map&layer" |
287 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd"> |
288 |
<map title="Test Map"> |
<map title="Test Map"> |
289 |
<rasterlayer title="My RasterLayer" |
<rasterlayer title="My RasterLayer" |
290 |
filename="../../Data/iceland/island.tif" |
filename="../../Data/iceland/island.tif" |
291 |
visible="true" %s %s> |
visible="true" %s> |
292 |
</rasterlayer> |
</rasterlayer> |
293 |
</map> |
</map> |
294 |
</session>''' % (opname, maskname) |
</session>''' % (opname, ) |
295 |
#print written_contents |
#print written_contents |
296 |
#print "********************************************" |
#print "********************************************" |
297 |
#print expected_contents |
#print expected_contents |
342 |
ClassGroupProperties(), |
ClassGroupProperties(), |
343 |
internal_from_unicode(u'\xdcml\xe4uts'))) # Uemlaeuts |
internal_from_unicode(u'\xdcml\xe4uts'))) # Uemlaeuts |
344 |
|
|
345 |
|
# Pattern |
346 |
|
clazz.AppendGroup(ClassGroupPattern("BUI", ClassGroupProperties(), |
347 |
|
"pattern")) |
348 |
|
|
349 |
filename = self.temp_file_name("%s.thuban" % self.id()) |
filename = self.temp_file_name("%s.thuban" % self.id()) |
350 |
save_session(session, filename) |
save_session(session, filename) |
353 |
written_contents = file.read() |
written_contents = file.read() |
354 |
file.close() |
file.close() |
355 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
356 |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd"> |
357 |
<session title="Map with Classifications" |
<session title="Map with Classifications" |
358 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd"> |
359 |
<fileshapesource id="D1" |
<fileshapesource id="D1" |
360 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
361 |
filetype="shapefile"/> |
filetype="shapefile"/> |
393 |
label="\xc3\x9cml\xc3\xa4uts"> |
label="\xc3\x9cml\xc3\xa4uts"> |
394 |
<cldata fill="None" stroke="#000000" stroke_width="1"/> |
<cldata fill="None" stroke="#000000" stroke_width="1"/> |
395 |
</clpoint> |
</clpoint> |
396 |
|
<clpattern pattern="BUI" label="pattern"> |
397 |
|
<cldata fill="None" stroke="#000000" stroke_width="1"/> |
398 |
|
</clpattern> |
399 |
</classification> |
</classification> |
400 |
</layer> |
</layer> |
401 |
</map> |
</map> |
425 |
written_contents = file.read() |
written_contents = file.read() |
426 |
file.close() |
file.close() |
427 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
428 |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd"> |
429 |
<session title="a DBF Table session" |
<session title="a DBF Table session" |
430 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd"> |
431 |
<filetable id="D1" filename="../../Data/iceland/political.dbf" |
<filetable id="D1" filename="../../Data/iceland/political.dbf" |
432 |
filetype="DBF" title="political"/> |
filetype="DBF" title="political"/> |
433 |
</session>''' |
</session>''' |
483 |
written_contents = file.read() |
written_contents = file.read() |
484 |
file.close() |
file.close() |
485 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
486 |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd"> |
487 |
<session title="A Joined Table session" |
<session title="A Joined Table session" |
488 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd"> |
489 |
<fileshapesource filename="../../Data/iceland/roads-line.shp" |
<fileshapesource filename="../../Data/iceland/roads-line.shp" |
490 |
filetype="shapefile" id="D142197204"/> |
filetype="shapefile" id="D142197204"/> |
491 |
<filetable filename="save_joinedtable.dbf" |
<filetable filename="save_joinedtable.dbf" |
561 |
written = file.read() |
written = file.read() |
562 |
file.close() |
file.close() |
563 |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
564 |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.2.1.dtd"> |
565 |
<session title="A PostGIS Session" |
<session title="A PostGIS Session" |
566 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.2.1.dtd"> |
567 |
<dbconnection id="DB" |
<dbconnection id="DB" |
568 |
dbtype="postgis" dbname="plugh" |
dbtype="postgis" dbname="plugh" |
569 |
host="xyzzy" port="42" |
host="xyzzy" port="42" |