[Zodb-checkins] CVS: StandaloneZODB - test.py:1.13
Jeremy Hylton
jeremy@zope.com
Thu, 7 Mar 2002 21:08:07 -0500
Update of /cvs-repository/StandaloneZODB
In directory cvs.zope.org:/tmp/cvs-serv4111
Modified Files:
test.py
Log Message:
Add testcase filter
=== StandaloneZODB/test.py 1.12 => 1.13 ===
return None
-def runner(files, debug):
+def match(rx, s):
+ if not rx:
+ return 1
+ if rx[0] == '!':
+ return re.search(rx[1:], s) is None
+ else:
+ return re.search(rx, s) is not None
+
+def filter_testcases(s, rx):
+ new = unittest.TestSuite()
+ for test in s._tests:
+ if isinstance(test, unittest.TestCase):
+ name = test.id() # Full test name: package.module.class.method
+ name = name[1 + name.rfind('.'):] # extract method name
+ if match(rx, name):
+ new.addTest(test)
+ else:
+ filtered = filter_testcases(test, rx)
+ if filtered:
+ new.addTest(filtered)
+ return new
+
+def runner(files, test_filter, debug):
runner = ImmediateTestRunner(verbosity=VERBOSE)
suite = unittest.TestSuite()
for file in files:
s = get_suite(file)
if s is not None:
+ if test_filter is not None:
+ s = filter_testcases(s, test_filter)
suite.addTest(s)
if debug:
suite.debug()
@@ -136,29 +160,36 @@
r = runner.run(suite)
return len(r.errors) + len(r.failures)
-def main(filter=None):
+def main(module_filter, test_filter):
setup_path()
- files = find_tests(filter)
+ files = find_tests(module_filter)
files.sort()
os.chdir("build")
if LOOP:
while 1:
- runner(files, debug)
+ runner(files, test_filter, debug)
else:
- runner(files, debug)
+ runner(files, test_filter, debug)
if __name__ == "__main__":
import getopt
- filter = None
+ module_filter = None
+ test_filter = None
VERBOSE = 0
LOOP = 0
debug = 0 # Don't collect test results; simply let tests crash
build = 0
- opts, args = getopt.getopt(sys.argv[1:], 'vdLb')
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], 'vdLbh')
+ except getopt.error, msg:
+ print msg
+ print "Try `python %s -h' for more information." % sys.argv[0]
+ sys.exit(2)
+
for k, v in opts:
if k == '-v':
VERBOSE = VERBOSE + 1
@@ -168,6 +199,9 @@
LOOP = 1
elif k == '-b':
build = 1
+ elif k == '-h':
+ print __doc__
+ sys.exit(0)
if build:
cmd = sys.executable + " setup.py -q build"
@@ -179,9 +213,11 @@
sys.exit(1)
if args:
- filter = args[0]
+ if len(args) > 1:
+ test_filter = args[1]
+ module_filter = args[0]
try:
- bad = main(filter)
+ bad = main(module_filter, test_filter)
if bad:
sys.exit(1)
except ImportError, err: