Skip to content

Commit bf8d938

Browse files
committed
Revamp py3test
* Make it look for a python3.4 binary in a few different places * Make it recommend running bin/install-python.sh if not found * Make test output clearer
1 parent a5185a2 commit bf8d938

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

py3test.py

+50-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.4
1+
#!/usr/bin/env python3
22

33
# Copyright 2018 The go-python Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style
@@ -15,37 +15,76 @@
1515
import os
1616
import sys
1717
from subprocess import Popen, PIPE, STDOUT
18+
from collections import defaultdict
1819

19-
testwith = ("python3.4", "gpython")
20+
py_version = "python3.4"
2021

21-
def runtests(dirpath, filenames):
22-
"""Run the tests found"""
22+
opt_install = "/opt/"+py_version
23+
24+
bin_dirs = os.environ["PATH"].split(os.pathsep) + [
25+
opt_install+"/bin",
26+
os.path.join(os.environ["HOME"], "bin/"+py_version+"/bin"),
27+
]
28+
29+
def find_python():
30+
"""Find a version of python to run"""
31+
for bin_dir in bin_dirs:
32+
path = os.path.join(bin_dir, py_version)
33+
if os.path.exists(path):
34+
return path
35+
print("Couldn't find "+py_version+" on $PATH or "+" or ".join(bin_dirs[-2:]))
36+
print("Install "+py_version+" by doing:")
37+
print(" sudo mkdir -p "+opt_install)
38+
print(" sudo chown $USER "+opt_install)
39+
print(" ./bin/install-python.sh "+opt_install+'"')
40+
sys.exit(1)
41+
42+
testwith = [find_python(), "gpython"]
43+
44+
def runtests(dirpath, filenames, failures):
45+
"""Run the tests found accumulating failures"""
2346
print("Running tests in %s" % dirpath)
2447
for name in filenames:
2548
if not name.endswith(".py") or name.startswith("lib") or name.startswith("raise"):
2649
continue
27-
print("Testing %s" % name)
50+
#print(" - %s" % name)
2851
fullpath = os.path.join(dirpath, name)
2952
for cmd in testwith:
3053
prog = [cmd, fullpath]
3154
p = Popen(prog, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
3255
stdout, stderr = p.communicate("")
3356
rc = p.returncode
3457
if rc != 0:
35-
print("*** %s %s Fail ***" % (cmd, fullpath))
36-
print("="*60)
37-
sys.stdout.write(stdout.decode("utf-8"))
38-
print("="*60)
39-
58+
failures[cmd][fullpath].append(stdout.decode("utf-8"))
59+
return failures
60+
4061
def main():
4162
binary = os.path.abspath(__file__)
4263
home = os.path.dirname(binary)
4364
os.chdir(home)
4465
print("Scanning %s for tests" % home)
4566

67+
failures = defaultdict(lambda: defaultdict(list))
4668
for dirpath, dirnames, filenames in os.walk("."):
4769
if os.path.basename(dirpath) == "tests":
48-
runtests(dirpath, filenames)
70+
runtests(dirpath, filenames, failures)
71+
72+
if not failures:
73+
print("All OK")
74+
return
75+
76+
print()
77+
78+
sep = "="*60+"\n"
79+
sep2 = "-"*60+"\n"
80+
81+
for cmd in sorted(failures.keys()):
82+
for path in sorted(failures[cmd].keys()):
83+
print(sep+"Failures for "+cmd+" in "+path)
84+
sys.stdout.write(sep+sep2.join(failures[cmd][path])+sep)
85+
print()
86+
sys.exit(1)
87+
4988

5089
if __name__ == "__main__":
5190
main()

0 commit comments

Comments
 (0)