1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#!/usr/bin/python2.3
# $Id: test 52 2004-12-25 06:05:40Z graham $
#
# A script for testing all of the example files shipped with PyX. Requires
# Ghostscript and ImageMagick.
import os.path
import shutil
import sys
import os
gs_args = ['-r400', '-dQUIET', '-dEPSCrop', '-dNOPAUSE', '-dBATCH', '-sDEVICE=ppmraw']
def run_test(interp, file):
"""Execute the example code and return the output filename."""
base, ext = os.path.splitext(file)
base = os.path.basename(base)
print base
name = {}
for ft in ('eps', 'ppm', 'png'):
name[ft] = "%s-%s.%s" % (base, interp, ft)
print " " + interp
if os.spawnlpe(os.P_WAIT, interp, interp, file, new_env):
print " " + interp + " FAILED"
return
if not os.path.exists(base + '.eps'):
print " no EPS file"
return
else:
os.rename(base + '.eps', name['eps'])
print " gs"
gs_cmd = ['gs'] + gs_args + ['-sOutputFile=' + name['ppm'], name['eps']]
if os.spawnvp(os.P_WAIT, 'gs', gs_cmd):
print " gs FAILED"
return
os.unlink(name['eps'])
print " convert"
convert_cmd = ['convert', '-resize', '50%', name['ppm'], name['png']]
if os.spawnvp(os.P_WAIT, 'convert', convert_cmd):
print " convert FAILED"
return
os.unlink(name['ppm'])
return name['png']
# Are we in the correct directory?
if not os.path.exists("debian/changelog") or not os.path.exists("examples"):
print "must be in the toplevel directory of the PyX source"
sys.exit(1)
# Set $PYTHONPATH so that we point to the correct location of the module.
new_env = os.environ.copy()
new_env["PYTHONPATH"] = os.getcwd()
# Setup a directory for output.
if not os.path.isdir("debian/output"):
os.mkdir("debian/output")
# Build a list of files to test.
files = []
for (dirpath, dirnames, filenames) in os.walk("examples"):
if ".svn" in dirnames:
dirnames.remove(".svn")
for file in filenames:
full = os.path.join(dirpath, file)
full = os.path.abspath(full)
if file.endswith(".py"):
files.append(full)
elif file.endswith(".dat"):
# The .dat files are used by some of the examples.
shutil.copy(full, "debian/output")
os.chdir("debian/output")
for file in files:
run_test("python2.2", file)
run_test("python2.3", file)
|