Commit c0650562 authored by Denis Bilenko's avatar Denis Bilenko

re-use testrunner code in test___monkey_patching

parent 0203a083
......@@ -2,15 +2,14 @@ import sys
import os
import glob
import util
import gevent
TIMEOUT = 120
directory = '%s.%s' % sys.version_info[:2]
version = '%s.%s.%s' % sys.version_info[:3]
def TESTRUNNER(tests=None):
directory = '%s.%s' % sys.version_info[:2]
version = '%s.%s.%s' % sys.version_info[:3]
preferred_version = open(os.path.join(directory, 'version')).read().strip()
if preferred_version != version:
util.log('WARNING: The tests in %s/ are from version %s and your Python is %s', directory, preferred_version, version)
......@@ -18,9 +17,6 @@ def TESTRUNNER(tests=None):
env = os.environ.copy()
env['PYTHONPATH'] = os.getcwd() + ':' + os.environ.get('PYTHONPATH', '')
for filename in glob.glob('%s/@test_*_tmp' % directory):
os.unlink(filename)
if not tests:
tests = sorted(glob.glob('%s/test_*.py' % directory))
......@@ -33,21 +29,8 @@ def TESTRUNNER(tests=None):
def main():
from testrunner import pool
import time
failed = []
def run(name, cmd, **kwargs):
if util.run(cmd, **kwargs):
failed.append(name)
start = time.time()
total = 0
for name, cmd, options in TESTRUNNER(sys.argv[1:]):
total += 1
pool.spawn(run, name, cmd, **options)
gevent.run()
util.report(total, failed, took=time.time() - start)
import testrunner
return testrunner.run_many(TESTRUNNER())
if __name__ == '__main__':
......
......@@ -33,17 +33,13 @@ def spawn(*args, **kwargs):
return g
def main():
def run_many(tests):
global NWORKERS, pool
start = time.time()
total = 0
failed = {}
tests = sys.argv[1:]
if not tests:
tests = set(glob.glob('test_*.py')) - set(['test_support.py'])
tests = sorted(tests)
tests = list(tests)
NWORKERS = min(len(tests), NWORKERS)
pool = Pool(NWORKERS)
util.BUFFER_OUTPUT = NWORKERS > 1
......@@ -61,17 +57,9 @@ def main():
try:
try:
for filename in tests:
for name, cmd, options in tests:
total += 1
if 'TESTRUNNER' in open(filename).read():
module = __import__(filename.rsplit('.', 1)[0])
for name, cmd, options in module.TESTRUNNER():
total += 1
name = filename + ' ' + name
spawn(run_one, name, cmd, **options).name = ' '.join(cmd)
else:
cmd = [sys.executable, '-u', filename]
spawn(run_one, filename, cmd, timeout=TIMEOUT).name = ' '.join(cmd)
spawn(run_one, name, cmd, **options).name = ' '.join(cmd)
gevent.run()
except KeyboardInterrupt:
try:
......@@ -103,6 +91,31 @@ def main():
util.log('- ' + '\n- '.join(failed_then_succeeded))
assert not pool, pool
os.system('rm -f */@test*_tmp')
def discover(tests):
if not tests:
tests = set(glob.glob('test_*.py')) - set(['test_support.py'])
tests = sorted(tests)
to_process = []
default_options = {'timeout': TIMEOUT}
for filename in tests:
if 'TESTRUNNER' in open(filename).read():
module = __import__(filename.rsplit('.', 1)[0])
for name, cmd, options in module.TESTRUNNER():
to_process.append((filename + ' ' + name, cmd, options))
else:
to_process.append((filename, [sys.executable, '-u', filename], default_options))
return to_process
def main():
run_many(discover(sys.argv[1:]))
if __name__ == '__main__':
main()
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