1 # Copyright (C) 2005-2010 Aaron Bentley and Panometrics, Inc.
2 # Marien Zwart <marienz@gentoo.org>
3 # W. Trevor King <wking@drexel.edu>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 """Usage: python test.py [module(s) ...]
21 When called without optional module names, run the test suites for
22 *all* modules. This may raise lots of errors if you haven't installed
23 one of the versioning control systems.
25 When called with module name arguments, only run the test suites from
26 those modules and their submodules. For example:
27 python test.py libbe.bugdir libbe.storage
38 from libbe.util.tree import Tree
39 from libbe.util.plugin import import_by_name
41 def python_tree(root_path='libbe', root_modname='libbe'):
48 if f.path.endswith('.py'):
49 f.name = os.path.basename(f.path)[:-len('.py')]
50 elif os.path.isdir(f.path) \
51 and os.path.exists(os.path.join(f.path, '__init__.py')):
52 f.name = os.path.basename(f.path)
54 for child in os.listdir(f.path):
55 if child == '__init__.py':
58 c.path = os.path.join(f.path, child)
64 f.modname = root_modname
66 f.modname = f.parent.modname + '.' + f.name
70 def add_module_tests(suite, modname):
72 mod = import_by_name(modname)
74 print >> sys.stderr, 'Failed to import "%s"' % (modname)
76 if hasattr(mod, 'suite'):
79 s = unittest.TestLoader().loadTestsFromModule(mod)
81 sdoc = doctest.DocTestSuite(mod)
87 suite = unittest.TestSuite()
89 if len(sys.argv) <= 1:
90 for node in tree.traverse():
91 add_module_tests(suite, node.modname)
94 for modname in sys.argv[1:]:
95 for node in tree.traverse():
96 if node.modname == modname:
97 for n in node.traverse():
98 if n.modname not in added:
99 add_module_tests(suite, n.modname)
100 added.append(n.modname)
103 result = unittest.TextTestRunner(verbosity=2).run(suite)
105 numErrors = len(result.errors)
106 numFailures = len(result.failures)
107 numBad = numErrors + numFailures