82 |
self.session = None |
self.session = None |
83 |
|
|
84 |
|
|
85 |
dtd = "http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
dtd = "http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
86 |
thubanids = [((dtd, n), (None, "id")) for n in |
thubanids = [((dtd, n), (None, "id")) for n in |
87 |
["fileshapesource", "filetable", "jointable", |
["fileshapesource", "filetable", "jointable", |
88 |
"derivedshapesource"]] |
"derivedshapesource"]] |
173 |
|
|
174 |
class TestSingleLayer(LoadSessionTest): |
class TestSingleLayer(LoadSessionTest): |
175 |
|
|
176 |
|
# Note: The use of & and non-ascii characters is deliberate. We |
177 |
|
# want to test whether the loading code handles that correctly. |
178 |
file_contents = '''\ |
file_contents = '''\ |
179 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
180 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
181 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
182 |
title="single map&layer"> |
title="Stra\xc3\x9fen & Landmarken"> |
183 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
184 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
185 |
<map title="Test Map"> |
<map title="\xc3\x9cbersicht"> |
186 |
<projection name="Unknown"> |
<projection epsg="32627" name="WGS 84 / UTM zone 27N"> |
187 |
<parameter value="zone=26"/> |
<parameter value="datum=WGS84"/> |
188 |
|
<parameter value="ellps=WGS84"/> |
189 |
<parameter value="proj=utm"/> |
<parameter value="proj=utm"/> |
190 |
<parameter value="ellps=clrk66"/> |
<parameter value="units=m"/> |
191 |
|
<parameter value="zone=27"/> |
192 |
</projection> |
</projection> |
193 |
<layer shapestore="D1" visible="true" |
<layer shapestore="D1" visible="true" |
194 |
stroke="#000000" title="My Layer" stroke_width="1" |
stroke="#000000" title="K\xc3\xbcste" stroke_width="1" |
195 |
fill="None"/> |
fill="None"/> |
196 |
</map> |
</map> |
197 |
</session> |
</session> |
204 |
self.session = session |
self.session = session |
205 |
|
|
206 |
# Check the title |
# Check the title |
207 |
eq(session.Title(), "single map&layer") |
eq(session.Title(), "Stra\xdfen & Landmarken") |
208 |
|
|
209 |
# the session has one map. |
# the session has one map. |
210 |
maps = session.Maps() |
maps = session.Maps() |
212 |
|
|
213 |
# Check the map's attributes |
# Check the map's attributes |
214 |
map = maps[0] |
map = maps[0] |
215 |
eq(map.Title(), "Test Map") |
eq(map.Title(), "\xdcbersicht") |
216 |
|
proj = map.GetProjection() |
217 |
|
eq(proj.GetName(), "WGS 84 / UTM zone 27N") |
218 |
|
eq(proj.EPSGCode(), "32627") |
219 |
|
params = proj.GetAllParameters() |
220 |
|
params.sort() |
221 |
|
eq(params, ["datum=WGS84", "ellps=WGS84", "proj=utm", "units=m", |
222 |
|
"zone=27"]) |
223 |
|
|
224 |
# the map has a single layer |
# the map has a single layer |
225 |
layers = map.Layers() |
layers = map.Layers() |
227 |
|
|
228 |
# Check the layer attributes |
# Check the layer attributes |
229 |
layer = layers[0] |
layer = layers[0] |
230 |
eq(layer.Title(), "My Layer") |
eq(layer.Title(), "K\xfcste") |
231 |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
self.failUnless(filenames_equal(layer.ShapeStore().FileName(), |
232 |
os.path.join(self.temp_dir(), |
os.path.join(self.temp_dir(), |
233 |
os.pardir, os.pardir, |
os.pardir, os.pardir, |
242 |
self.session.Destroy() |
self.session.Destroy() |
243 |
self.session = None |
self.session = None |
244 |
|
|
245 |
|
def test_leak(self): |
246 |
|
"""Test load_session for resource leaks |
247 |
|
|
248 |
|
The load_session function had a resource leak in that it created |
249 |
|
cyclic references. The objects would have been eventually |
250 |
|
collected by the garbage collector but too late. One symptom is |
251 |
|
that when layers are removed so that the last normal reference |
252 |
|
owned indirectly by the session to a shape store goes away, the |
253 |
|
shape store is not actually removed from the session even though |
254 |
|
the session only keeps weak references because there are still |
255 |
|
references owned by the cyclic garbage. |
256 |
|
""" |
257 |
|
session = load_session(self.filename()) |
258 |
|
self.session = session |
259 |
|
|
260 |
|
# sanity check |
261 |
|
self.assertEquals(len(session.ShapeStores()), 1) |
262 |
|
|
263 |
|
# remove the map. The shapestore should go away too |
264 |
|
session.RemoveMap(session.Maps()[0]) |
265 |
|
self.assertEquals(len(session.ShapeStores()), 0) |
266 |
|
|
267 |
|
|
268 |
class TestLayerVisibility(LoadSessionTest): |
class TestLayerVisibility(LoadSessionTest): |
269 |
|
|
270 |
file_contents = '''\ |
file_contents = '''\ |
271 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
272 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
273 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
274 |
title="single map&layer"> |
title="single map&layer"> |
275 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
276 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
394 |
|
|
395 |
file_contents = '''\ |
file_contents = '''\ |
396 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
397 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
398 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
399 |
title="single map&layer"> |
title="single map&layer"> |
400 |
<fileshapesource filetype="shapefile" id="D1" |
<fileshapesource filetype="shapefile" id="D1" |
401 |
filename="../../Data/iceland/political.shp"/> |
filename="../../Data/iceland/political.shp"/> |
442 |
|
|
443 |
file_contents = '''\ |
file_contents = '''\ |
444 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
445 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
446 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
447 |
title="single map&layer"> |
title="single map&layer"> |
448 |
<fileshapesource filetype="shapefile" id="D2" |
<fileshapesource filetype="shapefile" id="D2" |
449 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
520 |
|
|
521 |
file_contents = '''\ |
file_contents = '''\ |
522 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
523 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
524 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
525 |
title="single map&layer"> |
title="single map&layer"> |
526 |
<map title="Test Map"> |
<map title="Test Map"> |
527 |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
<rasterlayer visible="false" filename="../../Data/iceland/island.tif" |
554 |
class TestJoinedTable(LoadSessionTest): |
class TestJoinedTable(LoadSessionTest): |
555 |
|
|
556 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
557 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
558 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" title="A Joined Table session"> |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" title="A Joined Table session"> |
559 |
<fileshapesource filetype="shapefile" id="D137227612" |
<fileshapesource filetype="shapefile" id="D137227612" |
560 |
filename="../../Data/iceland/roads-line.shp"/> |
filename="../../Data/iceland/roads-line.shp"/> |
561 |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
<filetable filetype="DBF" filename="load_joinedtable.dbf" id="D136171140" |
603 |
class TestPostGISLayer(LoadSessionTest): |
class TestPostGISLayer(LoadSessionTest): |
604 |
|
|
605 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
606 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
607 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
608 |
title="unnamed session"> |
title="unnamed session"> |
609 |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
610 |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
652 |
class TestPostGISLayerPassword(LoadSessionTest): |
class TestPostGISLayerPassword(LoadSessionTest): |
653 |
|
|
654 |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
file_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
655 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
656 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
657 |
title="unnamed session"> |
title="unnamed session"> |
658 |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
<dbconnection port="%(port)s" host="%(host)s" user="%(user)s" |
659 |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
dbtype="postgis" id="D142684948" dbname="%(dbname)s"/> |
747 |
|
|
748 |
file_contents = '''\ |
file_contents = '''\ |
749 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
750 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
751 |
<session xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd" |
<session xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
752 |
title="single map&layer"> |
title="single map&layer"> |
753 |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
<fileshapesource id="D1" filename="../../Data/iceland/political.shp"/> |
754 |
<map title="Test Map"> |
<map title="Test Map"> |
775 |
# LoadError really was about the missing attribute |
# LoadError really was about the missing attribute |
776 |
self.assertEquals(str(value), |
self.assertEquals(str(value), |
777 |
"Element " |
"Element " |
778 |
"(u'http://thuban.intevation.org/dtds/thuban-0.9.dtd'," |
"(u'http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd'," |
779 |
" u'fileshapesource') requires an attribute 'filetype'") |
" u'fileshapesource') requires an attribute 'filetype'") |
780 |
else: |
else: |
781 |
self.fail("Missing filetype attribute doesn't raise LoadError") |
self.fail("Missing filetype attribute doesn't raise LoadError") |