1 # Copyright (C) 2005-2010 Aaron Bentley <abentley@panoramicfeedback.com>
2 # Marien Zwart <marienz@gentoo.org>
3 # W. Trevor King <wking@drexel.edu>
5 # This file is part of Bugs Everywhere.
7 # Bugs Everywhere is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation, either version 2 of the License, or (at your
10 # option) any later version.
12 # Bugs Everywhere is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
28 from libbe.util.tree import Tree
29 from libbe.util.plugin import import_by_name
30 from libbe.version import version
32 def python_tree(root_path='libbe', root_modname='libbe'):
39 if f.path.endswith('.py'):
40 f.name = os.path.basename(f.path)[:-len('.py')]
41 elif os.path.isdir(f.path) \
42 and os.path.exists(os.path.join(f.path, '__init__.py')):
43 f.name = os.path.basename(f.path)
45 for child in os.listdir(f.path):
46 if child == '__init__.py':
49 c.path = os.path.join(f.path, child)
55 f.modname = root_modname
57 f.modname = f.parent.modname + '.' + f.name
61 def add_module_tests(suite, modname):
63 mod = import_by_name(modname)
65 print >> sys.stderr, 'Failed to import "%s"' % (modname)
67 if hasattr(mod, 'suite'):
70 s = unittest.TestLoader().loadTestsFromModule(mod)
72 sdoc = doctest.DocTestSuite(mod)
78 if __name__ == '__main__':
80 parser = optparse.OptionParser(usage='%prog [options] [modules ...]',
82 """When called without optional module names, run the test suites for
83 *all* modules. This may raise lots of errors if you haven't installed
84 one of the versioning control systems.
86 When called with module name arguments, only run the test suites from
87 those modules and their submodules. For example::
89 $ python test.py libbe.bugdir libbe.storage
91 parser.add_option('-q', '--quiet', action='store_true', default=False,
92 help='Run unittests in quiet mode (verbosity 1).')
93 options,args = parser.parse_args()
94 print >> sys.stderr, 'Testing BE\n%s' % version(verbose=True)
97 if options.quiet == True:
100 suite = unittest.TestSuite()
103 for node in tree.traverse():
104 add_module_tests(suite, node.modname)
108 for node in tree.traverse():
109 if node.modname == modname:
110 for n in node.traverse():
111 if n.modname not in added:
112 add_module_tests(suite, n.modname)
113 added.append(n.modname)
116 result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
118 numErrors = len(result.errors)
119 numFailures = len(result.failures)
120 numBad = numErrors + numFailures