Test programs assumptions

Bernhard Herzog bh at intevation.de
Fri Mar 19 14:59:46 CET 2004


Martin Schulze <joey at infodrom.org> writes:

> Index: test_ogclib.py
> ===================================================================
> RCS file: /thubanrepository/thuban/Extensions/wms/test/test_ogclib.py,v
> retrieving revision 1.4
> diff -u -r1.4 test_ogclib.py
> --- test_ogclib.py	18 Mar 2004 17:13:28 -0000	1.4
> +++ test_ogclib.py	18 Mar 2004 19:30:57 -0000
> @@ -31,8 +31,11 @@
>      thubandir = os.path.abspath ("../../../")
>  else:
>      thubandir = os.path.abspath (os.path.dirname(__file__) + "/../../..")
> +path.insert (0, thubandir + "/test")
>  path.insert (0, thubandir)

This path munging code should really be in a separate module so that you
don't have to repeat in all the test modules.

Lokking at it a bit closer, you probably should only add the test
directory, import support and call support.initthuban() which will do
all the rest.  initthuban is what all the test modules in test/ use.

Oh, and I'd prefer no spaces before the open parenthese for function
calls or in function and class definitions.

> @@ -49,8 +52,7 @@
>  try:
>      from ogclib.WMSClient import WMSClient
>  except:

It's better to only catch ImportErrors here.  Catch all excepts often
hide unexpected errors.

> -    print "No PyOGCLib found, hence no tests available."
> -    os._exit(-1)
> +    raise support.SkipTest("No PyOGCLib found, hence no tests available.")

This will raise SkipTest when the module is imported, which is too
early.  It only works from within setUp or a test method.


In the postgissupport module this situation is handled by first catching
import errors for psycopg:

try:
    import psycopg
except ImportError:
    psycopg = None


and then a function called by all postgis tests in the setUp method or
in the test method:

_cannot_run_postgis_tests = None
def skip_if_no_postgis():
    global _cannot_run_postgis_tests
    if _cannot_run_postgis_tests is None:
        _cannot_run_postgis_tests = reason_for_not_running_tests()
    if _cannot_run_postgis_tests:
        raise support.SkipTest(_cannot_run_postgis_tests)

reason_for_not_running_tests checks whether psycopg is None but also
does a few more tests since psycopg isn't the only requirement for the
postgis tests.  Something simpler might suffice for your needs.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Skencil                                http://sketch.sourceforge.net/
Thuban                                  http://thuban.intevation.org/




More information about the Thuban-devel mailing list

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