~ubuntu-branches/debian/sid/pyx/sid

« back to all changes in this revision

Viewing changes to debian/examples-testrunner

  • Committer: Package Import Robot
  • Author(s): Stuart Prescott
  • Date: 2014-05-31 18:25:57 UTC
  • Revision ID: package-import@ubuntu.com-20140531182557-ijnr0lq16gz9twaf
Tags: 0.12.1-3
* Update packaging to reflect that newer versions of pyx support only
  python 3 and that they are separately packaged in the pyx3 source package.
* Update package descriptions to highlight that this is the python 2 version
  of pyx.
* Disable watch file since this package is tracking the obsolete branch.
* Add autopkgtest tests.
* Update standards version to 3.9.5 (no changes required).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
#
 
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
 
6
 
 
7
from __future__ import print_function
 
8
 
 
9
import os.path
 
10
import shutil
 
11
import sys
 
12
import os
 
13
 
 
14
gs_args = ['-r400', '-dQUIET', '-dEPSCrop', '-dNOPAUSE', '-dBATCH', '-sDEVICE=ppmraw']
 
15
 
 
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)
 
20
 
 
21
    print(base, end=': ')
 
22
 
 
23
    name = {}
 
24
    for ft in ('eps', 'ppm', 'png'):
 
25
        name[ft] = "%s-%s.%s" % (base, interp, ft)
 
26
 
 
27
    if os.spawnlpe(os.P_WAIT, interp, interp, filename, new_env):
 
28
        print(interp + " FAILED")
 
29
        return
 
30
 
 
31
    if not os.path.exists(base + '.eps'):
 
32
        print("no EPS file")
 
33
        return
 
34
    else:
 
35
        os.rename(base + '.eps', name['eps'])
 
36
 
 
37
    gs_cmd = ['gs'] + gs_args + ['-sOutputFile=' + name['ppm'], name['eps']]
 
38
    if os.spawnvp(os.P_WAIT, 'gs', gs_cmd):
 
39
        print("gs FAILED")
 
40
        return
 
41
    os.unlink(name['eps'])
 
42
 
 
43
    convert_cmd = ['convert', '-resize', '25%', name['ppm'], name['png']]
 
44
    if os.spawnvp(os.P_WAIT, 'convert', convert_cmd):
 
45
        print("convert FAILED")
 
46
        return
 
47
    os.unlink(name['ppm'])
 
48
 
 
49
    print("ok")
 
50
    return name['png']
 
51
 
 
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")
 
55
    sys.exit(1)
 
56
 
 
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()
 
61
 
 
62
# Build a list of files to test.
 
63
def get_files(dir):
 
64
    r = []
 
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)
 
71
 
 
72
            if filename.endswith(".py"):
 
73
                r.append(full)
 
74
            elif filename.endswith(".dat") or filename.endswith(".jpg"):
 
75
                # The .dat and .jpg files are used by some of
 
76
                # the examples.
 
77
                shutil.copy(full, "output")
 
78
    return r
 
79
 
 
80
files = get_files("examples")
 
81
 
 
82
tests = 0
 
83
failed = 0
 
84
 
 
85
for f in files:
 
86
    tests += 1
 
87
    os.chdir(os.path.dirname(f))
 
88
    if not run_test("python", f):
 
89
        failed += 1
 
90
 
 
91
print(tests, "tests,", failed, "FAILED")
 
92
 
 
93
if failed:
 
94
    sys.exit(1)