[pypy-svn] r58362 - in pypy/build/testrunner: . test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Sep 23 10:03:01 CEST 2008
Author: pedronis
Date: Tue Sep 23 10:02:58 2008
New Revision: 58362
Modified:
pypy/build/testrunner/runner.py
pypy/build/testrunner/test/test_runner.py
Log:
(iko, pedronis)
- some more tests
- factor main code into main(args)
- logic to add to the log info about unexpected exits
Modified: pypy/build/testrunner/runner.py
==============================================================================
--- pypy/build/testrunner/runner.py (original)
+++ pypy/build/testrunner/runner.py Tue Sep 23 10:02:58 2008
@@ -26,6 +26,19 @@
exitcode = run(args, cwd, out)
return exitcode
+def interpret_exitcode(exitcode, test):
+ extralog = ""
+ if exitcode:
+ failure = True
+ if exitcode != 1:
+ if exitcode > 0:
+ msg = "Exit code %d." % exitcode
+ else:
+ msg = "Killed by %s." % getsignalname(-exitcode)
+ extralog = "! %s\n %s\n" % (test, msg)
+ else:
+ failure = False
+ return failure, extralog
def worker(num, n, run_param, testdirs, result_queue):
sessdir = run_param.sessdir
@@ -55,15 +68,12 @@
else:
logdata = ""
- if exitcode:
- failure = True
- if exitcode != 1:
- pass # xxx unexpected exit cases
- else:
- failure = False
+ failure, extralog = interpret_exitcode(exitcode, test)
- result_queue.put((failure, logdata, output))
+ if extralog:
+ logdata += extralog
+ result_queue.put((failure, logdata, output))
def start_workers(n, run_param, testdirs):
@@ -147,7 +157,7 @@
-if __name__ == '__main__':
+def main(args):
parser = optparse.OptionParser()
parser.add_option("--logfile", dest="logfile", default=None,
help="accumulated machine-readable logfile")
@@ -162,7 +172,7 @@
type="int",
help="number of parallel test runs")
- opts, args = parser.parse_args()
+ opts, args = parser.parse_args(args)
if opts.logfile is None:
print "no logfile specified"
@@ -178,7 +188,6 @@
testdirs = []
-
run_param = RunParam(root)
# the config files are python files whose run overrides the content
# of the run_param instance namespace
@@ -196,3 +205,7 @@
if res:
sys.exit(1)
+
+
+if __name__ == '__main__':
+ main(sys.argv)
Modified: pypy/build/testrunner/test/test_runner.py
==============================================================================
--- pypy/build/testrunner/test/test_runner.py (original)
+++ pypy/build/testrunner/test/test_runner.py Tue Sep 23 10:02:58 2008
@@ -46,6 +46,29 @@
test_driver=['driver', 'darg'])
assert res == -signal.SIGSEGV
+ def test_interpret_exitcode(self):
+ failure, extralog = runner.interpret_exitcode(0, "test_foo")
+ assert not failure
+ assert extralog == ""
+
+ failure, extralog = runner.interpret_exitcode(1, "test_foo")
+ assert failure
+ assert extralog == ""
+
+
+ failure, extralog = runner.interpret_exitcode(2, "test_foo")
+ assert failure
+ assert extralog == """! test_foo
+ Exit code 2.
+"""
+
+ failure, extralog = runner.interpret_exitcode(-signal.SIGSEGV,
+ "test_foo")
+ assert failure
+ assert extralog == """! test_foo
+ Killed by SIGSEGV.
+"""
+
class TestRunner(object):
@@ -53,22 +76,45 @@
def setup_class(cls):
cls.udir = py.path.local.make_numbered_dir(prefix='usession-runner-',
keep=3)
- cls.udir.join('test_normal').ensure(dir=1)
- for p in py.path.local(__file__).dirpath(
- 'examples', 'normal').listdir("*.py"):
- p.copy(cls.udir.join('test_normal', 'test_'+p.basename))
+
+ def fill_test_dir(test_dir):
+ for p in py.path.local(__file__).dirpath(
+ 'examples', 'normal').listdir("*.py"):
+ p.copy(test_dir.join('test_'+p.basename))
+
+
+ test_normal_dir0 = cls.udir.join('one', 'test_normal').ensure(dir=1)
+ cls.one_test_dir = cls.udir.join('one')
+
+ fill_test_dir(test_normal_dir0)
+
+
+ test_normal_dir1 = cls.udir.join('two', 'test_normal1').ensure(dir=1)
+ test_normal_dir2 = cls.udir.join('two', 'pkg',
+ 'test_normal2').ensure(dir=1)
+ cls.two_test_dir = cls.udir.join('two')
+
+ fill_test_dir(test_normal_dir1)
+ fill_test_dir(test_normal_dir2)
+
def teardown_class(cls):
pass
- def test_collect_testdirs_simple(self):
+ def test_collect_testdirs(self):
res = []
- run_param = runner.RunParam(self.udir)
+ run_param = runner.RunParam(self.one_test_dir)
run_param.collect_testdirs(res)
assert res == ['test_normal']
+
+ res = []
+ run_param = runner.RunParam(self.two_test_dir)
+ run_param.collect_testdirs(res)
+
+ assert sorted(res) == ['pkg/test_normal2', 'test_normal1']
def test_one_dir(self):
test_driver = [py.path.local(py.__file__).dirpath('bin', 'py.test')]
@@ -76,11 +122,11 @@
log = cStringIO.StringIO()
out = cStringIO.StringIO()
- param = runner.RunParam(self.udir)
- param.test_driver = test_driver
- param.parallel_runs = 3
+ run_param = runner.RunParam(self.one_test_dir)
+ run_param.test_driver = test_driver
+ run_param.parallel_runs = 3
- res = runner.execute_tests(param, ['test_normal'], log, out)
+ res = runner.execute_tests(run_param, ['test_normal'], log, out)
assert res
@@ -100,6 +146,39 @@
assert noutcomes == 107
assert nfailures == 6
- # xxx test with more than one dir
- # xxx test for main logic
+ def test_many_dirs(self):
+ test_driver = [py.path.local(py.__file__).dirpath('bin', 'py.test')]
+
+ log = cStringIO.StringIO()
+ out = cStringIO.StringIO()
+
+ run_param = runner.RunParam(self.udir)
+ run_param.test_driver = test_driver
+ run_param.parallel_runs = 3
+
+ testdirs = []
+ run_param.collect_testdirs(testdirs)
+
+ res = runner.execute_tests(run_param, testdirs, log, out)
+
+ assert res
+
+ assert out.getvalue()
+
+ log_lines = log.getvalue().splitlines()
+
+ nfailures = 0
+ noutcomes = 0
+ for line in log_lines:
+ if line[0] != ' ':
+ noutcomes += 1
+ if line[0] != '.':
+ nfailures += 1
+
+ assert noutcomes == 3*107
+ assert nfailures == 3*6
+
+
+
+
More information about the Pypy-commit
mailing list