1 |
# Copyright (c) 2002, 2003 by Intevation GmbH |
# Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
35 |
support.initthuban() |
support.initthuban() |
36 |
import Thuban.Lib.connector |
import Thuban.Lib.connector |
37 |
|
|
38 |
|
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 |
def main(): |
def main(): |
61 |
"""Run all the tests in the Thuban test suite""" |
"""Run all the tests in the Thuban test suite""" |
62 |
|
|
74 |
|
|
75 |
verbosity = 1 |
verbosity = 1 |
76 |
|
|
77 |
opts, args = getopt.getopt(sys.argv[1:], 'v', ['verbose']) |
opts, args = getopt.getopt(sys.argv[1:], 'v', |
78 |
|
['verbose', "internal-encoding="]) |
79 |
for optchar, value in opts: |
for optchar, value in opts: |
80 |
if optchar in ("-v", "--verbose"): |
if optchar in ("-v", "--verbose"): |
81 |
verbosity = 2 |
verbosity = 2 |
82 |
|
elif optchar == "--internal-encoding": |
83 |
|
Thuban.set_internal_encoding(value) |
84 |
else: |
else: |
85 |
print>>sys.stderr, "Unknown option", optchar |
print>>sys.stderr, "Unknown option", optchar |
86 |
|
|
87 |
# All Python files starting with test in the current directory |
# Build the list of test names. If names were given on the command |
88 |
# contain test cases. |
# line, run exactly those. Othwerwise build a default list of |
89 |
# FIXME: It should be possible to run runtests.py even when not in |
# names. |
|
# the test directory |
|
|
files = os.listdir(os.curdir) |
|
90 |
if args: |
if args: |
91 |
names = args |
names = args |
92 |
else: |
else: |
93 |
names = [] |
# All Python files starting with 'test' in the current directory |
94 |
for file in files: |
# and some directories in Extensions contain test cases. |
95 |
if file[:4] == "test" and file[-3:] == ".py": |
# FIXME: It should be possible to run runtests.py even when not in |
96 |
names.append(file[:-3]) |
# the test directory |
97 |
|
names = find_test_modules(".") |
98 |
|
names += find_test_modules("../Extensions/svgexport/test", |
99 |
|
"Extensions.svgexport.test") |
100 |
|
names += find_test_modules("../Extensions/ogr/test", |
101 |
|
"Extensions.ogr.test") |
102 |
suite = unittest.defaultTestLoader.loadTestsFromNames(names) |
suite = unittest.defaultTestLoader.loadTestsFromNames(names) |
103 |
runner = support.ThubanTestRunner(verbosity = verbosity) |
runner = support.ThubanTestRunner(verbosity = verbosity) |
104 |
result = support.execute_as_testsuite(runner.run, suite) |
result = support.execute_as_testsuite(runner.run, suite) |