/[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 2382 - (hide annotations)
Mon Oct 4 17:03:29 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: 10916 byte(s)
Adding more tests to verify the test routine fails with non-equal arguments

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 joey 2382 # Non-Equality of different lists
116     self.assertRaises(AssertionError, self.compareLists, [1,2], [3,2])
117 joey 2381
118 joey 2382 # Non-Equality of different lists
119     self.assertRaises(AssertionError, self.compareLists, [1,2], [3,2,1])
120 joey 2381
121 joey 2382 # Non-Equality of empty and non-empty list
122     self.assertRaises(AssertionError, self.compareLists, [], [3,2,1])
123    
124    
125 joey 2381 def test_compareDicts(self):
126     """
127     Test the internal compareDicts method.
128     """
129    
130     # Equality of empty dictionaries
131     self.compareDicts({}, {})
132    
133     # Equality of equal dictionaries
134     # Python may represent the dictionaries differently
135     self.compareDicts({10:20, 11:30}, {10:20, 11:30})
136    
137     # Equality of permuted dictionaries
138     # Python may represent the dictionaries similar anyway
139     self.compareDicts({10:20, 11:30}, {11:30, 10:20})
140    
141 joey 2382 # Non-equality of different dictionaries
142     self.assertRaises(AssertionError, self.compareDicts, {10:20, 11:30},
143     {10:20, 11:30, 12:40})
144 joey 2381
145 joey 2382 # Non-equality of empty and non-empty dictionaries
146     self.assertRaises(AssertionError, self.compareDicts, {},
147     {10:20, 11:30, 12:40})
148 joey 2381
149 joey 2382
150 joey 2130 def test_general(self):
151 joey 2114 """
152     Test general attributes extracted from Capabilities XML
153     """
154    
155 joey 2134 self.assertEquals(self.getTitle().encode('latin-1'),
156     'Frida - Freie Vektor-Geodaten Osnabrück')
157     self.assertEquals(self.getAbstract(), '')
158     self.assertEquals(self.getFees(), '')
159     self.assertEquals(self.getAccessConstraints(), '')
160 joey 2114 formats = ['image/gif', 'image/png', 'image/jpeg', 'image/wbmp']
161 joey 2134 self.compareLists(self.getFormats(), formats)
162 joey 2114 layers = ['Osnabrueck', 'gruenflaechen', 'gewaesser',
163     'gewaesserpolyl','gewaesserlinien', 'strassen_all',
164     'strassenhinten', 'strassen', 'beschriftung',
165     'hauptbeschriftung', 'sehenswuerdigkeiten']
166 joey 2134 self.compareLists(self.getLayers(), layers)
167     self.compareLists(self.getSRS(), ['31493'])
168 joey 2114
169    
170 joey 2130 def test_LayerTitle(self):
171 joey 2114 """
172     Check if layer titles are recognised properly
173     """
174    
175     # main layer
176 joey 2134 self.assertEquals(self.getLayerTitle('Osnabrueck').encode('latin-1'),
177     'Frida - Freie Vektor-Geodaten Osnabrück')
178 joey 2114
179     # first nested layer
180 joey 2135 self.assertEquals(self.getLayerTitle(
181     'gruenflaechen').encode('latin-1'),
182 joey 2134 'Grünflächen')
183 joey 2114
184     # first nested layer
185 joey 2134 self.assertEquals(self.getLayerTitle('gewaesser').encode('latin-1'),
186     'Gewässer')
187 joey 2114
188     # second nested layer
189 joey 2135 self.assertEquals(self.getLayerTitle(
190     'gewaesserpolyl').encode('latin-1'),
191 joey 2134 'Gewässerflächen')
192 joey 2114
193    
194 joey 2130 def test_LayerSRS(self):
195 joey 2114 """
196     Check if the SRS are returned properly
197     """
198    
199     # SRS of main layer
200 joey 2134 self.compareLists(self.getLayerSRS('Osnabrueck'), ['31493'])
201 joey 2114
202     # Single SRS of layer without inheritance
203 joey 2134 self.compareLists(self.getLayerSRS('gruenflaechen'), ['31493'])
204 joey 2114
205 joey 2126 # Multiple SRS of layer without inheritance, but overwriting
206 joey 2135 self.compareLists(self.getLayerSRS('gewaesserpolyl'),
207     ['31493', '31494'])
208 joey 2114
209 joey 2126 # Multiple SRS of layer with inheritance, one new locally
210 joey 2135 self.compareLists(self.getLayerSRS('gewaesserlinien'),
211     ['31493', '31492'])
212 joey 2114
213 joey 2126 # Multiple SRS with inheritance, two new locally
214 joey 2135 self.compareLists(self.getLayerSRS('strassen'),
215     ['31493', '31494', '31495'])
216 joey 2114
217 joey 2126 # Single SRS with inheritance but overwriting
218 joey 2141 self.compareLists(self.getLayerSRS('beschriftung'),
219     ['31493', '31494', '31495'])
220 joey 2114
221 joey 2168 # SRS of a layer with AUTO SRS ignored
222     self.compareLists(self.getLayerSRS('sehenswuerdigkeiten'), ['31493'])
223 joey 2114
224 joey 2168
225 joey 2130 def test_LatLonBoundingBoxes(self):
226 joey 2114 """
227     Check if the LatLonBoundingBoxes are returned properly
228     """
229    
230     # main LatLonBoundingBox
231     bbox = {'minx': "7.92881", 'miny': "52.2131",
232     'maxx': "8.18349", 'maxy': "52.341"}
233 joey 2134 self.compareDicts(self.getLayerLatLonBBox('Osnabrueck'), bbox)
234 joey 2114
235     # inherited LatLonBoundingBox
236     bbox = {'minx': "7.92881", 'miny': "52.2131",
237     'maxx': "8.18349", 'maxy': "52.341"}
238 joey 2134 self.compareDicts(self.getLayerLatLonBBox('gewaesser'), bbox)
239 joey 2114
240     # third layer non-inherited LatLonBoundingBox
241     bbox = {'minx': "7.93531", 'miny': "52.2328",
242     'maxx': "8.17739", 'maxy': "52.3353"}
243 joey 2134 self.compareDicts(self.getLayerLatLonBBox('gewaesserpolyl'), bbox)
244 joey 2114
245    
246 joey 2130 def test_BoundingBoxes(self):
247 joey 2114 """
248     Check if the BoundingBoxes are returned properly
249     """
250    
251     # main BoundingBox
252     bbox = {'minx': "3.427e+06", 'miny': "5.787e+06",
253     'maxx': "3.4442e+06", 'maxy': "5.801e+06"}
254 joey 2134 self.compareDicts(self.getLayerBBox('Osnabrueck', '31493'), bbox)
255 joey 2114
256     # inherited BoundingBox
257 joey 2134 self.compareDicts(self.getLayerBBox('gewaesser', '31493'), bbox)
258 joey 2114
259     # overwritten BoundingBox
260     bbox = {'minx': "3.427e+06", 'miny': "5.78901e+06",
261     'maxx': "3.44173e+06", 'maxy': "5.79952e+06"}
262 joey 2134 self.compareDicts(self.getLayerBBox('gewaesserlinien', '31492'), bbox)
263 joey 2114
264     # multiple BoundingBoxes
265     bbox = {'minx': "3.42743e+06", 'miny': "5.78919e+06",
266     'maxx': "3.44381e+06", 'maxy': "5.80038e+06"}
267 joey 2134 self.compareDicts(self.getLayerBBox('gewaesserpolyl', '31493'), bbox)
268 joey 2114 bbox = {'minx': "3.42742e+06", 'miny': "5.78918e+06",
269     'maxx': "3.44380e+06", 'maxy': "5.80037e+06"}
270 joey 2134 self.compareDicts(self.getLayerBBox('gewaesserpolyl', '31494'), bbox)
271 joey 2114
272 joey 2142 # Non-existing BoundingBox
273     self.assertEquals(self.getLayerBBox('beschriftung', '31490'), None)
274 joey 2119
275 joey 2142
276 joey 2169 def test_LatLonBoundingBoxes_as_bboxes(self):
277     """
278     Check if the LatLonBoundingBoxes are returned properly
279     """
280    
281     # main LatLonBoundingBox
282     bbox = {'minx': "7.92881", 'miny': "52.2131",
283     'maxx': "8.18349", 'maxy': "52.341"}
284     self.compareDicts(self.getLayerBBox('Osnabrueck', '4326'), bbox)
285    
286     # inherited LatLonBoundingBox
287     bbox = {'minx': "7.92881", 'miny': "52.2131",
288     'maxx': "8.18349", 'maxy': "52.341"}
289     self.compareDicts(self.getLayerBBox('gewaesser', '4326'), bbox)
290    
291     # third layer non-inherited LatLonBoundingBox
292     bbox = {'minx': "7.93531", 'miny': "52.2328",
293     'maxx': "8.17739", 'maxy': "52.3353"}
294     self.compareDicts(self.getLayerBBox('gewaesserpolyl', '4326'), bbox)
295    
296    
297 joey 2130 def test_queryable(self):
298 joey 2114 """
299     Check if layers are properly classified queryable or not
300     """
301    
302     # implicit setting in main layer
303 joey 2134 self.assertEquals(self.isQueryable('Osnabrueck'), 0)
304 joey 2114
305     # explicit setting in second layer
306 joey 2134 self.assertEquals(self.isQueryable('gruenflaechen'), 0)
307 joey 2114
308     # inherited setting in second layer
309 joey 2134 self.assertEquals(self.isQueryable('gewaesser'), 0)
310 joey 2114
311     # explicit setting in second layer
312 joey 2134 self.assertEquals(self.isQueryable('sehenswuerdigkeiten'), 1)
313 joey 2114
314     # explicit setting in third layer
315 joey 2134 self.assertEquals(self.isQueryable('strassen'), 1)
316 joey 2114
317    
318     if __name__ == "__main__":
319     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