multiprocess --in progress

This commit is contained in:
wiredfool 2014-01-28 12:21:05 -08:00
parent bcfc06d6d0
commit 4386c4edbb

View File

@ -3,6 +3,7 @@ from __future__ import print_function
# minimal test runner # minimal test runner
import glob, os, os.path, sys, tempfile import glob, os, os.path, sys, tempfile
from multiprocessing import Pool
try: try:
root = os.path.dirname(__file__) root = os.path.dirname(__file__)
@ -14,10 +15,36 @@ if not os.path.isfile("PIL/Image.py"):
print("***", "$ python Tests/run.py") print("***", "$ python Tests/run.py")
sys.exit(1) sys.exit(1)
print("-"*68)
python_options = [] python_options = []
tester_options = [] tester_options = []
include = [x for x in sys.argv[1:] if x[:2] != "--"]
def test_one(f):
test, ext = os.path.splitext(os.path.basename(f))
print("running", test, "...")
# 2>&1 works on unix and on modern windowses. we might care about
# very old Python versions, but not ancient microsoft products :-)
out = os.popen("%s %s -u %s %s 2>&1" % (
sys.executable, python_options, f, tester_options
))
result = out.read().strip()
status = out.close()
return (result, status)
def filter_tests(files):
ret = []
for f in files:
test, ext = os.path.splitext(os.path.basename(f))
if include and test not in include:
continue
ret.append(f)
return ret
def main():
global python_options, tester_options
print("-"*68)
if "--installed" not in sys.argv: if "--installed" not in sys.argv:
os.environ["PYTHONPATH"] = "." os.environ["PYTHONPATH"] = "."
@ -32,23 +59,19 @@ files = glob.glob(os.path.join(root, "test_*.py"))
files.sort() files.sort()
success = failure = 0 success = failure = 0
include = [x for x in sys.argv[1:] if x[:2] != "--"]
skipped = [] skipped = []
python_options = " ".join(python_options) python_options = " ".join(python_options)
tester_options = " ".join(tester_options) tester_options = " ".join(tester_options)
for file in files:
test, ext = os.path.splitext(os.path.basename(file)) files = filter_tests(files)
if include and test not in include:
continue print (files)
print("running", test, "...") pool = Pool()
# 2>&1 works on unix and on modern windowses. we might care about results = pool.map(test_one, files)
# very old Python versions, but not ancient microsoft products :-)
out = os.popen("%s %s -u %s %s 2>&1" % ( for test,(result, status) in zip(files,results):
sys.executable, python_options, file, tester_options
))
result = out.read().strip()
if result == "ok": if result == "ok":
result = None result = None
elif result == "skip": elif result == "skip":
@ -57,7 +80,6 @@ for file in files:
continue continue
elif not result: elif not result:
result = "(no output)" result = "(no output)"
status = out.close()
if status or result: if status or result:
if status: if status:
print("=== error", status) print("=== error", status)
@ -94,3 +116,8 @@ if failure:
sys.exit(1) sys.exit(1)
else: else:
print(tests(success), "passed.") print(tests(success), "passed.")
return 0
if __name__=='__main__':
sys.exit(main())