Test programs assumptions

Bernhard Herzog bh at intevation.de
Thu Mar 18 15:44:50 CET 2004


Martin Schulze <joey at infodrom.org> writes:

> Does this imply that other tests outside the test/ directory
> (i.e. ../Extension/**/test/test*.py) will be executed from within the
> test/ directory if they get included in the normal test suite?

If you run them with test/runtests.py (and expect the tests in test/ to
work): yes.

> As soon as you want to import other modules, load files, run external
> programs you have to make assumptions on the paths, which is why I
> ask, so I know how the tools are supposed to work.

Well, __file__ will give you the name of the current module, so you can
use that to figure out where files are if you know the location relative
to the module's file.  E.g. a file "foo" in the same directory is
usually os.path.join(os.path.dirname(__file__), "foo")

> Hmm, I'll rephrase my original question:

I can't simply make a cross in any one of these as the sitution a more
complex than that.

>  [ ] **/test/test_*.py except for the test programs in the test/
>      directory are supposed to run from the Thuban main directory
>      (which is not test/ but rather test/../)

It's OK if they can be run from that directory as long as they don't
rely on it.

>  [ ] **/test/test_*.py except for the test programs in the test/
>      directory are supposed to run from the Thuban test/ directory

It should be possible to run them this way.  They should not rely on it
though.  It's OK if they can be run from other directories too.

>  [ ] **/test/test_*.py are only supposed to run from the directory
>      they are placed in

That's the way it currently is for some of the tests, which is more or
less by accident.  I wouldn't say that they are supposed to be run from
there.  It's the only way it currently works if you want to be able to
run all the tests but that really is a bug that ought to be fixed.

>> See test/postgissupport.py for this might be used.  If you raise
>> SkipTest you need to use support.run_tests instead of unittest.main so
>> that it is handled as intended (with the normal unittest it would be
>> flagged as an error).
>
> Which leads me back to my initial question, which directory to assume
> besides the one the test is stored in, since support.py is either
> test.support, support or ../../../test/support.

Good question.  I must admit that I'm not sure exactly how we need to
extend the test suite and its support code to handle tests outside of
test/.  For the svgexport tests I only did the minimum to make them run
as part of the whole test suite when run via test/runtests.py.

The easiest way for you to continue is probably this:

create your own support module in Extensions/wms/test and put the some
code there that is run only once to add some directories to sys.path,
like the Thuban main directory and test so that you can import Thuban
and the test support modules.  You can't call it support.py though
because then it would shadow the support module from test/.

Longer term it would probably be a good idea to put the test support
code into a separate package alongside Thuban/ or maybe even in Thuban/.
Then you'd only have to make sure that you can import Thuban itself to
also get the test support code.


   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)