[pypy-commit] pypy refine-testrunner: testrunner: refactor runner parameter usage
RonnyPfannschmidt
noreply at buildbot.pypy.org
Sun Jul 1 17:56:13 CEST 2012
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch: refine-testrunner
Changeset: r55886:9fe10c51dd55
Date: 2012-07-01 17:50 +0200
http://bitbucket.org/pypy/pypy/changeset/9fe10c51dd55/
Log: testrunner: refactor runner parameter usage
diff --git a/testrunner/runner.py b/testrunner/runner.py
--- a/testrunner/runner.py
+++ b/testrunner/runner.py
@@ -40,7 +40,7 @@
root = run_param.root
test_driver = run_param.test_driver
interp = run_param.interp
- dry_run = run_param.dry_run
+ runfunc = run_param.runfunc
timeout = run_param.timeout
cleanup = run_param.cleanup
# xxx cfg thread start
@@ -56,15 +56,10 @@
one_output = sessdir.join("%d-%s-output" % (num, basename))
num += n
- if dry_run:
- runfunc = util.dry_run
- else:
- runfunc = util.run
try:
exitcode = execute_test(root, test, one_output, logfname,
interp, test_driver, runfunc=runfunc,
timeout=timeout)
-
cleanup(test)
except:
print "execute-test for %r failed with:" % test
@@ -98,7 +93,7 @@
return result_queue
-def execute_tests(run_param, testdirs, logfile, out):
+def execute_tests(run_param, testdirs, logfile):
sessdir = py.path.local.make_numbered_dir(prefix='usession-testrunner-',
keep=4)
run_param.sessdir = sessdir
@@ -107,8 +102,8 @@
failure = False
for testname in testdirs:
- out.write("-- %s\n" % testname)
- out.write("-- total: %d to run\n" % len(testdirs))
+ run_param.log("-- %s", testname)
+ run_param.log("-- total: %d to run", len(testdirs))
result_queue = start_workers(N, run_param, testdirs)
@@ -126,8 +121,8 @@
if res[0] == 'start':
started += 1
- out.write("++ starting %s [%d started in total]\n" % (res[1],
- started))
+ run_param.log("++ starting %s [%d started in total]",
+ res[1], started)
continue
testname, somefailed, logdata, output = res[1:]
@@ -136,9 +131,9 @@
heading = "__ %s [%d done in total] " % (testname, done)
- out.write(heading + (79-len(heading))*'_'+'\n')
+ run_param.log(heading.ljust(79, '_'))
- out.write(output)
+ run_param.log(output.rstrip())
if logdata:
logfile.write(logdata)
@@ -146,20 +141,44 @@
class RunParam(object):
- dry_run = False
- interp = [os.path.abspath(sys.executable)]
+ run = staticmethod(util.run)
+ dry_run = staticmethod(util.dry_run)
+
pytestpath = os.path.abspath(os.path.join('py', 'bin', 'py.test'))
if not os.path.exists(pytestpath):
pytestpath = os.path.abspath(os.path.join('pytest.py'))
assert os.path.exists(pytestpath)
test_driver = [pytestpath]
- parallel_runs = 1
- timeout = None
cherrypick = None
- def __init__(self, opts):
- self.root = py.path.local(opts.root)
+ def __init__(self, root, out):
+ self.root = root
+ self.out = out
+ self.interp = [os.path.abspath(sys.executable)]
+ self.runfunc = self.run
+ self.parallel_runs = 1
+ self.timeout = None
+ self.cherrypick = None
+
+ @classmethod
+ def from_options(cls, opts, out):
+ root = py.path.local(opts.root)
+
+ self = cls(root, out)
+
+ self.parallel_runs = opts.parallel_runs
+ self.timeout = opts.timeout
+
+ if opts.dry_run:
+ self.runfunc = self.dry_run
+ else:
+ self.runfunc = self.run
+ return self
+
+
+ def log(self, fmt, *args):
+ self.out.write((fmt % args) + '\n')
def is_test_py_file(self, p):
name = p.basename
@@ -173,6 +192,10 @@
testdirs.append(reldir)
return
+ def cleanup(self, test):
+ # used for test_collect_testdirs
+ pass
+
def collect_testdirs(self, testdirs, p=None):
if p is None:
p = self.root
@@ -193,9 +216,6 @@
if p1.check(dir=1, link=0):
self.collect_testdirs(testdirs, p1)
- def cleanup(self, testdir):
- pass
-
def main(opts, args):
@@ -212,7 +232,7 @@
testdirs = []
- run_param = RunParam(opts)
+ run_param = RunParam.from_options(opts, out)
# the config files are python files whose run overrides the content
# of the run_param instance namespace
# in that code function overriding method should not take self
@@ -220,7 +240,7 @@
for config_py_file in opts.config:
config_py_file = os.path.expanduser(config_py_file)
if py.path.local(config_py_file).check(file=1):
- print >>out, "using config", config_py_file
+ run_param.log("using config %s", config_py_file)
execfile(config_py_file, run_param.__dict__)
if run_param.cherrypick:
@@ -229,16 +249,11 @@
else:
run_param.collect_testdirs(testdirs)
- if opts.parallel_runs:
- run_param.parallel_runs = opts.parallel_runs
- if opts.timeout:
- run_param.timeout = opts.timeout
- run_param.dry_run = opts.dry_run
if opts.dry_run:
- print >>out, run_param.__dict__
+ run_param.log("%s", run_param.__dict__)
- res = execute_tests(run_param, testdirs, logfile, out)
+ res = execute_tests(run_param, testdirs, logfile)
if res:
sys.exit(1)
diff --git a/testrunner/test/test_runner.py b/testrunner/test/test_runner.py
--- a/testrunner/test/test_runner.py
+++ b/testrunner/test/test_runner.py
@@ -120,11 +120,11 @@
log = cStringIO.StringIO()
out = cStringIO.StringIO()
- run_param = runner.RunParam(self.one_test_dir)
+ run_param = runner.RunParam(self.one_test_dir,out)
run_param.test_driver = test_driver
run_param.parallel_runs = 3
- res = runner.execute_tests(run_param, ['test_normal'], log, out)
+ res = runner.execute_tests(run_param, ['test_normal'], log)
assert res
@@ -156,12 +156,12 @@
log = cStringIO.StringIO()
out = cStringIO.StringIO()
- run_param = runner.RunParam(self.one_test_dir)
+ run_param = runner.RunParam(self.one_test_dir, out)
run_param.test_driver = test_driver
run_param.parallel_runs = 3
- run_param.dry_run = True
+ run_param.runfunc = run_param.dry_run
- res = runner.execute_tests(run_param, ['test_normal'], log, out)
+ res = runner.execute_tests(run_param, ['test_normal'], log)
assert not res
@@ -186,7 +186,7 @@
def cleanup(testdir):
cleanedup.append(testdir)
- run_param = runner.RunParam(self.manydir)
+ run_param = runner.RunParam(self.manydir, out)
run_param.test_driver = test_driver
run_param.parallel_runs = 3
run_param.cleanup = cleanup
@@ -195,7 +195,7 @@
run_param.collect_testdirs(testdirs)
alltestdirs = testdirs[:]
- res = runner.execute_tests(run_param, testdirs, log, out)
+ res = runner.execute_tests(run_param, testdirs, log)
assert res
@@ -220,16 +220,15 @@
test_driver = [pytest_script]
log = cStringIO.StringIO()
- out = cStringIO.StringIO()
- run_param = runner.RunParam(self.test_stall_dir)
+ run_param = runner.RunParam(self.test_stall_dir, sys.stdout)
run_param.test_driver = test_driver
run_param.parallel_runs = 3
run_param.timeout = 3
testdirs = []
run_param.collect_testdirs(testdirs)
- res = runner.execute_tests(run_param, testdirs, log, out)
+ res = runner.execute_tests(run_param, testdirs, log)
assert res
log_lines = log.getvalue().splitlines()
@@ -237,40 +236,19 @@
def test_run_wrong_interp(self):
log = cStringIO.StringIO()
- out = cStringIO.StringIO()
- run_param = runner.RunParam(self.one_test_dir)
+ run_param = runner.RunParam(self.one_test_dir, sys.stdout)
run_param.interp = ['wrong-interp']
run_param.parallel_runs = 3
testdirs = []
run_param.collect_testdirs(testdirs)
- res = runner.execute_tests(run_param, testdirs, log, out)
+ res = runner.execute_tests(run_param, testdirs, log)
assert res
log_lines = log.getvalue().splitlines()
assert log_lines[1] == ' Failed to run interp'
- def test_run_bad_get_test_driver(self):
- test_driver = [pytest_script]
-
- log = cStringIO.StringIO()
- out = cStringIO.StringIO()
-
- run_param = runner.RunParam(self.one_test_dir)
- run_param.parallel_runs = 3
- def boom(testdir):
- raise RuntimeError("Boom")
- run_param.get_test_driver = boom
-
- testdirs = []
- run_param.collect_testdirs(testdirs)
- res = runner.execute_tests(run_param, testdirs, log, out)
- assert res
-
- log_lines = log.getvalue().splitlines()
- assert log_lines[1] == ' Failed with exception in execute-test'
-
class TestRunnerNoThreads(RunnerTests):
with_thread = False
@@ -278,7 +256,7 @@
def test_collect_testdirs(self):
res = []
seen = []
- run_param = runner.RunParam(self.one_test_dir)
+ run_param = runner.RunParam(self.one_test_dir, sys.stdout)
real_collect_one_testdir = run_param.collect_one_testdir
def witness_collect_one_testdir(testdirs, reldir, tests):
@@ -298,7 +276,7 @@
run_param.collect_one_testdir = real_collect_one_testdir
res = []
- run_param = runner.RunParam(self.two_test_dir)
+ run_param = runner.RunParam(self.two_test_dir, sys.stdout)
run_param.collect_testdirs(res)
diff --git a/testrunner/util.py b/testrunner/util.py
--- a/testrunner/util.py
+++ b/testrunner/util.py
@@ -15,7 +15,7 @@
help="configuration python file (optional)")
parser.add_option("--root", dest="root", default=".",
help="root directory for the run")
-parser.add_option("--parallel-runs", dest="parallel_runs", default=0,
+parser.add_option("--parallel-runs", dest="parallel_runs", default=1,
type="int",
help="number of parallel test runs")
parser.add_option("--dry-run", dest="dry_run", default=False,
More information about the pypy-commit
mailing list