1 |
# Copyright (c) 2002, 2003 by Intevation GmbH |
# Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
16 |
Maintenance of the test cases: |
Maintenance of the test cases: |
17 |
|
|
18 |
When during a development period the file format is changed with respect |
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 |
to the last released version for the first time, the tests here should |
20 |
copied to the version specific test file. The round-trip tests which |
be 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 |
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 |
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 |
here are actually ones that may have been written by the current thuban |
40 |
import dbflib |
import dbflib |
41 |
import shapelib |
import shapelib |
42 |
|
|
43 |
|
from Thuban import internal_from_unicode |
44 |
from Thuban.Model.save import save_session |
from Thuban.Model.save import save_session |
45 |
from Thuban.Model.load import load_session, parse_color, LoadError, \ |
from Thuban.Model.load import load_session, parse_color, LoadError, \ |
46 |
LoadCancelled |
LoadCancelled |
54 |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
55 |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
56 |
|
|
|
|
|
57 |
def filenames_equal(name1, name2): |
def filenames_equal(name1, name2): |
58 |
"""Return true if the filenames name1 and name2 are equal. |
"""Return true if the filenames name1 and name2 are equal. |
59 |
|
|
89 |
self.session = None |
self.session = None |
90 |
|
|
91 |
|
|
92 |
dtd = "http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
dtd = "http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
93 |
thubanids = [((dtd, n), (None, "id")) for n in |
thubanids = [((dtd, n), (None, "id")) for n in |
94 |
["fileshapesource", "filetable", "jointable", |
["fileshapesource", "filetable", "jointable", |
95 |
"derivedshapesource"]] |
"derivedshapesource"]] |
124 |
print a != b and "***************" or "" |
print a != b and "***************" or "" |
125 |
print a |
print a |
126 |
print b |
print b |
127 |
|
|
128 |
self.assertEquals(el1, el2, |
self.assertEquals(el1, el2, |
129 |
"loaded file not equivalent to the saved file") |
"loaded file not equivalent to the saved file") |
130 |
|
|
163 |
props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1]) |
props.SetLineWidth(data[CLASSES][i][GROUP_PROPS][1]) |
164 |
props.SetFill( |
props.SetFill( |
165 |
parse_color(data[CLASSES][i][GROUP_PROPS][2])) |
parse_color(data[CLASSES][i][GROUP_PROPS][2])) |
166 |
|
if len(data[CLASSES][i][GROUP_PROPS]) > 3: |
167 |
|
props.SetSize(data[CLASSES][i][GROUP_PROPS][3]) |
168 |
|
|
169 |
if data[CLASSES][i][GROUP_TYPE] == "default": |
if data[CLASSES][i][GROUP_TYPE] == "default": |
170 |
g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL]) |
g = ClassGroupDefault(props, data[CLASSES][i][GROUP_LABEL]) |
188 |
# want to test whether the loading code handles that correctly. |
# want to test whether the loading code handles that correctly. |
189 |
file_contents = '''\ |
file_contents = '''\ |
190 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
191 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
192 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
193 |
title="Stra\xc3\x9fen & Landmarken"> |
title="Stra\xc3\x9fen & Landmarken"> |
194 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
195 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
201 |
<parameter value="units=m"/> |
<parameter value="units=m"/> |
202 |
<parameter value="zone=27"/> |
<parameter value="zone=27"/> |
203 |
</projection> |
</projection> |
204 |
<layer shapestore="D1" visible="true" |
<layer shapestore="D1" visible="true" title="K\xc3\xbcste"> |
205 |
stroke="#000000" title="K\xc3\xbcste" stroke_width="1" |
<classification> |
206 |
fill="None"/> |
<clnull label=""> |
207 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
208 |
|
</clnull> |
209 |
|
</classification> |
210 |
|
</layer> |
211 |
</map> |
</map> |
212 |
</session> |
</session> |
213 |
''' |
''' |
219 |
self.session = session |
self.session = session |
220 |
|
|
221 |
# Check the title |
# Check the title |
222 |
eq(session.Title(), "Stra\xdfen & Landmarken") |
eq(session.Title(), internal_from_unicode(u"Stra\xdfen & Landmarken")) |
223 |
|
|
224 |
# the session has one map. |
# the session has one map. |
225 |
maps = session.Maps() |
maps = session.Maps() |
227 |
|
|
228 |
# Check the map's attributes |
# Check the map's attributes |
229 |
map = maps[0] |
map = maps[0] |
230 |
eq(map.Title(), "\xdcbersicht") |
eq(map.Title(), internal_from_unicode(u"\xdcbersicht")) |
231 |
proj = map.GetProjection() |
proj = map.GetProjection() |
232 |
eq(proj.GetName(), "WGS 84 / UTM zone 27N") |
eq(proj.GetName(), "WGS 84 / UTM zone 27N") |
233 |
eq(proj.EPSGCode(), "32627") |
eq(proj.EPSGCode(), "32627") |
242 |
|
|
243 |
# Check the layer attributes |
# Check the layer attributes |
244 |
layer = layers[0] |
layer = layers[0] |
245 |
eq(layer.Title(), "K\xfcste") |
eq(layer.Title(), internal_from_unicode(u"K\xfcste")) |
246 |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
247 |
os.path.join(self.temp_dir(), |
os.path.join(self.temp_dir(), |
248 |
os.pardir, os.pardir, |
os.pardir, os.pardir, |
284 |
|
|
285 |
file_contents = '''\ |
file_contents = '''\ |
286 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
287 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
288 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
289 |
title="Non ASCII column name test"> |
title="Non ASCII column name test"> |
290 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
291 |
filename="TestNonAsciiColumnName.shp"/> |
filename="TestNonAsciiColumnName.shp"/> |
297 |
<parameter value="units=m"/> |
<parameter value="units=m"/> |
298 |
<parameter value="zone=27"/> |
<parameter value="zone=27"/> |
299 |
</projection> |
</projection> |
300 |
<layer shapestore="D1" visible="true" |
<layer shapestore="D1" visible="true" title="layer"> |
|
stroke="#000000" title="layer" stroke_width="1" |
|
|
fill="None"> |
|
301 |
<classification field="Fl\xc3\xa4che" field_type="double"> |
<classification field="Fl\xc3\xa4che" field_type="double"> |
302 |
<clnull label=""> |
<clnull label=""> |
303 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
359 |
|
|
360 |
file_contents = '''\ |
file_contents = '''\ |
361 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
362 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
363 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
364 |
title="single map&layer"> |
title="single map&layer"> |
365 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
366 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
370 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
371 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
372 |
</projection> |
</projection> |
373 |
<layer shapestore="D1" visible="false" stroke="#000000" |
<layer shapestore="D1" visible="false" title="My Layer"> |
374 |
title="My Layer" stroke_width="1" fill="None"/> |
<classification> |
375 |
|
<clnull label=""> |
376 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
377 |
|
</clnull> |
378 |
|
</classification> |
379 |
|
</layer> |
380 |
</map> |
</map> |
381 |
</session> |
</session> |
382 |
''' |
''' |
398 |
self.check_format() |
self.check_format() |
399 |
|
|
400 |
|
|
401 |
|
class TestSymbolSize(ClassificationTest): |
402 |
|
|
403 |
|
file_contents = '''\ |
404 |
|
<?xml version="1.0" encoding="UTF-8"?> |
405 |
|
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
406 |
|
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session"> |
407 |
|
<fileshapesource filetype="shapefile" id="D813968480" filename="../../Data/iceland/cultural_landmark-point.shp"/> |
408 |
|
<map title="Iceland map"> |
409 |
|
<layer title="cultural_landmark-point" shapestore="D813968480" visible="true"> |
410 |
|
<classification field="CLPTLABEL" field_type="string"> |
411 |
|
<clnull label=""> |
412 |
|
<cldata stroke="#000000" stroke_width="1" size="3" fill="#000000"/> |
413 |
|
</clnull> |
414 |
|
<clpoint label="" value="RUINS"> |
415 |
|
<cldata stroke="#000000" stroke_width="1" size="6" fill="#ffffff"/> |
416 |
|
</clpoint> |
417 |
|
<clpoint label="" value="FARM"> |
418 |
|
<cldata stroke="#000000" stroke_width="1" size="9" fill="#ffff00"/> |
419 |
|
</clpoint> |
420 |
|
</classification> |
421 |
|
</layer> |
422 |
|
</map> |
423 |
|
</session> |
424 |
|
''' |
425 |
|
|
426 |
|
def test(self): |
427 |
|
"""Test that the size attribute for point symbols is correctly |
428 |
|
loaded for a layer.""" |
429 |
|
eq = self.assertEquals |
430 |
|
session = load_session(self.filename()) |
431 |
|
self.session = session |
432 |
|
|
433 |
|
map = session.Maps()[0] # only one map in the sample |
434 |
|
|
435 |
|
expected = [("cultural_landmark-point", 2, |
436 |
|
[("default", (), "", |
437 |
|
("#000000", 1, "#000000", 3)), |
438 |
|
("single", "RUINS", "", |
439 |
|
("#000000", 1, "#ffffff", 6)), |
440 |
|
("single", "FARM", "", |
441 |
|
("#000000", 1, "#ffff00", 9))])] |
442 |
|
|
443 |
|
self.TestLayers(map.Layers(), expected) |
444 |
|
|
445 |
|
self.check_format() |
446 |
|
|
447 |
|
|
448 |
class TestClassification(ClassificationTest): |
class TestClassification(ClassificationTest): |
449 |
|
|
450 |
file_contents = '''\ |
file_contents = '''\ |
451 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
452 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
453 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
454 |
title="single map&layer"> |
title="single map&layer"> |
455 |
<fileshapesource filetype="shapefile" id="D138389860" |
<fileshapesource filetype="shapefile" id="D138389860" |
456 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
462 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
463 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
464 |
</projection> |
</projection> |
465 |
<layer shapestore="D138389860" visible="true" stroke="#000000" |
<layer shapestore="D138389860" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
466 |
<classification field="POPYREG" field_type="string"> |
<classification field="POPYREG" field_type="string"> |
467 |
<clnull label=""> |
<clnull label=""> |
468 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
479 |
</clpoint> |
</clpoint> |
480 |
</classification> |
</classification> |
481 |
</layer> |
</layer> |
482 |
<layer shapestore="D138504492" visible="true" stroke="#000000" |
<layer shapestore="D138504492" visible="true" title="My Layer 2"> |
|
title="My Layer 2" stroke_width="2" fill="None"> |
|
483 |
<classification field="AREA" field_type="double"> |
<classification field="AREA" field_type="double"> |
484 |
<clnull label=""> |
<clnull label=""> |
485 |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
<cldata stroke="#000000" stroke_width="2" fill="None"/> |
516 |
("#000000", 2, "None")), |
("#000000", 2, "None")), |
517 |
("single", "1", "", |
("single", "1", "", |
518 |
("#000000", 10, "None")), |
("#000000", 10, "None")), |
519 |
("single", "\xe4\xf6\xfc", "\xdcml\xe4uts", |
("single", internal_from_unicode(u"\xe4\xf6\xfc"), |
520 |
|
internal_from_unicode(u"\xdcml\xe4uts"), |
521 |
("#000000", 1, "None"))]), |
("#000000", 1, "None"))]), |
522 |
("My Layer 2", 4, |
("My Layer 2", 4, |
523 |
[("default", (), "", |
[("default", (), "", |
540 |
|
|
541 |
file_contents = '''\ |
file_contents = '''\ |
542 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
543 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
544 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
545 |
title="single map&layer"> |
title="single map&layer"> |
546 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
547 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
551 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
552 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
553 |
</projection> |
</projection> |
554 |
<layer shapestore="D1" visible="true" stroke="#000000" |
<layer shapestore="D1" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
555 |
<classification field="POPYREG" field_type="string"> |
<classification field="POPYREG" field_type="string"> |
556 |
<clnull label="hallo"> |
<clnull label="hallo"> |
557 |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
587 |
|
|
588 |
file_contents = '''\ |
file_contents = '''\ |
589 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
590 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
591 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
592 |
title="single map&layer"> |
title="single map&layer"> |
593 |
<fileshapesource filetype="shapefile" id="D2" |
<fileshapesource filetype="shapefile" id="D2" |
594 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
600 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
601 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
602 |
</projection> |
</projection> |
603 |
<layer shapestore="D4" visible="true" stroke="#000000" |
<layer shapestore="D4" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
604 |
<projection name="hello"> |
<projection name="hello"> |
605 |
<parameter value="zone=13"/> |
<parameter value="zone=13"/> |
606 |
<parameter value="proj=tmerc"/> |
<parameter value="proj=tmerc"/> |
615 |
</clpoint> |
</clpoint> |
616 |
</classification> |
</classification> |
617 |
</layer> |
</layer> |
618 |
<layer shapestore="D2" visible="true" stroke="#000000" |
<layer shapestore="D2" visible="true" title="My Layer"> |
|
title="My Layer" stroke_width="1" fill="None"> |
|
619 |
<projection name="Unknown"> |
<projection name="Unknown"> |
620 |
<parameter value="proj=lcc"/> |
<parameter value="proj=lcc"/> |
621 |
<parameter value="lat_1=10"/> |
<parameter value="lat_1=10"/> |
622 |
<parameter value="lat_2=20"/> |
<parameter value="lat_2=20"/> |
623 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
624 |
</projection> |
</projection> |
625 |
|
<classification> |
626 |
|
<clnull label=""> |
627 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
628 |
|
</clnull> |
629 |
|
</classification> |
630 |
</layer> |
</layer> |
631 |
</map> |
</map> |
632 |
</session> |
</session> |
668 |
|
|
669 |
file_contents = '''\ |
file_contents = '''\ |
670 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
671 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
672 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
673 |
title="single map&layer"> |
title="single map&layer"> |
674 |
<map title="Test Map"> |
<map title="Test Map"> |
675 |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
676 |
title="My RasterLayer"/> |
title="My RasterLayer" opacity="0.4" masktype="alpha"/> |
677 |
</map> |
</map> |
678 |
</session> |
</session> |
679 |
''' |
''' |
690 |
layer = map.Layers()[0] # one layer in the sample |
layer = map.Layers()[0] # one layer in the sample |
691 |
|
|
692 |
eq(layer.Title(), "My RasterLayer") |
eq(layer.Title(), "My RasterLayer") |
693 |
|
eq(layer.Opacity(), 0.4) |
694 |
|
eq(layer.MaskType(), layer.MASK_ALPHA) |
695 |
|
|
696 |
self.failIf(layer.Visible()) |
self.failIf(layer.Visible()) |
697 |
self.failUnless(filenames_equal(layer.GetImageFilename(), |
self.failUnless(filenames_equal(layer.GetImageFilename(), |
698 |
os.path.join(self.temp_dir(), |
os.path.join(self.temp_dir(), |
705 |
class TestJoinedTable(LoadSessionTest): |
class TestJoinedTable(LoadSessionTest): |
706 |
|
|
707 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
708 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
709 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" title="A Joined Table session"> |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="A Joined Table session"> |
710 |
<fileshapesource filetype="shapefile" id="D137227612" |
<fileshapesource filetype="shapefile" id="D137227612" |
711 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
712 |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
718 |
<derivedshapesource table="D136169900" shapesource="D137227612" |
<derivedshapesource table="D136169900" shapesource="D137227612" |
719 |
id="D136170932"/> |
id="D136170932"/> |
720 |
<map title="Test Map"> |
<map title="Test Map"> |
721 |
<layer shapestore="D136170932" visible="true" stroke="#000000" |
<layer shapestore="D136170932" visible="true" title="My Layer"> |
722 |
title="My Layer" stroke_width="1" fill="None"/> |
<classification> |
723 |
|
<clnull label=""> |
724 |
|
<cldata stroke="#000000" stroke_width="1" fill="None"/> |
725 |
|
</clnull> |
726 |
|
</classification> |
727 |
|
</layer> |
728 |
</map> |
</map> |
729 |
</session> |
</session> |
730 |
''' |
''' |
761 |
# test whether they're supported correctly. |
# test whether they're supported correctly. |
762 |
|
|
763 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
764 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
765 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" title="Thuban sample session"> |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="Thuban sample session"> |
766 |
<fileshapesource filetype="shapefile" id="D145265052" |
<fileshapesource filetype="shapefile" id="D145265052" |
767 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
768 |
<fileshapesource filetype="shapefile" id="D145412868" |
<fileshapesource filetype="shapefile" id="D145412868" |
773 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
774 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
775 |
</projection> |
</projection> |
776 |
<layer shapestore="D145265052" visible="true" stroke="#000000" |
<layer shapestore="D145265052" visible="true" title="political"> |
|
title="political" stroke_width="1" fill="#c0c0c0"> |
|
777 |
<projection name="Geographic"> |
<projection name="Geographic"> |
778 |
<parameter value="proj=latlong"/> |
<parameter value="proj=latlong"/> |
779 |
<parameter value="to_meter=0.017453"/> |
<parameter value="to_meter=0.017453"/> |
780 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
781 |
</projection> |
</projection> |
782 |
|
<classification> |
783 |
|
<clnull label=""> |
784 |
|
<cldata stroke="#000000" stroke_width="1" fill="#c0c0c0"/> |
785 |
|
</clnull> |
786 |
|
</classification> |
787 |
</layer> |
</layer> |
788 |
<layer shapestore="D145412868" visible="true" stroke="#000000" |
<layer shapestore="D145412868" visible="true" title="landmarks"> |
|
title="landmarks" stroke_width="1" fill="#ffff00"> |
|
789 |
<projection name="Geographic"> |
<projection name="Geographic"> |
790 |
<parameter value="proj=latlong"/> |
<parameter value="proj=latlong"/> |
791 |
<parameter value="to_meter=0.017453"/> |
<parameter value="to_meter=0.017453"/> |
792 |
<parameter value="ellps=clrk66"/> |
<parameter value="ellps=clrk66"/> |
793 |
</projection> |
</projection> |
794 |
|
<classification> |
795 |
|
<clnull label=""> |
796 |
|
<cldata size="5" stroke="#000000" stroke_width="1" fill="#ffff00"/> |
797 |
|
</clnull> |
798 |
|
</classification> |
799 |
</layer> |
</layer> |
800 |
<labellayer> |
<labellayer> |
801 |
<label x="-21.5" y="64.25" text="RUINS" |
<label x="-21.5" y="64.25" text="RUINS" |
814 |
|
|
815 |
label_layer = self.session.Maps()[0].LabelLayer() |
label_layer = self.session.Maps()[0].LabelLayer() |
816 |
expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER), |
expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER), |
817 |
(-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP), |
(-15.125, 64.75, internal_from_unicode(u"H\xfctte"), |
818 |
|
ALIGN_RIGHT, ALIGN_TOP), |
819 |
] |
] |
820 |
for label, values in zip(label_layer.Labels(), expected_labels): |
for label, values in zip(label_layer.Labels(), expected_labels): |
821 |
self.assertEquals((label.x, label.y, label.text, label.halign, |
self.assertEquals((label.x, label.y, label.text, label.halign, |
827 |
class TestPostGISLayer(LoadSessionTest): |
class TestPostGISLayer(LoadSessionTest): |
828 |
|
|
829 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
830 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
831 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
832 |
title="unnamed session"> |
title="unnamed session"> |
833 |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
834 |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
835 |
<dbshapesource tablename="landmarks" id="D143149420" dbconn="D142684948"/> |
<dbshapesource id="D143149420" dbconn="D142684948" |
836 |
|
tablename="landmarks_point_id" id_column="point_id" |
837 |
|
geometry_column="the_geom" /> |
838 |
<map title="unnamed map"> |
<map title="unnamed map"> |
839 |
<layer shapestore="D143149420" visible="true" stroke="#000000" |
<layer shapestore="D143149420" visible="true" stroke="#000000" |
840 |
title="landmarks" stroke_width="1" fill="None"/> |
title="landmarks" stroke_width="1" fill="None"/> |
878 |
class TestPostGISLayerPassword(LoadSessionTest): |
class TestPostGISLayerPassword(LoadSessionTest): |
879 |
|
|
880 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
881 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
882 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
883 |
title="unnamed session"> |
title="unnamed session"> |
884 |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
885 |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
973 |
|
|
974 |
file_contents = '''\ |
file_contents = '''\ |
975 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
976 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
977 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0.0.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
978 |
title="single map&layer"> |
title="single map&layer"> |
979 |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
980 |
<map title="Test Map"> |
<map title="Test Map"> |
1001 |
# LoadError really was about the missing attribute |
# LoadError really was about the missing attribute |
1002 |
self.assertEquals(str(value), |
self.assertEquals(str(value), |
1003 |
"Element " |
"Element " |
1004 |
"(u'http://thuban.intevation.org/dtds/thuban-1.0.0.dtd'," |
"(u'http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd'," |
1005 |
" u'fileshapesource') requires an attribute 'filetype'") |
" u'fileshapesource') requires an attribute 'filetype'") |
1006 |
else: |
else: |
1007 |
self.fail("Missing filetype attribute doesn't raise LoadError") |
self.fail("Missing filetype attribute doesn't raise LoadError") |
1008 |
|
|
1009 |
|
class Shapefile_CallBack: |
1010 |
|
|
1011 |
|
def __init__(self, params): |
1012 |
|
"""Initialize the callback return values. |
1013 |
|
|
1014 |
|
params must be a dictionary of the potential CB modes (keys), |
1015 |
|
with lists of tuples of return values as values. |
1016 |
|
Depending on the test the callback can be called multiple, |
1017 |
|
each time a return value is poped from the list |
1018 |
|
""" |
1019 |
|
|
1020 |
|
self.params = params |
1021 |
|
|
1022 |
|
|
1023 |
|
def s_cb(self, filename, mode = None, second_try= 0): |
1024 |
|
if self.params.has_key(mode): |
1025 |
|
return self.params[mode].pop(0) |
1026 |
|
else: |
1027 |
|
raise LoadError |
1028 |
|
|
1029 |
|
class TestAltPath(LoadSessionTest): |
1030 |
|
|
1031 |
|
"""Test the various cases in the alternative path feature. |
1032 |
|
|
1033 |
|
The test checks the reasonable cases: |
1034 |
|
- First recognition of a path error, fixed with user interaction. |
1035 |
|
- First recognition of a path error, load cancelled. |
1036 |
|
- Path error fixed from list, confirmed by user. |
1037 |
|
- Path error fixed from list, changed by user. |
1038 |
|
- Path error fixed from list, cancelled by user. |
1039 |
|
- Path error wrongly fixed from list, manual fix forced. |
1040 |
|
""" |
1041 |
|
|
1042 |
|
file_contents = '''\ |
1043 |
|
<?xml version="1.0" encoding="UTF-8"?> |
1044 |
|
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
1045 |
|
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" title="AltPath Test session"> |
1046 |
|
<fileshapesource filetype="shapefile" id="D1108450956" filename="../../Data/iceland/political.shp"/> |
1047 |
|
<fileshapesource filetype="shapefile" id="D1108900076" filename="../Data/iceland/roads-line.shp"/> |
1048 |
|
<fileshapesource filetype="shapefile" id="D1108947244" filename="../../Data/iceland/cultural_landmark-point.shp"/> |
1049 |
|
<map title="not the iceland map"> |
1050 |
|
<layer title="political" stroke_width="1" shapestore="D1108450956" visible="true" stroke="#000000" fill="#c0c0c0"/> |
1051 |
|
<layer title="roads-line" stroke_width="1" shapestore="D1108900076" visible="true" stroke="#000000" fill="None"/> |
1052 |
|
<layer title="something else" stroke_width="1" shapestore="D1108947244" visible="true" stroke="#000000" fill="None"/> |
1053 |
|
</map> |
1054 |
|
</session> |
1055 |
|
''' |
1056 |
|
|
1057 |
|
def checkSession(self, session): |
1058 |
|
"""Check if session has been loaded successfully.""" |
1059 |
|
|
1060 |
|
eq = self.assertEquals |
1061 |
|
|
1062 |
|
map = session.Maps()[0] |
1063 |
|
layers = map.Layers() |
1064 |
|
|
1065 |
|
eq("AltPath Test session", session.Title()) |
1066 |
|
eq("not the iceland map", map.Title()) |
1067 |
|
eq(3,len(layers)) |
1068 |
|
eq("political",layers[0].Title()) |
1069 |
|
eq("roads-line",layers[1].Title()) |
1070 |
|
eq("something else",layers[2].Title()) |
1071 |
|
|
1072 |
|
def test_01_single_path_error_fix(self): |
1073 |
|
"""Test single file path error fix.""" |
1074 |
|
# The usual initial case |
1075 |
|
s_cb = Shapefile_CallBack({ |
1076 |
|
"search": [("../Data/iceland/roads-line.shp",0)], |
1077 |
|
"check": [(None, None)]}) |
1078 |
|
self.session = load_session(self.filename(), |
1079 |
|
shapefile_callback =s_cb.s_cb) |
1080 |
|
self.checkSession(self.session) |
1081 |
|
|
1082 |
|
def test_02_path_error_fix_from_list(self): |
1083 |
|
"""Test single file path error fix.""" |
1084 |
|
# This represents the usual case for "from_list" |
1085 |
|
s_cb = Shapefile_CallBack({ |
1086 |
|
"search": [("../Data/iceland/roads-line.shp",1)], |
1087 |
|
"check": [(os.path.abspath("../Data/iceland/roads-line.shp"),1)] |
1088 |
|
}) |
1089 |
|
self.session = load_session(self.filename(), |
1090 |
|
shapefile_callback =s_cb.s_cb) |
1091 |
|
self.checkSession(self.session) |
1092 |
|
|
1093 |
|
def test_03_single_path_error_cancelled(self): |
1094 |
|
"""Test alternative path cancelled.""" |
1095 |
|
s_cb = Shapefile_CallBack({ |
1096 |
|
"search": [(None,0)], |
1097 |
|
"check": [(None, None)]}) |
1098 |
|
self.assertRaises(LoadCancelled, |
1099 |
|
load_session, self.filename(), None, s_cb.s_cb) |
1100 |
|
|
1101 |
|
def test_04_path_error_fix_from_list_cancelled(self): |
1102 |
|
"""Test alternative path from list cancelled.""" |
1103 |
|
s_cb = Shapefile_CallBack({ |
1104 |
|
"search": [("../Data/iceland/roads-line.shp",1)], |
1105 |
|
"check": [(None,1)] |
1106 |
|
}) |
1107 |
|
self.assertRaises(LoadCancelled, |
1108 |
|
load_session, self.filename(), None, s_cb.s_cb) |
1109 |
|
|
1110 |
|
def test_05_path_error_fix_from_list_changed(self): |
1111 |
|
"""Test alternative path from list changed.""" |
1112 |
|
s_cb = Shapefile_CallBack({ |
1113 |
|
"search": [("../Data/iceland/roads-line.shp",1)], |
1114 |
|
"check": [("../Data/iceland/roads-line.shp",0)] |
1115 |
|
}) |
1116 |
|
self.session = load_session(self.filename(), |
1117 |
|
shapefile_callback =s_cb.s_cb) |
1118 |
|
self.checkSession(self.session) |
1119 |
|
|
1120 |
|
def test_06_path_error_fix_from_list_fails(self): |
1121 |
|
"""Test alternative path recovery from list.""" |
1122 |
|
s_cb = Shapefile_CallBack({ |
1123 |
|
"search": [("../wrong/iceland/roads-line.shp",1), |
1124 |
|
("../Data/iceland/roads-line.shp",0)], |
1125 |
|
"check": [(None,None)] |
1126 |
|
}) |
1127 |
|
self.session = load_session(self.filename(), |
1128 |
|
shapefile_callback =s_cb.s_cb) |
1129 |
|
self.assertRaises(IndexError, |
1130 |
|
s_cb.s_cb, None, "search") |
1131 |
|
|
1132 |
|
|
1133 |
|
|
1134 |
if __name__ == "__main__": |
if __name__ == "__main__": |
1135 |
support.run_tests() |
support.run_tests() |