-from libbe import plugin
+"""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 with module name arguments, only run the doctests from
+those modules.
+"""
+
+import libbe
+libbe.TESTING = True
+from libbe import plugin, vcs
+import unittest
import doctest
import sys
+
+suite = unittest.TestSuite()
+
if len(sys.argv) > 1:
- match = False
- mod = plugin.get_plugin("libbe", sys.argv[1])
- if mod is not None:
- doctest.testmod(mod)
- match = True
- mod = plugin.get_plugin("becommands", sys.argv[1])
- if mod is not None:
- doctest.testmod(mod)
- match = True
- if not match:
- print "No modules match \"%s\"" % sys.argv[1]
-else:
- for module in plugin.iter_plugins("libbe"):
- doctest.testmod(module[1])
- for module in plugin.iter_plugins("becommands"):
- doctest.testmod(module[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"):
+ continue
+ suite.addTest(module.suite)
+ for modname,module in plugin.iter_plugins("becommands"):
+ suite.addTest(doctest.DocTestSuite(module))
+
+_vcs = vcs.installed_vcs()
+vcs.set_preferred_vcs(_vcs.name)
+print 'Using %s as the testing VCS' % _vcs.name
+
+result = unittest.TextTestRunner(verbosity=2).run(suite)
+
+numErrors = len(result.errors)
+numFailures = len(result.failures)
+numBad = numErrors + numFailures
+if numBad > 126:
+ numBad = 1
+sys.exit(numBad)