File: run_test.py

package info (click to toggle)
ipe-tools 1%3A7.2.29.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 880 kB
  • sloc: cpp: 2,719; python: 2,122; ansic: 1,052; sh: 224; makefile: 94; xml: 39
file content (55 lines) | stat: -rw-r--r-- 1,494 bytes parent folder | download | duplicates (5)
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
#
# Run all the tests in tests subdirectory
# and save plots in ipe and svg format
# 
from __future__ import division, print_function, unicode_literals

import os, sys

def fix_file(f):
  data = open("tests/%s" % f, "r").readlines()
  os.rename("tests/%s" % f, "tests/%s.bak" % f)
  out = open("tests/%s" % f, "w")
  for l in data:
    ll = l.strip()
    if ll == "import matplotlib as mpl": continue
    if ll == "print mpl.__file__": continue
    if ll == "mpl.use('module://backend_ipe')": continue
    if ll == "#mpl.use('module://backend_ipe')": continue    
    if ll == "#plt.show()" or ll == "plt.show()": continue
    if ll[:12] == "#plt.savefig": continue
    if ll[:11] == "plt.savefig": continue
    out.write(l)
  out.close()

def runall(form):
  tests = [f[:-3] for f in os.listdir("tests") if f[-3:] == ".py"]
  for f in tests:
    # doesn't work on my matplotlib version
    if f == "power_norm_demo": continue
    run(form, f)

def run(form, f):
  sys.stderr.write("# %s\n" % f)
  t = open("tmp.py", "w")
  t.write("""# %s
import matplotlib as mpl
""" % f)
  if form=="ipe":
    t.write("mpl.use('module://backend_ipe')\n")
  t.write(open("tests/%s.py" % f, "r").read())
  t.write("plt.savefig('out/%s.%s', format='%s')\n" % (f, form, form))
  t.close()
  os.system("python tmp.py")

if len(sys.argv) != 3:
  sys.stderr.write("Usage: run_test.py <format> <test>\n")
  sys.exit(9)

form = sys.argv[1]
test = sys.argv[2]
if test == 'all':
  runall(form)
else:
  run(form, test)