/[thuban]/branches/WIP-pyshapelib-bramz/Extensions/wms/test/test_parser.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Extensions/wms/test/test_parser.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2381 - (hide annotations)
Mon Oct 4 16:44:05 2004 UTC (20 years, 5 months ago) by joey
Original Path: trunk/thuban/Extensions/wms/test/test_parser.py
File MIME type: text/x-python
File size: 10454 byte(s)
Added missing self-test

1 joey 2114 # -*- encoding: iso-8859-1 -*-
2     #
3     # Copyright (c) 2004 by Intevation GmbH
4     # Authors:
5     # Martin Schulze <[email protected]>
6     #
7     # This program is free software; you can redistribute it and/or modify
8     # it under the terms of the GNU General Public License as published by
9     # the Free Software Foundation; either version 2 of the License, or
10     # (at your option) any later version.
11     #
12     # This program is distributed in the hope that it will be useful,
13     # but WITHOUT ANY WARRANTY; without even the implied warranty of
14     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     # GNU General Public License for more details.
16     #
17     # You should have received a copy of the GNU General Public License
18     # along with this program; if not, write to the Free Software
19     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20    
21     """
22     Test for WMSCapabilitiesParser from ../parser.py
23    
24     """
25    
26     __version__ = "$Revision$"
27     # $Source$
28     # $Id$
29    
30     import os
31     import unittest
32    
33 joey 2121 import adjustpath
34 joey 2114
35     from Extensions.wms.parser import WMSCapabilitiesParser
36    
37    
38 joey 2130 class TestWMSCapabilitiesParser(unittest.TestCase, WMSCapabilitiesParser):
39 joey 2114 """
40     Defines a test environment for the class WMSCapabilities.
41     """
42    
43 joey 2130 def compareLists(self, foo, bar):
44 joey 2114 """
45     Compare two lists
46     - check same number of elements
47     - check whether all elements in the first list are part of the second
48     """
49    
50     # Check for same number of elements
51     if len(foo) != len(bar):
52 joey 2130 self.fail("Different number of elements");
53 joey 2114
54     # Loop through all elements for existance
55     for elm in foo:
56     if elm not in bar:
57 joey 2130 self.fail("%s not in second list" % elm);
58 joey 2114
59    
60 joey 2130 def compareDicts(self, foo, bar):
61 joey 2114 """
62     Compare two dictionaries (hashes)
63     - check same number of keys
64     - check whether all keys from the first list are part of the second
65     """
66    
67     # Check for same number of elements
68     if len(foo) != len(bar):
69 joey 2130 self.fail("Different number of keys");
70 joey 2114
71     # Loop through all elements for existance
72     for key in foo.keys():
73     if key not in bar:
74 joey 2130 self.fail("%s not in second dictionary" % key);
75 joey 2114 if foo[key] != bar[key]:
76 joey 2130 self.fail("%s has different value in second dictionary" % key);
77 joey 2114
78    
79 joey 2127 def setUp(self):
80 joey 2114 """
81     Load the locally stored frida capabilities.
82     http://frida.intevation.org/cgi-bin/frida_wms?
83     """
84    
85     try:
86     try:
87 joey 2130 f = open("sample.xml", "r")
88 joey 2114 except:
89 joey 2130 f = open(os.path.dirname(__file__) + "/sample.xml", "r")
90 joey 2114 except:
91     print "Cannot open sample.xml for reading"
92     else:
93 joey 2130 xml = f.read();
94 joey 2114 f.close()
95 joey 2130 self.grok(xml)
96 joey 2114
97    
98 joey 2381 def test_compareLists(self):
99     """
100     Test the internal compareLists method.
101     """
102    
103     # Equality of empty lists
104     self.compareLists([], [])
105    
106     # Equality of equal lists
107     self.compareLists([1,2], [1,2])
108    
109     # Equality of permuted lists
110     self.compareLists([1,2], [2,1])
111    
112     # Equality of large permuted lists
113     self.compareLists([1,2,3,4,5,6,7,8], [8,3,1,2,5,7,4,6])
114    
115     # TODO: Check if non-equality raises an exception:
116     #
117     # [a,b] != [c,b,a]
118     # [a,b] != [c,b]
119     # [] = []
120     # [] != [a]
121    
122    
123     def test_compareDicts(self):
124     """
125     Test the internal compareDicts method.
126     """
127    
128     # Equality of empty dictionaries
129     self.compareDicts({}, {})
130    
131     # Equality of equal dictionaries
132     # Python may represent the dictionaries differently
133     self.compareDicts({10:20, 11:30}, {10:20, 11:30})
134    
135     # Equality of permuted dictionaries
136     # Python may represent the dictionaries similar anyway
137     self.compareDicts({10:20, 11:30}, {11:30, 10:20})
138    
139     # TODO: Check if non-equality raises an exception:
140     #
141     # {a:b, b:c} != {a:b}
142    
143    
144 joey 2130 def test_general(self):
145 joey 2114 """
146     Test general attributes extracted from Capabilities XML
147     """
148    
149 joey 2134 self.assertEquals(self.getTitle().encode('latin-1'),
150     'Frida - Freie Vektor-Geodaten Osnabrück')
151     self.assertEquals(self.getAbstract(), '')
152     self.assertEquals(self.getFees(), '')
153     self.assertEquals(self.getAccessConstraints(), '')
154 joey 2114 formats = ['image/gif', 'image/png', 'image/jpeg', 'image/wbmp']
155 joey 2134 self.compareLists(self.getFormats(), formats)
156 joey 2114 layers = ['Osnabrueck', 'gruenflaechen', 'gewaesser',
157     'gewaesserpolyl','gewaesserlinien', 'strassen_all',
158     'strassenhinten', 'strassen', 'beschriftung',
159     'hauptbeschriftung', 'sehenswuerdigkeiten']
160 joey 2134 self.compareLists(self.getLayers(), layers)
161     self.compareLists(self.getSRS(), ['31493'])
162 joey 2114
163    
164 joey 2130 def test_LayerTitle(self):
165 joey 2114 """
166     Check if layer titles are recognised properly
167     """
168    
169     # main layer
170 joey 2134 self.assertEquals(self.getLayerTitle('Osnabrueck').encode('latin-1'),
171     'Frida - Freie Vektor-Geodaten Osnabrück')
172 joey 2114
173     # first nested layer
174 joey 2135 self.assertEquals(self.getLayerTitle(
175     'gruenflaechen').encode('latin-1'),
176 joey 2134 'Grünflächen')
177 joey 2114
178     # first nested layer
179 joey 2134 self.assertEquals(self.getLayerTitle('gewaesser').encode('latin-1'),
180     'Gewässer')
181 joey 2114
182     # second nested layer
183 joey 2135 self.assertEquals(self.getLayerTitle(
184     'gewaesserpolyl').encode('latin-1'),
185 joey 2134 'Gewässerflächen')
186 joey 2114
187    
188 joey 2130 def test_LayerSRS(self):
189 joey 2114 """
190     Check if the SRS are returned properly
191     """
192    
193     # SRS of main layer
194 joey 2134 self.compareLists(self.getLayerSRS('Osnabrueck'), ['31493'])
195 joey 2114
196     # Single SRS of layer without inheritance
197 joey 2134 self.compareLists(self.getLayerSRS('gruenflaechen'), ['31493'])
198 joey 2114
199 joey 2126 # Multiple SRS of layer without inheritance, but overwriting
200 joey 2135 self.compareLists(self.getLayerSRS('gewaesserpolyl'),
201     ['31493', '31494'])
202 joey 2114
203 joey 2126 # Multiple SRS of layer with inheritance, one new locally
204 joey 2135 self.compareLists(self.getLayerSRS('gewaesserlinien'),
205     ['31493', '31492'])
206 joey 2114
207 joey 2126 # Multiple SRS with inheritance, two new locally
208 joey 2135 self.compareLists(self.getLayerSRS('strassen'),
209     ['31493', '31494', '31495'])
210 joey 2114
211 joey 2126 # Single SRS with inheritance but overwriting
212 joey 2141 self.compareLists(self.getLayerSRS('beschriftung'),
213     ['31493', '31494', '31495'])
214 joey 2114
215 joey 2168 # SRS of a layer with AUTO SRS ignored
216     self.compareLists(self.getLayerSRS('sehenswuerdigkeiten'), ['31493'])
217 joey 2114
218 joey 2168
219 joey 2130 def test_LatLonBoundingBoxes(self):
220 joey 2114 """
221     Check if the LatLonBoundingBoxes are returned properly
222     """
223    
224     # main LatLonBoundingBox
225     bbox = {'minx': "7.92881", 'miny': "52.2131",
226     'maxx': "8.18349", 'maxy': "52.341"}
227 joey 2134 self.compareDicts(self.getLayerLatLonBBox('Osnabrueck'), bbox)
228 joey 2114
229     # inherited LatLonBoundingBox
230     bbox = {'minx': "7.92881", 'miny': "52.2131",
231     'maxx': "8.18349", 'maxy': "52.341"}
232 joey 2134 self.compareDicts(self.getLayerLatLonBBox('gewaesser'), bbox)
233 joey 2114
234     # third layer non-inherited LatLonBoundingBox
235     bbox = {'minx': "7.93531", 'miny': "52.2328",
236     'maxx': "8.17739", 'maxy': "52.3353"}
237 joey 2134 self.compareDicts(self.getLayerLatLonBBox('gewaesserpolyl'), bbox)
238 joey 2114
239    
240 joey 2130 def test_BoundingBoxes(self):
241 joey 2114 """
242     Check if the BoundingBoxes are returned properly
243     """
244    
245     # main BoundingBox
246     bbox = {'minx': "3.427e+06", 'miny': "5.787e+06",
247     'maxx': "3.4442e+06", 'maxy': "5.801e+06"}
248 joey 2134 self.compareDicts(self.getLayerBBox('Osnabrueck', '31493'), bbox)
249 joey 2114
250     # inherited BoundingBox
251 joey 2134 self.compareDicts(self.getLayerBBox('gewaesser', '31493'), bbox)
252 joey 2114
253     # overwritten BoundingBox
254     bbox = {'minx': "3.427e+06", 'miny': "5.78901e+06",
255     'maxx': "3.44173e+06", 'maxy': "5.79952e+06"}
256 joey 2134 self.compareDicts(self.getLayerBBox('gewaesserlinien', '31492'), bbox)
257 joey 2114
258     # multiple BoundingBoxes
259     bbox = {'minx': "3.42743e+06", 'miny': "5.78919e+06",
260     'maxx': "3.44381e+06", 'maxy': "5.80038e+06"}
261 joey 2134 self.compareDicts(self.getLayerBBox('gewaesserpolyl', '31493'), bbox)
262 joey 2114 bbox = {'minx': "3.42742e+06", 'miny': "5.78918e+06",
263     'maxx': "3.44380e+06", 'maxy': "5.80037e+06"}
264 joey 2134 self.compareDicts(self.getLayerBBox('gewaesserpolyl', '31494'), bbox)
265 joey 2114
266 joey 2142 # Non-existing BoundingBox
267     self.assertEquals(self.getLayerBBox('beschriftung', '31490'), None)
268 joey 2119
269 joey 2142
270 joey 2169 def test_LatLonBoundingBoxes_as_bboxes(self):
271     """
272     Check if the LatLonBoundingBoxes are returned properly
273     """
274    
275     # main LatLonBoundingBox
276     bbox = {'minx': "7.92881", 'miny': "52.2131",
277     'maxx': "8.18349", 'maxy': "52.341"}
278     self.compareDicts(self.getLayerBBox('Osnabrueck', '4326'), bbox)
279    
280     # inherited LatLonBoundingBox
281     bbox = {'minx': "7.92881", 'miny': "52.2131",
282     'maxx': "8.18349", 'maxy': "52.341"}
283     self.compareDicts(self.getLayerBBox('gewaesser', '4326'), bbox)
284    
285     # third layer non-inherited LatLonBoundingBox
286     bbox = {'minx': "7.93531", 'miny': "52.2328",
287     'maxx': "8.17739", 'maxy': "52.3353"}
288     self.compareDicts(self.getLayerBBox('gewaesserpolyl', '4326'), bbox)
289    
290    
291 joey 2130 def test_queryable(self):
292 joey 2114 """
293     Check if layers are properly classified queryable or not
294     """
295    
296     # implicit setting in main layer
297 joey 2134 self.assertEquals(self.isQueryable('Osnabrueck'), 0)
298 joey 2114
299     # explicit setting in second layer
300 joey 2134 self.assertEquals(self.isQueryable('gruenflaechen'), 0)
301 joey 2114
302     # inherited setting in second layer
303 joey 2134 self.assertEquals(self.isQueryable('gewaesser'), 0)
304 joey 2114
305     # explicit setting in second layer
306 joey 2134 self.assertEquals(self.isQueryable('sehenswuerdigkeiten'), 1)
307 joey 2114
308     # explicit setting in third layer
309 joey 2134 self.assertEquals(self.isQueryable('strassen'), 1)
310 joey 2114
311    
312     if __name__ == "__main__":
313     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