mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-05 04:50:09 +03:00
multiprocess --in progress
This commit is contained in:
parent
bcfc06d6d0
commit
4386c4edbb
155
Tests/run.py
155
Tests/run.py
|
@ -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,83 +15,109 @@ 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 = []
|
||||||
|
|
||||||
if "--installed" not in sys.argv:
|
|
||||||
os.environ["PYTHONPATH"] = "."
|
|
||||||
|
|
||||||
if "--coverage" in sys.argv:
|
|
||||||
tester_options.append("--coverage")
|
|
||||||
|
|
||||||
if "--log" in sys.argv:
|
|
||||||
tester_options.append("--log")
|
|
||||||
|
|
||||||
files = glob.glob(os.path.join(root, "test_*.py"))
|
|
||||||
files.sort()
|
|
||||||
|
|
||||||
success = failure = 0
|
|
||||||
include = [x for x in sys.argv[1:] if x[:2] != "--"]
|
include = [x for x in sys.argv[1:] if x[:2] != "--"]
|
||||||
skipped = []
|
|
||||||
|
|
||||||
python_options = " ".join(python_options)
|
def test_one(f):
|
||||||
tester_options = " ".join(tester_options)
|
test, ext = os.path.splitext(os.path.basename(f))
|
||||||
|
|
||||||
for file in files:
|
|
||||||
test, ext = os.path.splitext(os.path.basename(file))
|
|
||||||
if include and test not in include:
|
|
||||||
continue
|
|
||||||
print("running", test, "...")
|
print("running", test, "...")
|
||||||
# 2>&1 works on unix and on modern windowses. we might care about
|
# 2>&1 works on unix and on modern windowses. we might care about
|
||||||
# very old Python versions, but not ancient microsoft products :-)
|
# very old Python versions, but not ancient microsoft products :-)
|
||||||
out = os.popen("%s %s -u %s %s 2>&1" % (
|
out = os.popen("%s %s -u %s %s 2>&1" % (
|
||||||
sys.executable, python_options, file, tester_options
|
sys.executable, python_options, f, tester_options
|
||||||
))
|
))
|
||||||
result = out.read().strip()
|
result = out.read().strip()
|
||||||
if result == "ok":
|
|
||||||
result = None
|
|
||||||
elif result == "skip":
|
|
||||||
print("---", "skipped") # FIXME: driver should include a reason
|
|
||||||
skipped.append(test)
|
|
||||||
continue
|
|
||||||
elif not result:
|
|
||||||
result = "(no output)"
|
|
||||||
status = out.close()
|
status = out.close()
|
||||||
if status or result:
|
|
||||||
if status:
|
|
||||||
print("=== error", status)
|
|
||||||
if result:
|
|
||||||
if result[-3:] == "\nok":
|
|
||||||
# if there's an ok at the end, it's not really ok
|
|
||||||
result = result[:-3]
|
|
||||||
print(result)
|
|
||||||
failure = failure + 1
|
|
||||||
else:
|
|
||||||
success = success + 1
|
|
||||||
|
|
||||||
print("-"*68)
|
return (result, status)
|
||||||
|
|
||||||
temp_root = os.path.join(tempfile.gettempdir(), 'pillow-tests')
|
def filter_tests(files):
|
||||||
tempfiles = glob.glob(os.path.join(temp_root, "temp_*"))
|
ret = []
|
||||||
if tempfiles:
|
for f in files:
|
||||||
print("===", "remaining temporary files")
|
test, ext = os.path.splitext(os.path.basename(f))
|
||||||
for file in tempfiles:
|
if include and test not in include:
|
||||||
print(file)
|
continue
|
||||||
|
ret.append(f)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def main():
|
||||||
|
global python_options, tester_options
|
||||||
|
|
||||||
print("-"*68)
|
print("-"*68)
|
||||||
|
|
||||||
def tests(n):
|
if "--installed" not in sys.argv:
|
||||||
if n == 1:
|
os.environ["PYTHONPATH"] = "."
|
||||||
return "1 test"
|
|
||||||
else:
|
|
||||||
return "%d tests" % n
|
|
||||||
|
|
||||||
if skipped:
|
if "--coverage" in sys.argv:
|
||||||
print("---", tests(len(skipped)), "skipped.")
|
tester_options.append("--coverage")
|
||||||
print(skipped)
|
|
||||||
if failure:
|
if "--log" in sys.argv:
|
||||||
print("***", tests(failure), "of", (success + failure), "failed.")
|
tester_options.append("--log")
|
||||||
sys.exit(1)
|
|
||||||
else:
|
files = glob.glob(os.path.join(root, "test_*.py"))
|
||||||
print(tests(success), "passed.")
|
files.sort()
|
||||||
|
|
||||||
|
success = failure = 0
|
||||||
|
skipped = []
|
||||||
|
|
||||||
|
python_options = " ".join(python_options)
|
||||||
|
tester_options = " ".join(tester_options)
|
||||||
|
|
||||||
|
|
||||||
|
files = filter_tests(files)
|
||||||
|
|
||||||
|
print (files)
|
||||||
|
pool = Pool()
|
||||||
|
results = pool.map(test_one, files)
|
||||||
|
|
||||||
|
for test,(result, status) in zip(files,results):
|
||||||
|
if result == "ok":
|
||||||
|
result = None
|
||||||
|
elif result == "skip":
|
||||||
|
print("---", "skipped") # FIXME: driver should include a reason
|
||||||
|
skipped.append(test)
|
||||||
|
continue
|
||||||
|
elif not result:
|
||||||
|
result = "(no output)"
|
||||||
|
if status or result:
|
||||||
|
if status:
|
||||||
|
print("=== error", status)
|
||||||
|
if result:
|
||||||
|
if result[-3:] == "\nok":
|
||||||
|
# if there's an ok at the end, it's not really ok
|
||||||
|
result = result[:-3]
|
||||||
|
print(result)
|
||||||
|
failure = failure + 1
|
||||||
|
else:
|
||||||
|
success = success + 1
|
||||||
|
|
||||||
|
print("-"*68)
|
||||||
|
|
||||||
|
temp_root = os.path.join(tempfile.gettempdir(), 'pillow-tests')
|
||||||
|
tempfiles = glob.glob(os.path.join(temp_root, "temp_*"))
|
||||||
|
if tempfiles:
|
||||||
|
print("===", "remaining temporary files")
|
||||||
|
for file in tempfiles:
|
||||||
|
print(file)
|
||||||
|
print("-"*68)
|
||||||
|
|
||||||
|
def tests(n):
|
||||||
|
if n == 1:
|
||||||
|
return "1 test"
|
||||||
|
else:
|
||||||
|
return "%d tests" % n
|
||||||
|
|
||||||
|
if skipped:
|
||||||
|
print("---", tests(len(skipped)), "skipped.")
|
||||||
|
print(skipped)
|
||||||
|
if failure:
|
||||||
|
print("***", tests(failure), "of", (success + failure), "failed.")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print(tests(success), "passed.")
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
sys.exit(main())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user