Test programs assumptions

Martin Schulze joey at infodrom.org
Fri Mar 19 16:30:37 CET 2004


Moin!

Bernhard Herzog wrote:
> 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.

Aye.

> 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.

I wonder how useful this is if you don't need the rest of Thuban but
only certain modules.  I believe that this would add quite some bloat
to the tests, which isn't required and has a chance of slowing down
things more than we want.  However, if you insist on this, I'll
implement it the way you want it.

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

I'll remove them.

> > @@ -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.

true.

> > -    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.

I understand.  However, in this particular case this won't work
because the main (and only) test class is a specialisation of the
class from the module we're importing and whose import we're trying to
catch with SkipTest.

ogclib contains class WMSClient

[..]
from ogclib import WMSClient

class TestWMSClient (unittest.TestCase, WMSClient)
      def...
      def
	  skip_if_no_ogclib()
[..]

This won't work since if the class TestWMSClient cannot be created
since WMSClient is not available.

Any idea how to solve this dilemma?

Regards,

	Joey

-- 
Unix is user friendly ...  It's just picky about its friends.




More information about the Thuban-devel mailing list

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