Commit b26ccc00 authored by 's avatar

Implemented some fixes suggested by jim to avoid running non-PyUnit modules

that happen to match the naming convention.
parent 916c5be9
...@@ -16,8 +16,8 @@ conventions. Test modules should have a name prefixed with 'test', such as ...@@ -16,8 +16,8 @@ conventions. Test modules should have a name prefixed with 'test', such as
named 'test_suite' that returns a PyUnit TestSuite object. By convention, named 'test_suite' that returns a PyUnit TestSuite object. By convention,
we put test suites in 'tests' subdirectories of the packages they test. we put test suites in 'tests' subdirectories of the packages they test.
Testrunner is used to run all checked in test suites before releases are Testrunner is used to run all checked in test suites before (final) releases
made, and can be used to quickly run a particular suite or all suites in aremade, and can be used to quickly run a particular suite or all suites in
a particular directory.""" a particular directory."""
import sys, os, imp, string, getopt import sys, os, imp, string, getopt
...@@ -47,23 +47,6 @@ class TestRunner: ...@@ -47,23 +47,6 @@ class TestRunner:
import unittest import unittest
pyunit=unittest pyunit=unittest
# modules that would match, but are not (yet) PyUnit tests.
skip_names={'testrunner.py': None,
'test_logger.py': None,
'test_MultiMapping.py': None,
'test_Sync.py': None,
'test_ThreadLock.py': None,
'test_acquisition.py': None,
'test_add.py': None,
'test_binding.py': None,
'test_explicit_acquisition.py': None,
'test_func_attr.py': None,
'test_method_hook.py': None,
'test.py': None,
}
skip_name=skip_names.has_key
def getSuiteFromFile(self, filepath): def getSuiteFromFile(self, filepath):
if not os.path.isfile(filepath): if not os.path.isfile(filepath):
raise ValueError, '%s is not a file' % filepath raise ValueError, '%s is not a file' % filepath
...@@ -77,6 +60,15 @@ class TestRunner: ...@@ -77,6 +60,15 @@ class TestRunner:
return None return None
return function() return function()
def smellsLikeATest(self, filepath, find=string.find):
file=open(filepath, 'r')
lines=file.readlines()
file.close()
for line in lines:
if find(line, 'def test_suite(') > -1:
return 1
return 0
def runSuite(self, suite): def runSuite(self, suite):
runner=pyunit.TextTestRunner() runner=pyunit.TextTestRunner()
runner.run(suite) runner.run(suite)
...@@ -94,12 +86,12 @@ class TestRunner: ...@@ -94,12 +86,12 @@ class TestRunner:
"""Run all tests found in the directory named by pathname """Run all tests found in the directory named by pathname
and all subdirectories.""" and all subdirectories."""
names=os.listdir(pathname) names=os.listdir(pathname)
skip_name = self.skip_name
for name in names: for name in names:
fname, ext=os.path.splitext(name) fname, ext=os.path.splitext(name)
if name[:4]=='test' and name[-3:]=='.py' and \ if name[:4]=='test' and name[-3:]=='.py' and \
(not skip_name(name)): name != 'testrunner.py':
filepath=os.path.join(pathname, name) filepath=os.path.join(pathname, name)
if self.smellsLikeATest(filepath):
self.runFile(filepath) self.runFile(filepath)
for name in names: for name in names:
fullpath=os.path.join(pathname, name) fullpath=os.path.join(pathname, name)
...@@ -124,10 +116,12 @@ class TestRunner: ...@@ -124,10 +116,12 @@ class TestRunner:
def main(args): def main(args):
usage_msg="""Usage: python testrunner.py [options] usage_msg="""Usage: python testrunner.py options
If run without options, testrunner will run all test suites If run without options, testrunner will display this usage
found in all subdirectories of the current working directory. message. If you want to run all test suites found in all
subdirectories of the current working directory, use the
-a option.
options: options:
...@@ -146,14 +140,20 @@ def main(args): ...@@ -146,14 +140,20 @@ def main(args):
-f filepath -f filepath
Run the test suite found in the file specified. The filepath Run the test suite found in the file specified. The filepath
should be a fully qualified path to the file to be run.\n""" should be a fully qualified path to the file to be run.
-h
Display usage information.\n"""
pathname=None pathname=None
filename=None filename=None
test_all=None test_all=None
try: try:
options, arg=getopt.getopt(args, 'ad:f:') options, arg=getopt.getopt(args, 'ahd:f:')
if not options:
err_exit(usage_msg)
for name, value in options: for name, value in options:
name=name[1:] name=name[1:]
if name == 'a': if name == 'a':
...@@ -162,10 +162,11 @@ def main(args): ...@@ -162,10 +162,11 @@ def main(args):
pathname=string.strip(value) pathname=string.strip(value)
elif name == 'f': elif name == 'f':
filename=string.strip(value) filename=string.strip(value)
elif name == 'h':
err_exit(usage_msg)
else: else:
err_exit(usage_msg) err_exit(usage_msg)
if not options:
test_all=1
except: except:
err_exit(usage_msg) err_exit(usage_msg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment