1 |
bh |
292 |
# Copyright (c) 2002 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Bernhard Herzog <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
""" |
9 |
|
|
Test loading a thuban session from a file |
10 |
|
|
""" |
11 |
|
|
|
12 |
|
|
__version__ = "$Revision$" |
13 |
|
|
# $Source$ |
14 |
|
|
# $Id$ |
15 |
|
|
|
16 |
|
|
import os |
17 |
|
|
import unittest |
18 |
|
|
|
19 |
|
|
import support |
20 |
|
|
support.initthuban() |
21 |
|
|
|
22 |
|
|
from Thuban.Model.load import load_session |
23 |
|
|
from Thuban.Model.session import Session |
24 |
|
|
from Thuban.Model.map import Map |
25 |
|
|
from Thuban.Model.layer import Layer |
26 |
|
|
from Thuban.Model.proj import Projection |
27 |
jonathan |
409 |
from Thuban.Model.color import Color |
28 |
bh |
292 |
|
29 |
|
|
def filenames_equal(name1, name2): |
30 |
|
|
"""Return true if the filenames name1 and name2 are equal. |
31 |
|
|
|
32 |
|
|
On systems where it is available, simply use os.path.samefile, |
33 |
|
|
otherwise return whether the normalized versions of the filenames |
34 |
|
|
according to os.path.normpath are equal. |
35 |
|
|
""" |
36 |
|
|
if hasattr(os.path, "samefile"): |
37 |
|
|
return os.path.samefile(name1, name2) |
38 |
|
|
return os.path.normpath(name1) == os.path.normpath(name2) |
39 |
|
|
|
40 |
|
|
|
41 |
|
|
contents_single_map = '''\ |
42 |
|
|
<?xml version="1.0" encoding="UTF-8"?> |
43 |
|
|
<!DOCTYPE session SYSTEM "thuban.dtd"> |
44 |
|
|
<session title="single map&layer"> |
45 |
|
|
<map title="Test Map"> |
46 |
|
|
<projection> |
47 |
|
|
<parameter value="zone=26"/> |
48 |
|
|
<parameter value="proj=utm"/> |
49 |
|
|
<parameter value="ellps=clrk66"/> |
50 |
|
|
</projection> |
51 |
|
|
<layer title="My Layer" stroke_width="1" fill="None" |
52 |
|
|
filename="../../Data/iceland/political.shp" |
53 |
|
|
stroke="#000000"/> |
54 |
|
|
</map> |
55 |
|
|
</session> |
56 |
|
|
''' |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
class LoadSessionTest(unittest.TestCase, support.FileTestMixin): |
60 |
|
|
|
61 |
|
|
def setUp(self): |
62 |
|
|
"""Create the test files""" |
63 |
|
|
file = open(self.temp_file_name("load_singlelayer.thuban"), "w") |
64 |
|
|
file.write(contents_single_map) |
65 |
|
|
file.close() |
66 |
|
|
self.session = None |
67 |
|
|
|
68 |
|
|
def tearDown(self): |
69 |
|
|
if self.session is not None: |
70 |
|
|
self.session.Destroy() |
71 |
|
|
|
72 |
|
|
def testSingleLayer(self): |
73 |
|
|
"""Load a session with a single map with a single layer""" |
74 |
|
|
eq = self.assertEquals |
75 |
|
|
session = load_session(self.temp_file_name("load_singlelayer.thuban")) |
76 |
|
|
self.session = session |
77 |
|
|
|
78 |
|
|
# Check the title |
79 |
|
|
eq(session.Title(), "single map&layer") |
80 |
|
|
|
81 |
|
|
# the session has one map. |
82 |
|
|
maps = session.Maps() |
83 |
|
|
eq(len(maps), 1) |
84 |
|
|
|
85 |
|
|
# Check the map's attributes |
86 |
|
|
map = maps[0] |
87 |
|
|
eq(map.Title(), "Test Map") |
88 |
|
|
|
89 |
|
|
# the map has a single layer |
90 |
|
|
layers = map.Layers() |
91 |
|
|
eq(len(layers), 1) |
92 |
|
|
|
93 |
|
|
# Check the layer attributes |
94 |
|
|
layer = layers[0] |
95 |
|
|
eq(layer.Title(), "My Layer") |
96 |
|
|
self.failUnless(filenames_equal(layer.filename, |
97 |
|
|
os.path.join(self.temp_dir(), |
98 |
|
|
os.pardir, os.pardir, |
99 |
|
|
"Data", "iceland", |
100 |
|
|
"political.shp"))) |
101 |
jonathan |
610 |
eq(layer.GetClassification().GetDefaultFill(), Color.Transparent) |
102 |
jonathan |
482 |
eq(layer.GetClassification().GetDefaultLineColor().hex(), "#000000") |
103 |
bh |
292 |
|
104 |
|
|
|
105 |
|
|
if __name__ == "__main__": |
106 |
|
|
unittest.main() |