comparison test/runtests.py @ 12:f9f15ee39ed7

New Status class that handles several fields
author Bernhard Herzog <bh@intevation.de>
date Fri, 09 Mar 2007 18:23:09 +0100
parents
children
comparison
equal deleted inserted replaced
11:6efe0bd3d8c1 12:f9f15ee39ed7
1 # Copyright (C) 2007 by Intevation GmbH
2 # Authors:
3 # Bernhard Herzog <bh@intevation.de>
4 #
5 # This program is free software under the GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """
9 Main entry point for the test suite.
10
11 Just run this file as a python script to execute all tests
12 """
13
14 import os
15 import sys
16 import unittest
17 import optparse
18
19 test_dir = os.path.dirname(__file__)
20 sys.path.append(os.path.join(test_dir, os.pardir))
21
22 def find_test_modules(dirname, package = None):
23 """Return a list the names of the test modules in the directory dirname
24
25 The return value is a list of names that can be passed to
26 unittest.defaultTestLoader.loadTestsFromNames. Each name of the
27 list is the name of a pure python module, one for each file in
28 dirname whose name starts with 'test' and ends with '.py'.
29
30 The optional parameter package should be the name of the python
31 package whose directory is dirname. If package is given all names
32 in the returned list will be prefixed with package and a dot.
33 """
34 if package:
35 prefix = package + "."
36 else:
37 prefix = ""
38
39 suffix = ".py"
40 return [prefix + name[:-len(suffix)]
41 for name in os.listdir(dirname)
42 if name.startswith("test") and name.endswith(suffix)]
43
44
45 def main():
46 """Run all the tests in the test suite"""
47
48 parser = optparse.OptionParser()
49 parser.set_defaults(verbosity=1)
50 parser.add_option("-v", "--verbose", action="store_const", const=2,
51 dest="verbosity")
52 opts, rest = parser.parse_args()
53
54 # Build the list of test names. If names were given on the command
55 # line, run exactly those. Othwerwise build a default list of
56 # names.
57 if rest:
58 names = rest
59 else:
60 # All Python files starting with 'test' in the current directory
61 # and some directories in Extensions contain test cases.
62 # FIXME: It should be possible to run runtests.py even when not in
63 # the test directory
64 names = find_test_modules(test_dir)
65 suite = unittest.defaultTestLoader.loadTestsFromNames(names)
66 runner = unittest.TextTestRunner(verbosity=opts.verbosity)
67 result = runner.run(suite)
68 sys.exit(not result.wasSuccessful())
69
70
71 if __name__ == "__main__":
72 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)