/[thuban]/branches/WIP-pyshapelib-bramz/test/test_load.py
ViewVC logotype

Contents of /branches/WIP-pyshapelib-bramz/test/test_load.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 292 - (show annotations)
Fri Aug 30 09:44:12 2002 UTC (22 years, 6 months ago) by bh
Original Path: trunk/thuban/test/test_load.py
File MIME type: text/x-python
File size: 3023 byte(s)
Initial set of tests and
brief instructions on how to run them

1 # 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
28 def filenames_equal(name1, name2):
29 """Return true if the filenames name1 and name2 are equal.
30
31 On systems where it is available, simply use os.path.samefile,
32 otherwise return whether the normalized versions of the filenames
33 according to os.path.normpath are equal.
34 """
35 if hasattr(os.path, "samefile"):
36 return os.path.samefile(name1, name2)
37 return os.path.normpath(name1) == os.path.normpath(name2)
38
39
40 contents_single_map = '''\
41 <?xml version="1.0" encoding="UTF-8"?>
42 <!DOCTYPE session SYSTEM "thuban.dtd">
43 <session title="single map&amp;layer">
44 <map title="Test Map">
45 <projection>
46 <parameter value="zone=26"/>
47 <parameter value="proj=utm"/>
48 <parameter value="ellps=clrk66"/>
49 </projection>
50 <layer title="My Layer" stroke_width="1" fill="None"
51 filename="../../Data/iceland/political.shp"
52 stroke="#000000"/>
53 </map>
54 </session>
55 '''
56
57
58 class LoadSessionTest(unittest.TestCase, support.FileTestMixin):
59
60 def setUp(self):
61 """Create the test files"""
62 file = open(self.temp_file_name("load_singlelayer.thuban"), "w")
63 file.write(contents_single_map)
64 file.close()
65 self.session = None
66
67 def tearDown(self):
68 if self.session is not None:
69 self.session.Destroy()
70
71 def testSingleLayer(self):
72 """Load a session with a single map with a single layer"""
73 eq = self.assertEquals
74 session = load_session(self.temp_file_name("load_singlelayer.thuban"))
75 self.session = session
76
77 # Check the title
78 eq(session.Title(), "single map&layer")
79
80 # the session has one map.
81 maps = session.Maps()
82 eq(len(maps), 1)
83
84 # Check the map's attributes
85 map = maps[0]
86 eq(map.Title(), "Test Map")
87
88 # the map has a single layer
89 layers = map.Layers()
90 eq(len(layers), 1)
91
92 # Check the layer attributes
93 layer = layers[0]
94 eq(layer.Title(), "My Layer")
95 self.failUnless(filenames_equal(layer.filename,
96 os.path.join(self.temp_dir(),
97 os.pardir, os.pardir,
98 "Data", "iceland",
99 "political.shp")))
100 eq(layer.fill, None)
101 eq(layer.stroke.hex(), "#000000")
102
103
104 if __name__ == "__main__":
105 unittest.main()

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26