/[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 2127 - (hide annotations)
Wed Mar 24 16:59:02 2004 UTC (20 years, 11 months ago) by joey
Original Path: trunk/thuban/Extensions/wms/test/test_parser.py
File MIME type: text/x-python
File size: 7866 byte(s)
Move loading the sample file into the setUp method.

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     class TestWMSCapabilitiesParser (unittest.TestCase, WMSCapabilitiesParser):
39     """
40     Defines a test environment for the class WMSCapabilities.
41     """
42    
43     def compareLists (self, foo, bar):
44     """
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     self.fail ("Different number of elements");
53    
54     # Loop through all elements for existance
55     for elm in foo:
56     if elm not in bar:
57     self.fail ("%s not in second list" % elm);
58    
59    
60     def compareDicts (self, foo, bar):
61     """
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     self.fail ("Different number of keys");
70    
71     # Loop through all elements for existance
72     for key in foo.keys():
73     if key not in bar:
74     self.fail ("%s not in second dictionary" % key);
75     if foo[key] != bar[key]:
76     self.fail ("%s has different value in second dictionary" % key);
77    
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     f = open ("sample.xml", "r")
88     except:
89     f = open (os.path.dirname (__file__) + "/sample.xml", "r")
90     except:
91     print "Cannot open sample.xml for reading"
92     else:
93     xml = f.read ();
94     f.close()
95     self.grok (xml)
96    
97    
98     def test_general (self):
99     """
100     Test general attributes extracted from Capabilities XML
101     """
102    
103 joey 2124 self.assertEquals (self.getTitle().encode('latin-1'),'Frida - Freie Vektor-Geodaten Osnabrück')
104 joey 2114 self.assertEquals (self.getAbstract(),'')
105     self.assertEquals (self.getFees(),'')
106     self.assertEquals (self.getAccessConstraints(),'')
107     formats = ['image/gif', 'image/png', 'image/jpeg', 'image/wbmp']
108     self.compareLists (self.getFormats(),formats)
109     layers = ['Osnabrueck', 'gruenflaechen', 'gewaesser',
110     'gewaesserpolyl','gewaesserlinien', 'strassen_all',
111     'strassenhinten', 'strassen', 'beschriftung',
112     'hauptbeschriftung', 'sehenswuerdigkeiten']
113     self.compareLists (self.getLayers(),layers)
114 joey 2124 self.compareLists (self.getSRS(),['31493'])
115 joey 2114
116    
117     def test_LayerTitle (self):
118     """
119     Check if layer titles are recognised properly
120     """
121    
122     # main layer
123 joey 2124 self.assertEquals (self.getLayerTitle('Osnabrueck').encode('latin-1'),'Frida - Freie Vektor-Geodaten Osnabrück')
124 joey 2114
125     # first nested layer
126 joey 2124 self.assertEquals (self.getLayerTitle('gruenflaechen').encode('latin-1'),'Grünflächen')
127 joey 2114
128     # first nested layer
129 joey 2124 self.assertEquals (self.getLayerTitle('gewaesser').encode('latin-1'),'Gewässer')
130 joey 2114
131     # second nested layer
132 joey 2124 self.assertEquals (self.getLayerTitle('gewaesserpolyl').encode('latin-1'),'Gewässerflächen')
133 joey 2114
134    
135     def test_LayerSRS (self):
136     """
137     Check if the SRS are returned properly
138     """
139    
140     # SRS of main layer
141 joey 2126 self.compareLists (self.getLayerSRS('Osnabrueck'),['31493'])
142 joey 2114
143     # Single SRS of layer without inheritance
144 joey 2126 self.compareLists (self.getLayerSRS('gruenflaechen'),['31493'])
145 joey 2114
146 joey 2126 # Multiple SRS of layer without inheritance, but overwriting
147     self.compareLists (self.getLayerSRS('gewaesserpolyl'),['31493', '31494'])
148 joey 2114
149 joey 2126 # Multiple SRS of layer with inheritance, one new locally
150     self.compareLists (self.getLayerSRS('gewaesserlinien'),['31493', '31492'])
151 joey 2114
152 joey 2126 # Multiple SRS with inheritance, two new locally
153     self.compareLists (self.getLayerSRS('strassen'),['31493', '31494', '31495'])
154 joey 2114
155 joey 2126 # Single SRS with inheritance but overwriting
156     self.compareLists (self.getLayerSRS('beschriftung'),['31493'])
157 joey 2114
158    
159     def test_LatLonBoundingBoxes (self):
160     """
161     Check if the LatLonBoundingBoxes are returned properly
162     """
163    
164     # main LatLonBoundingBox
165     bbox = {'minx': "7.92881", 'miny': "52.2131",
166     'maxx': "8.18349", 'maxy': "52.341"}
167     self.compareDicts (self.getLayerLatLonBBox('Osnabrueck'),bbox)
168    
169     # inherited LatLonBoundingBox
170     bbox = {'minx': "7.92881", 'miny': "52.2131",
171     'maxx': "8.18349", 'maxy': "52.341"}
172     self.compareDicts (self.getLayerLatLonBBox('gewaesser'),bbox)
173    
174     # third layer non-inherited LatLonBoundingBox
175     bbox = {'minx': "7.93531", 'miny': "52.2328",
176     'maxx': "8.17739", 'maxy': "52.3353"}
177     self.compareDicts (self.getLayerLatLonBBox('gewaesserpolyl'),bbox)
178    
179    
180     def test_BoundingBoxes (self):
181     """
182     Check if the BoundingBoxes are returned properly
183     """
184    
185     # main BoundingBox
186     bbox = {'minx': "3.427e+06", 'miny': "5.787e+06",
187     'maxx': "3.4442e+06", 'maxy': "5.801e+06"}
188 joey 2126 self.compareDicts (self.getLayerBBox('Osnabrueck', '31493'),bbox)
189 joey 2114
190     # inherited BoundingBox
191 joey 2126 self.compareDicts (self.getLayerBBox('gewaesser', '31493'),bbox)
192 joey 2114
193     # overwritten BoundingBox
194     bbox = {'minx': "3.427e+06", 'miny': "5.78901e+06",
195     'maxx': "3.44173e+06", 'maxy': "5.79952e+06"}
196 joey 2126 self.compareDicts (self.getLayerBBox('gewaesserlinien', '31492'),bbox)
197 joey 2114
198     # multiple BoundingBoxes
199     bbox = {'minx': "3.42743e+06", 'miny': "5.78919e+06",
200     'maxx': "3.44381e+06", 'maxy': "5.80038e+06"}
201 joey 2126 self.compareDicts (self.getLayerBBox('gewaesserpolyl', '31493'),bbox)
202 joey 2114 bbox = {'minx': "3.42742e+06", 'miny': "5.78918e+06",
203     'maxx': "3.44380e+06", 'maxy': "5.80037e+06"}
204 joey 2126 self.compareDicts (self.getLayerBBox('gewaesserpolyl', '31494'),bbox)
205 joey 2114
206 joey 2119
207 joey 2114 def test_queryable (self):
208     """
209     Check if layers are properly classified queryable or not
210     """
211    
212     # implicit setting in main layer
213     self.assertEquals (self.isQueryable('Osnabrueck'),0)
214    
215     # explicit setting in second layer
216     self.assertEquals (self.isQueryable('gruenflaechen'),0)
217    
218     # inherited setting in second layer
219     self.assertEquals (self.isQueryable('gewaesser'),0)
220    
221     # explicit setting in second layer
222     self.assertEquals (self.isQueryable('sehenswuerdigkeiten'),1)
223    
224     # explicit setting in third layer
225     self.assertEquals (self.isQueryable('strassen'),1)
226    
227    
228     if __name__ == "__main__":
229     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