3
# A simple test runner that runs all of thee example files shipped with PyX.
4
# Requires Ghostscript and ImageMagick.
5
# Note that test output should not be present prior to running the tests
7
from __future__ import print_function
14
gs_args = ['-r400', '-dQUIET', '-dEPSCrop', '-dNOPAUSE', '-dBATCH', '-sDEVICE=ppmraw']
16
def run_test(interp, filename):
17
"""Execute the example code and return the output filename."""
18
base, ext = os.path.splitext(filename)
19
base = os.path.basename(base)
24
for ft in ('eps', 'ppm', 'png'):
25
name[ft] = "%s-%s.%s" % (base, interp, ft)
27
if os.spawnlpe(os.P_WAIT, interp, interp, filename, new_env):
28
print(interp + " FAILED")
31
if not os.path.exists(base + '.eps'):
35
os.rename(base + '.eps', name['eps'])
37
gs_cmd = ['gs'] + gs_args + ['-sOutputFile=' + name['ppm'], name['eps']]
38
if os.spawnvp(os.P_WAIT, 'gs', gs_cmd):
41
os.unlink(name['eps'])
43
convert_cmd = ['convert', '-resize', '25%', name['ppm'], name['png']]
44
if os.spawnvp(os.P_WAIT, 'convert', convert_cmd):
45
print("convert FAILED")
47
os.unlink(name['ppm'])
52
# Are we in the correct directory?
53
if not os.path.exists("examples"):
54
print("must be in the toplevel directory of the PyX source")
57
# Set $PYTHONPATH so that we point to the correct location of the module.
58
new_env = os.environ.copy()
59
if "SYS_PYX" not in os.environ:
60
new_env["PYTHONPATH"] = os.getcwd()
62
# Build a list of files to test.
65
for (dirpath, dirnames, filenames) in os.walk(dir):
66
if ".svn" in dirnames:
67
dirnames.remove(".svn")
68
for filename in filenames:
69
full = os.path.join(dirpath, filename)
70
full = os.path.abspath(full)
72
if filename.endswith(".py"):
74
elif filename.endswith(".dat") or filename.endswith(".jpg"):
75
# The .dat and .jpg files are used by some of
77
shutil.copy(full, "output")
80
files = get_files("examples")
87
os.chdir(os.path.dirname(f))
88
if not run_test("python", f):
91
print(tests, "tests,", failed, "FAILED")