50 |
from Thuban.Model.table import DBFTable, MemoryTable, \ |
from Thuban.Model.table import DBFTable, MemoryTable, \ |
51 |
FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \ |
FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING, \ |
52 |
table_to_dbf |
table_to_dbf |
53 |
|
from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \ |
54 |
|
ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE |
55 |
|
|
56 |
|
|
57 |
def filenames_equal(name1, name2): |
def filenames_equal(name1, name2): |
89 |
self.session = None |
self.session = None |
90 |
|
|
91 |
|
|
92 |
dtd = "http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
dtd = "http://thuban.intevation.org/dtds/thuban-1.0rc1.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"]] |
99 |
("jointable", "right"), |
("jointable", "right"), |
100 |
("derivedshapesource", "table"), |
("derivedshapesource", "table"), |
101 |
("derivedshapesource", "shapesource")]] |
("derivedshapesource", "shapesource")]] |
102 |
filenames = [((dtd, n), (None, m)) for n, m in |
|
103 |
[("fileshapesource", "filename"), |
# The filenames in the tests should be understandable on all |
104 |
("rasterlayer", "filename"), |
# currently supported platforms so filenames is an empty list |
105 |
("filetable", "filename")]] |
filenames = [] |
106 |
|
|
107 |
del n, m, dtd |
del n, m, dtd |
108 |
|
|
109 |
def check_format(self): |
def check_format(self): |
186 |
file_contents = '''\ |
file_contents = '''\ |
187 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
188 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
189 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
190 |
title="Stra\xc3\x9fen & Landmarken"> |
title="Stra\xc3\x9fen & Landmarken"> |
191 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
192 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
278 |
file_contents = '''\ |
file_contents = '''\ |
279 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
280 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
281 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
282 |
title="Non ASCII column name test"> |
title="Non ASCII column name test"> |
283 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
284 |
filename="TestNonAsciiColumnName.shp"/> |
filename="TestNonAsciiColumnName.shp"/> |
355 |
file_contents = '''\ |
file_contents = '''\ |
356 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
357 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
358 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
359 |
title="single map&layer"> |
title="single map&layer"> |
360 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
361 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
393 |
file_contents = '''\ |
file_contents = '''\ |
394 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
395 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
396 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
397 |
title="single map&layer"> |
title="single map&layer"> |
398 |
<fileshapesource filetype="shapefile" id="D138389860" |
<fileshapesource filetype="shapefile" id="D138389860" |
399 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
485 |
file_contents = '''\ |
file_contents = '''\ |
486 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
487 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
488 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
489 |
title="single map&layer"> |
title="single map&layer"> |
490 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
491 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
533 |
file_contents = '''\ |
file_contents = '''\ |
534 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
535 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
536 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
537 |
title="single map&layer"> |
title="single map&layer"> |
538 |
<fileshapesource filetype="shapefile" id="D2" |
<fileshapesource filetype="shapefile" id="D2" |
539 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
611 |
file_contents = '''\ |
file_contents = '''\ |
612 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
613 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
614 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
615 |
title="single map&layer"> |
title="single map&layer"> |
616 |
<map title="Test Map"> |
<map title="Test Map"> |
617 |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
645 |
|
|
646 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
647 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
648 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" title="A Joined Table session"> |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" title="A Joined Table session"> |
649 |
<fileshapesource filetype="shapefile" id="D137227612" |
<fileshapesource filetype="shapefile" id="D137227612" |
650 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
651 |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
689 |
self.check_format() |
self.check_format() |
690 |
|
|
691 |
|
|
692 |
|
class TestLabelLayer(LoadSessionTest): |
693 |
|
|
694 |
|
# Note that the labels deliberately contain non-ascii characters to |
695 |
|
# test whether they're supported correctly. |
696 |
|
|
697 |
|
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
698 |
|
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
699 |
|
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" title="Thuban sample session"> |
700 |
|
<fileshapesource filetype="shapefile" id="D145265052" |
701 |
|
filename="../../Data/iceland/political.shp"/> |
702 |
|
<fileshapesource filetype="shapefile" id="D145412868" |
703 |
|
filename="../../Data/iceland/cultural_landmark-point.shp"/> |
704 |
|
<map title="Iceland map"> |
705 |
|
<projection name="Unknown"> |
706 |
|
<parameter value="zone=26"/> |
707 |
|
<parameter value="proj=utm"/> |
708 |
|
<parameter value="ellps=clrk66"/> |
709 |
|
</projection> |
710 |
|
<layer shapestore="D145265052" visible="true" stroke="#000000" |
711 |
|
title="political" stroke_width="1" fill="#c0c0c0"> |
712 |
|
<projection name="Geographic"> |
713 |
|
<parameter value="proj=latlong"/> |
714 |
|
<parameter value="to_meter=0.017453"/> |
715 |
|
<parameter value="ellps=clrk66"/> |
716 |
|
</projection> |
717 |
|
</layer> |
718 |
|
<layer shapestore="D145412868" visible="true" stroke="#000000" |
719 |
|
title="landmarks" stroke_width="1" fill="#ffff00"> |
720 |
|
<projection name="Geographic"> |
721 |
|
<parameter value="proj=latlong"/> |
722 |
|
<parameter value="to_meter=0.017453"/> |
723 |
|
<parameter value="ellps=clrk66"/> |
724 |
|
</projection> |
725 |
|
</layer> |
726 |
|
<labellayer> |
727 |
|
<label x="-21.5" y="64.25" text="RUINS" |
728 |
|
halign="left" valign="center"/> |
729 |
|
<label x="-15.125" y="64.75" text="H\xc3\xbctte" |
730 |
|
halign="right" valign="top"/> |
731 |
|
</labellayer> |
732 |
|
</map> |
733 |
|
</session> |
734 |
|
''' |
735 |
|
|
736 |
|
def test(self): |
737 |
|
"""Test loading a session with a label layer""" |
738 |
|
session = load_session(self.filename()) |
739 |
|
self.session = session |
740 |
|
|
741 |
|
label_layer = self.session.Maps()[0].LabelLayer() |
742 |
|
expected_labels = [(-21.5, 64.25, "RUINS", ALIGN_LEFT, ALIGN_CENTER), |
743 |
|
(-15.125, 64.75, "H\xfctte", ALIGN_RIGHT, ALIGN_TOP), |
744 |
|
] |
745 |
|
for label, values in zip(label_layer.Labels(), expected_labels): |
746 |
|
self.assertEquals((label.x, label.y, label.text, label.halign, |
747 |
|
label.valign), |
748 |
|
values) |
749 |
|
self.check_format() |
750 |
|
|
751 |
|
|
752 |
class TestPostGISLayer(LoadSessionTest): |
class TestPostGISLayer(LoadSessionTest): |
753 |
|
|
754 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
755 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
756 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
757 |
title="unnamed session"> |
title="unnamed session"> |
758 |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
759 |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
802 |
|
|
803 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
804 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
805 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
806 |
title="unnamed session"> |
title="unnamed session"> |
807 |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
808 |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
897 |
file_contents = '''\ |
file_contents = '''\ |
898 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
899 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
900 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd" |
901 |
title="single map&layer"> |
title="single map&layer"> |
902 |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
903 |
<map title="Test Map"> |
<map title="Test Map"> |
924 |
# LoadError really was about the missing attribute |
# LoadError really was about the missing attribute |
925 |
self.assertEquals(str(value), |
self.assertEquals(str(value), |
926 |
"Element " |
"Element " |
927 |
"(u'http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd'," |
"(u'http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd'," |
928 |
" u'fileshapesource') requires an attribute 'filetype'") |
" u'fileshapesource') requires an attribute 'filetype'") |
929 |
else: |
else: |
930 |
self.fail("Missing filetype attribute doesn't raise LoadError") |
self.fail("Missing filetype attribute doesn't raise LoadError") |