aboutsummaryrefslogtreecommitdiffstats
path: root/test.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-31 15:54:12 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-31 15:54:12 -0500
commitb0b5341c4045dd27cfbb3e2585cb2614ed9ad903 (patch)
tree37c7c2d011617ccd7a6f28a24ea77bb1b3cddfe7 /test.py
parenta06030436d3940dddfba37b344f90651366d67e1 (diff)
parent2d1562d951e763fed71fe60e77cc9921be9abdc9 (diff)
downloadbugseverywhere-b0b5341c4045dd27cfbb3e2585cb2614ed9ad903.tar.gz
Merged be.restructure, major internal reorganization.
Added a bunch of classes to make the commands, user interfaces, and storage backends more abstract and distinct. This should make it much easier to extend and maintain BE. Features: * Directory restructured: becommands/ -> libbe/commands submods sorted by functionality. * Lots of new classes: Option, Argument, Command InputOutput, StorageCallbacks, UserInterface Storage * Consolidated ID handling in libbe.util.id * Transitioned VCS backends for Python-based VCSs from subprocess calss to internal python calls. Plus the user-visible changes: * New bugdir/bug/comment ID format replaces old bug:comment format. * Deprecated support for `be diff` on Arch and Darcs <= 2.3.1. A new backend abstraction (Storage) makes the former implementation ungainly. * Improved command completion. * Removed commands close, open, email_bugs, * Flipped some arguments `be assign BUG-ID [ASSIGNEE]` -> `be status ASSIGNED BUG-ID ...` `be severity BUG-ID SEVERITY` -> `be severity SEVERITY BUG-ID ...` `be status BUG-ID STATUS` -> `be status STATUS BUG-ID ...` In the merge: * Added 'commit' to list of pagerless commands. * Updated doc/README.dev See #bea86499-824e-4e77-b085-2d581fa9ccab/1100c966-9671-4bc6-8b68-6d408a910da1# for a discussion of why the changes were made and some of the difficulties en-route.
Diffstat (limited to 'test.py')
-rw-r--r--test.py114
1 files changed, 74 insertions, 40 deletions
diff --git a/test.py b/test.py
index 4f20808..f26aaa8 100644
--- a/test.py
+++ b/test.py
@@ -1,54 +1,88 @@
+# Copyright
+
"""Usage: python test.py [module(s) ...]
-When called without optional module names, run the doctests from *all*
-modules. This may raise lots of errors if you haven't installed one
-of the versioning control systems.
+When called without optional module names, run the test suites for
+*all* modules. This may raise lots of errors if you haven't installed
+one of the versioning control systems.
-When called with module name arguments, only run the doctests from
-those modules.
+When called with module name arguments, only run the test suites from
+those modules and their submodules. For example:
+ python test.py libbe.bugdir libbe.storage
"""
-import libbe
-libbe.TESTING = True
-from libbe import plugin, vcs
-import unittest
import doctest
+import os
+import os.path
import sys
+import unittest
-suite = unittest.TestSuite()
+import libbe
+libbe.TESTING = True
+from libbe.util.tree import Tree
+from libbe.util.plugin import import_by_name
-if len(sys.argv) > 1:
- for submodname in sys.argv[1:]:
- match = False
- mod = plugin.get_plugin("libbe", submodname)
- if mod is not None:
- if hasattr(mod, "suite"):
- suite.addTest(mod.suite)
- match = True
- else:
- print "Module \"%s\" has no test suite" % submodname
- mod = plugin.get_plugin("becommands", submodname)
- if mod is not None:
- if hasattr(mod, "suite"):
- suite.addTest(mod.suite)
- else:
- suite.addTest(doctest.DocTestSuite(mod))
- match = True
- if not match:
- print "No modules match \"%s\"" % submodname
- sys.exit(1)
-else:
- failed = False
- for modname,module in plugin.iter_plugins("libbe"):
- if not hasattr(module, "suite"):
+def python_tree(root_path='libbe', root_modname='libbe'):
+ tree = Tree()
+ tree.path = root_path
+ tree.parent = None
+ stack = [tree]
+ while len(stack) > 0:
+ f = stack.pop(0)
+ if f.path.endswith('.py'):
+ f.name = os.path.basename(f.path)[:-len('.py')]
+ elif os.path.isdir(f.path) \
+ and os.path.exists(os.path.join(f.path, '__init__.py')):
+ f.name = os.path.basename(f.path)
+ f.is_module = True
+ for child in os.listdir(f.path):
+ if child == '__init__.py':
+ continue
+ c = Tree()
+ c.path = os.path.join(f.path, child)
+ c.parent = f
+ stack.append(c)
+ else:
continue
- suite.addTest(module.suite)
- for modname,module in plugin.iter_plugins("becommands"):
- suite.addTest(doctest.DocTestSuite(module))
+ if f.parent == None:
+ f.modname = root_modname
+ else:
+ f.modname = f.parent.modname + '.' + f.name
+ f.parent.append(f)
+ return tree
-_vcs = vcs.installed_vcs()
-vcs.set_preferred_vcs(_vcs.name)
-print 'Using %s as the testing VCS' % _vcs.name
+def add_module_tests(suite, modname):
+ try:
+ mod = import_by_name(modname)
+ except ValueError, e:
+ print >> sys.stderr, 'Failed to import "%s"' % (modname)
+ raise e
+ if hasattr(mod, 'suite'):
+ s = mod.suite
+ else:
+ s = unittest.TestLoader().loadTestsFromModule(mod)
+ try:
+ sdoc = doctest.DocTestSuite(mod)
+ suite.addTest(sdoc)
+ except ValueError:
+ pass
+ suite.addTest(s)
+
+suite = unittest.TestSuite()
+tree = python_tree()
+if len(sys.argv) <= 1:
+ for node in tree.traverse():
+ add_module_tests(suite, node.modname)
+else:
+ added = []
+ for modname in sys.argv[1:]:
+ for node in tree.traverse():
+ if node.modname == modname:
+ for n in node.traverse():
+ if n.modname not in added:
+ add_module_tests(suite, n.modname)
+ added.append(n.modname)
+ break
result = unittest.TextTestRunner(verbosity=2).run(suite)