joey: thuban/Extensions/wms/test test_ogclib.py,1.4,1.5

cvs@intevation.de cvs at intevation.de
Fri Mar 19 17:57:33 CET 2004


Author: joey

Update of /thubanrepository/thuban/Extensions/wms/test
In directory doto:/tmp/cvs-serv25518

Modified Files:
	test_ogclib.py 
Log Message:
Several improvements:

 . Moved path detection and adding into a module of its own,
   adjustpath, which exports thubandir as main Thuban directory.

 . Reorganised the module in order to support the SkipTest feature for
   Thuban test cases.

   - Adjusted the error handling for importing the ogclib from the
     PyOGCLib package.

   - The test class is no longer a specialisation of WMSClient, but
     contains an instance of this particular class and uses its
     methods instead.

   - The special setUp() method will check whether importing PyOGCLib
     worked by calling the external function skip_if_no_ogclib() and
     also create the WMSClient instance.

   - Call support.run_tests() instead of unittest.main().

Index: test_ogclib.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/wms/test/test_ogclib.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- test_ogclib.py	18 Mar 2004 17:13:28 -0000	1.4
+++ test_ogclib.py	19 Mar 2004 16:57:31 -0000	1.5
@@ -24,14 +24,10 @@
 from string import split
 from sys import path
 
-# Add the main Thuban directory so the path so that all modules are
-# accessible as expected
-#
-if os.path.dirname (__file__) == "" or os.path.dirname (__file__) == ".":
-    thubandir = os.path.abspath ("../../../")
-else:
-    thubandir = os.path.abspath (os.path.dirname(__file__) + "/../../..")
-path.insert (0, thubandir)
+from adjustpath import thubandir
+path.insert (0, thubandir + "/test")
+
+import support
 
 # ----------------------------------------------------------------------
 # FIXME: Temporary code until PyOGCLib is a standard requirement
@@ -46,19 +42,25 @@
     path.insert (0, pyogclib)
 # ----------------------------------------------------------------------
 
+_pyogclib_import_error = None
 try:
     from ogclib.WMSClient import WMSClient
-except:
-    print "No PyOGCLib found, hence no tests available."
-    os._exit(-1)
+except ImportError, extra:
+    _pyogclib_import_error = str(extra)
 
 
-class TestOGCLib (unittest.TestCase, WMSClient):
+class TestOGCLib (unittest.TestCase):
     """
     Defines a test environment for the PyOGCLib, i.e. check whether URL
     strings are built properly.
     """
 
+    wmsclient = None
+
+    def setUp (self):
+        skip_if_no_ogclib()
+        self.wmsclient = WMSClient()
+
     def compare_URLs (self, foo, bar):
         """
         Check if two URLs are equal, i.e.:
@@ -115,11 +117,11 @@
 
         frida = "http://frida.intevation.org/cgi-bin/frida_wms?"
 
-        url = self.getCapabilitiesURL(frida, "1.0")
+        url = self.wmsclient.getCapabilitiesURL(frida, "1.0")
         result = frida + "WMTVER=1.0&REQUEST=capabilities"
         self.compare_URLs (url, result)
 
-        url = self.getCapabilitiesURL(frida, "1.1")
+        url = self.wmsclient.getCapabilitiesURL(frida, "1.1")
         result = frida + "VERSION=1.1&SERVICE=WMS&REQUEST=GetCapabilities"
         self.compare_URLs (url, result)
 
@@ -148,7 +150,7 @@
         result = result_base + \
                  "&LAYERS=" + "%2C".join(layers) + \
                  "&STYLES=" + "%2C".join(styles)
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version)
 
         # Repeat and continue with version 1.1, as denoted in OGC 01-068r3
@@ -162,18 +164,18 @@
         result = result_base + \
                  "&LAYERS=" + "%2C".join(layers) + \
                  "&STYLES=" + "%2C".join(styles)
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version)
         self.compare_URLs (result, url)
 
         result += "&TRANSPARENT=TRUE"
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version,
                              transparent=1 )
         self.compare_URLs (result, url)
 
         result += "&BGCOLOR=0xFF00FF"
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version,
                              transparent=1, bgcolor='0xFF00FF')
         self.compare_URLs (result, url)
@@ -182,7 +184,7 @@
         result = result_base + \
                  "&LAYERS=" + "%2C".join(layers) + \
                  "&STYLES=" + "%2C".join(styles)
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version)
         self.compare_URLs (result, url)
 
@@ -190,7 +192,7 @@
         result = result_base + \
                  "&LAYERS=" + "%2C".join(layers) + \
                  "&STYLES=" + "%2C".join(styles)
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version)
         self.compare_URLs (result, url)
 
@@ -198,7 +200,7 @@
         result = result_base + \
                  "&LAYERS=" + "%2C".join(layers) + \
                  "&STYLES=" + "%2C".join(styles)
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version,
                              styles = styles)
         self.compare_URLs (result, url)
@@ -207,14 +209,20 @@
         result = result_base + \
                  "&LAYERS=" + "%2C".join(layers) + \
                  "&STYLES=" + "%2C".join(styles)
-        url = self.getMapURL(frida, format, width, height, epsg,
+        url = self.wmsclient.getMapURL(frida, format, width, height, epsg,
                              bbox, layers, version=version,
                              styles = styles)
         self.compare_URLs (result, url)
 
 
+def skip_if_no_ogclib():
+    if _pyogclib_import_error is not None:
+        raise support.SkipTest(_pyogclib_import_error)
+#        raise support.SkipTest("No PyOGCLib found, hence no tests available.")
+
+
 if __name__ == "__main__":
-    unittest.main()
+    support.run_tests()
 
 """
 





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)