File: test

package info (click to toggle)
pyx 0.11.1-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 3,468 kB
  • sloc: python: 18,575; ansic: 99; makefile: 91; sh: 9
file content (92 lines) | stat: -rw-r--r-- 2,358 bytes parent folder | download | duplicates (4)
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
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python2.3
# $Id: test 92 2006-06-11 05:12:16Z 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)

	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'])

	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'])

	convert_cmd = ['convert', '-resize', '25%', name['ppm'], name['png']]
	if os.spawnvp(os.P_WAIT, 'convert', convert_cmd):
		print "convert FAILED"
		return
	os.unlink(name['ppm'])

	print "ok"
	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()
if not os.environ.has_key("SYS_PYX"):
	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.
def get_files(dir):
	r = []
	for (dirpath, dirnames, filenames) in os.walk(dir):
		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"):
				r.append(full)
			elif file.endswith(".dat") or file.endswith(".jpg"):
				# The .dat and .jpg files are used by some of
				# the examples.
				shutil.copy(full, "debian/output")
	return r

files = get_files("examples")
files += get_files("gallery")

os.chdir("debian/output")
tests = 0
failed = 0
for file in files:
	tests += 1
	if not run_test("python", file):
		failed += 1

print tests, "tests,", failed, "FAILED"