1 |
bh |
2640 |
# Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH |
2 |
bh |
292 |
# Authors: |
3 |
|
|
# Bernhard Herzog <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
""" |
9 |
|
|
Main entry point for the Thuban test suite. |
10 |
|
|
|
11 |
|
|
Just run this file as a python script to execute all tests |
12 |
|
|
""" |
13 |
|
|
|
14 |
bh |
1269 |
__version__ = "$Revision$" |
15 |
|
|
# $Source$ |
16 |
|
|
# $Id$ |
17 |
bh |
292 |
|
18 |
bh |
1458 |
import os |
19 |
|
|
|
20 |
|
|
# It should be possible to run the Thuban testsuite without an X |
21 |
|
|
# connection, so we remove the DISPLAY environment variable which should |
22 |
|
|
# lead to an error if the wxGTK module is imported accidentally. The |
23 |
|
|
# DISPLAY variable is not always set so we catch and ignore the KeyError |
24 |
|
|
try: |
25 |
|
|
del os.environ["DISPLAY"] |
26 |
|
|
except KeyError: |
27 |
|
|
pass |
28 |
|
|
|
29 |
|
|
import sys |
30 |
bh |
1219 |
import warnings |
31 |
bh |
292 |
import unittest |
32 |
bh |
1377 |
import getopt |
33 |
bh |
292 |
|
34 |
|
|
import support |
35 |
|
|
support.initthuban() |
36 |
|
|
import Thuban.Lib.connector |
37 |
|
|
|
38 |
bh |
2079 |
def find_test_modules(dirname, package = None): |
39 |
|
|
"""Return a list the names of the test modules in the directory dirname |
40 |
|
|
|
41 |
|
|
The return value is a list of names that can be passed to |
42 |
|
|
unittest.defaultTestLoader.loadTestsFromNames. Each name of the |
43 |
|
|
list is the name of a pure python module, one for each file in |
44 |
|
|
dirname that starts with 'test'. |
45 |
|
|
|
46 |
|
|
The optional parameter package should be the name of the python |
47 |
|
|
package whose directory is dirname. If package is given all names |
48 |
|
|
in the returned list will be prefixed with package and a dot. |
49 |
|
|
""" |
50 |
|
|
if package: |
51 |
|
|
prefix = package + "." |
52 |
|
|
else: |
53 |
|
|
prefix = "" |
54 |
|
|
|
55 |
|
|
return [prefix + name[:-3] |
56 |
|
|
for name in os.listdir(dirname) |
57 |
|
|
if name[:4] == "test" and name[-3:] == ".py"] |
58 |
|
|
|
59 |
|
|
|
60 |
bh |
292 |
def main(): |
61 |
|
|
"""Run all the tests in the Thuban test suite""" |
62 |
|
|
|
63 |
bh |
1219 |
# Turn Thuban's deprecation warnings into errors so they're cought |
64 |
|
|
# by the tests |
65 |
|
|
# |
66 |
|
|
# Maintenance: Keep a warning filter until the backwards |
67 |
|
|
# compatibility code is removed at which time using the old |
68 |
|
|
# interfaces should lead to other errors anyway. |
69 |
|
|
|
70 |
|
|
# The layer attributes table, shapetable, shapefile and filename are |
71 |
|
|
# deprecated. |
72 |
|
|
warnings.filterwarnings("error", "The Layer attribute.*is deprecated", |
73 |
|
|
DeprecationWarning) |
74 |
|
|
|
75 |
bh |
1377 |
verbosity = 1 |
76 |
bh |
1219 |
|
77 |
bh |
1377 |
opts, args = getopt.getopt(sys.argv[1:], 'v', ['verbose']) |
78 |
|
|
for optchar, value in opts: |
79 |
bh |
1476 |
if optchar in ("-v", "--verbose"): |
80 |
bh |
1377 |
verbosity = 2 |
81 |
jonathan |
1396 |
else: |
82 |
|
|
print>>sys.stderr, "Unknown option", optchar |
83 |
bh |
1377 |
|
84 |
bh |
2079 |
# Build the list of test names. If names were given on the command |
85 |
|
|
# line, run exactly those. Othwerwise build a default list of |
86 |
|
|
# names. |
87 |
bh |
1838 |
if args: |
88 |
|
|
names = args |
89 |
|
|
else: |
90 |
bh |
2079 |
# All Python files starting with 'test' in the current directory |
91 |
|
|
# and some directories in Extensions contain test cases. |
92 |
|
|
# FIXME: It should be possible to run runtests.py even when not in |
93 |
|
|
# the test directory |
94 |
|
|
names = find_test_modules(".") |
95 |
|
|
names += find_test_modules("../Extensions/svgexport/test", |
96 |
|
|
"Extensions.svgexport.test") |
97 |
bh |
2640 |
names += find_test_modules("../Extensions/ogr/test", |
98 |
|
|
"Extensions.ogr.test") |
99 |
bh |
292 |
suite = unittest.defaultTestLoader.loadTestsFromNames(names) |
100 |
bh |
1555 |
runner = support.ThubanTestRunner(verbosity = verbosity) |
101 |
bh |
1601 |
result = support.execute_as_testsuite(runner.run, suite) |
102 |
bh |
292 |
|
103 |
|
|
sys.exit(not result.wasSuccessful()) |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
if __name__ == "__main__": |
107 |
|
|
main() |