annotate test/runtests.py @ 542:dc17b62d3cdd

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