1 |
< |
#!/usr/local/bin/python |
1 |
> |
#!/usr/bin/env python |
2 |
> |
# -*- coding: utf-8 -*- |
3 |
> |
''' run_tests.py - Run Radiance test suite |
4 |
> |
2013 - 2016 Georg Mischler |
5 |
|
|
6 |
+ |
Invocation: |
7 |
+ |
As script, call with -H for instructions. |
8 |
+ |
As module, see docstrings in class RadianceTests for instructions. |
9 |
+ |
''' |
10 |
+ |
from __future__ import division, print_function, unicode_literals |
11 |
+ |
__all__ = ['TESTCATS', 'RadianceTests', 'main'] |
12 |
+ |
import os |
13 |
|
import sys |
14 |
+ |
import types |
15 |
+ |
import argparse |
16 |
+ |
import unittest |
17 |
|
|
18 |
< |
cal_units = [ |
19 |
< |
'test_calc', |
7 |
< |
'test_cnt', |
8 |
< |
'test_ev', |
9 |
< |
'test_histo', |
10 |
< |
'test_lam', |
11 |
< |
'test_neat', |
12 |
< |
'test_rcalc', |
13 |
< |
'test_tabfunc', |
14 |
< |
'test_total', |
15 |
< |
] |
18 |
> |
SHORTPROGN = os.path.splitext(os.path.basename(sys.argv[0]))[0] |
19 |
> |
TESTCATS = ('cal','cv','gen','hd','meta','ot','px', 'rt','util',) |
20 |
|
|
21 |
< |
cv_units = [ |
18 |
< |
'test_3ds2mgf', |
19 |
< |
'test_arch2rad', |
20 |
< |
'test_ies2rad', |
21 |
< |
'test_lampcolor', |
22 |
< |
'test_mgf2inv', |
23 |
< |
'test_mgf2rad', |
24 |
< |
'test_nff2rad', |
25 |
< |
'test_obj2rad', |
26 |
< |
'test_thf2rad', |
27 |
< |
'test_tmesh2rad', |
28 |
< |
'test_rad2mgf', |
29 |
< |
'test_mgf2meta', |
30 |
< |
'test_mgfilt', |
31 |
< |
] |
21 |
> |
class Error(Exception): pass |
22 |
|
|
23 |
< |
gen_units = [ |
24 |
< |
'test_genbeads', |
35 |
< |
'test_genblinds', |
36 |
< |
'test_genbox', |
37 |
< |
'test_genbranch', |
38 |
< |
'test_gencat', |
39 |
< |
'test_genclock', |
40 |
< |
'test_genmarble', |
41 |
< |
'test_genprism', |
42 |
< |
'test_genrev', |
43 |
< |
'test_gensky', |
44 |
< |
'test_gensurf', |
45 |
< |
'test_genworm', |
46 |
< |
'test_replmarks', |
47 |
< |
'test_mkillum', |
48 |
< |
'test_xform', |
49 |
< |
] |
23 |
> |
class RadianceTests(): |
24 |
> |
'''Test Radiance programs below subdirectory "testcases" recursively. |
25 |
|
|
26 |
< |
hd_units = [ |
27 |
< |
'test_rhcopy', |
53 |
< |
'test_rhinfo', |
54 |
< |
'test_rholo', |
55 |
< |
'test_rhpict', |
56 |
< |
#'test_genrhenv', |
57 |
< |
'test_genrhgrid', |
58 |
< |
# XXX device drivers? |
59 |
< |
] |
26 |
> |
This class will create a virtual module "testsupport" with constants |
27 |
> |
and functions for use in individual test cases. |
28 |
|
|
29 |
< |
meta_units = [ |
30 |
< |
'test_cv', |
31 |
< |
'test_meta2tga', |
32 |
< |
'test_pexpand', |
33 |
< |
'test_plot4', |
34 |
< |
'test_plotin', |
35 |
< |
'test_psort', |
36 |
< |
'test_psmeta', |
37 |
< |
'test_gcomp', |
38 |
< |
'test_bgraph', |
39 |
< |
'test_dgraph', |
40 |
< |
'test_igraph', |
41 |
< |
#'test_x11meta', |
42 |
< |
] |
29 |
> |
testsupport.bindir - list of paths added to PATH |
30 |
> |
testsupport.path - complete list of paths currently in PATH |
31 |
> |
testsupport.radlib - list of paths added to RAYPATH |
32 |
> |
testsupport.raypath - complete list of paths currently in RAYPATH |
33 |
> |
testsupport.pyradlib - absolute path of python support library directory |
34 |
> |
testsupport.datadir - absolute path of test data directory |
35 |
> |
testsupport.datafile([sub, [sub,]] fn) - return absolute file path in |
36 |
> |
data directory or in a subdirectory |
37 |
> |
''' |
38 |
> |
def __init__(self, **args): |
39 |
> |
'''Args are: |
40 |
> |
bindir=[directory ...] - will be prepended to PATH for tests |
41 |
> |
radlib=[directory ...] - will be prepended to RAYPATH for tests |
42 |
> |
cat=[category ...] - only test those categories (else TESTCATS) |
43 |
> |
V=False - if True, verbose listing of executed tests |
44 |
> |
''' |
45 |
> |
self.bindir = args.get('bindir') |
46 |
> |
self.radlib = args.get('radlib') |
47 |
> |
self.testcats = args.get('cat') |
48 |
> |
self.V = 2 if args.get('V') else 1 |
49 |
> |
try: |
50 |
> |
old_osenv = os.environ |
51 |
|
|
52 |
< |
meta_special_units = [ |
53 |
< |
'test_mt160', |
54 |
< |
'test_mt160l', |
55 |
< |
'test_mtext', |
56 |
< |
'test_okimate', |
57 |
< |
'test_mx80', |
82 |
< |
'test_imagew', |
83 |
< |
'test_impress', |
84 |
< |
'test_aed5', |
85 |
< |
'test_tcurve', |
86 |
< |
'test_tbar', |
87 |
< |
'test_tscat', |
88 |
< |
'test_plotout', |
89 |
< |
] |
52 |
> |
thisfile = os.path.abspath(__file__) |
53 |
> |
self.thisdir = os.path.split(thisfile)[0] |
54 |
> |
self.testdir = os.path.join(self.thisdir, 'testcases') |
55 |
> |
old_syspath = sys.path |
56 |
> |
if self.testdir not in sys.path: |
57 |
> |
sys.path.insert(0, self.testdir) |
58 |
|
|
59 |
< |
ot_units = [ |
60 |
< |
'test_oconv', |
61 |
< |
'test_getbbox', |
62 |
< |
'test_obj2mesh', |
63 |
< |
] |
59 |
> |
oldpath = old_osenv.get('PATH', '') |
60 |
> |
pathlist = oldpath.split(os.pathsep) |
61 |
> |
if self.bindir: |
62 |
> |
for bdir in self.bindir: |
63 |
> |
if bdir not in pathlist: |
64 |
> |
pathlist.insert(0, bdir) |
65 |
> |
os.environ['PATH'] = os.pathsep.join(pathlist) |
66 |
|
|
67 |
< |
px_units = [ |
68 |
< |
'test_macbethcal', |
69 |
< |
'test_normtiff', |
70 |
< |
'test_oki20', |
71 |
< |
'test_oki20c', |
72 |
< |
'test_pcomb', |
73 |
< |
'test_pcompos', |
104 |
< |
'test_pcond', |
105 |
< |
'test_pcwarp', |
106 |
< |
'test_pextrem', |
107 |
< |
'test_pfilt', |
108 |
< |
'test_pflip', |
109 |
< |
'test_pinterp', |
110 |
< |
'test_protate', |
111 |
< |
'test_psign', |
112 |
< |
'test_pvalue', |
113 |
< |
'test_ra_avs', |
114 |
< |
'test_ra_bn', |
115 |
< |
'test_ra_gif', |
116 |
< |
'test_ra_hexbit', |
117 |
< |
'test_ra_pict', |
118 |
< |
'test_ra_ppm', |
119 |
< |
'test_ra_pr', |
120 |
< |
'test_ra_pr24', |
121 |
< |
'test_ra_ps', |
122 |
< |
'test_ra_rgbe', |
123 |
< |
'test_ra_t16', |
124 |
< |
'test_ra_t8', |
125 |
< |
'test_ra_xyze', |
126 |
< |
'test_ra_tiff', |
127 |
< |
'test_t4027', |
128 |
< |
'test_ttyimage', |
129 |
< |
#'test_ximage', |
130 |
< |
#'test_xshowtrace', |
131 |
< |
] |
67 |
> |
oldraypath = old_osenv.get('RAYPATH', '') |
68 |
> |
raypathlist = oldraypath.split(os.pathsep) |
69 |
> |
if self.radlib: |
70 |
> |
for rlib in self.radlib: |
71 |
> |
if rlib not in raypathlist: |
72 |
> |
raypathlist.insert(0, rlib) |
73 |
> |
os.environ['RAYPATH'] = os.pathsep.join(raypathlist) |
74 |
|
|
75 |
< |
px_special_units = [ |
76 |
< |
'test_ra_im', |
77 |
< |
'test_psum', |
78 |
< |
'test_t4014', |
79 |
< |
'test_paintjet', |
80 |
< |
'test_mt160r', |
81 |
< |
'test_greyscale', |
82 |
< |
'test_colorscale', |
83 |
< |
'test_d48c', |
84 |
< |
] |
75 |
> |
pyradlib = None |
76 |
> |
for rp in raypathlist: |
77 |
> |
prd = os.path.join(rp, 'pyradlib') |
78 |
> |
#print(prd) |
79 |
> |
if os.path.isdir(prd) or os.path.islink(prd): |
80 |
> |
#print('--- found !!!') |
81 |
> |
if rp not in sys.path: |
82 |
> |
sys.path.insert(0, rp) |
83 |
> |
pyradlib = prd |
84 |
> |
if not pyradlib: |
85 |
> |
raise Error('Python support library directory "pyradlib" not found on RAYPATH') |
86 |
|
|
87 |
< |
rt_units = [ |
88 |
< |
'test_lookamb', |
89 |
< |
'test_rpict', |
90 |
< |
'test_rtrace', |
91 |
< |
#'test_rview', |
92 |
< |
] |
87 |
> |
# Since this here is the best place to figure out where |
88 |
> |
# everything is, we create an ad-hoc module to hold directory |
89 |
> |
# paths and functions for creating file paths. |
90 |
> |
# The individual test cases can then "import testsupport" to |
91 |
> |
# get access to the complete information. |
92 |
> |
supmod = types.ModuleType(str('testsupport')) |
93 |
> |
datadir = os.path.join(self.thisdir, 'test data') |
94 |
> |
supmod.bindir = self.bindir |
95 |
> |
supmod.datadir = datadir |
96 |
> |
supmod.datafile = lambda fn,*ffn: os.path.join(datadir, fn, *ffn) |
97 |
> |
supmod.path = pathlist |
98 |
> |
supmod.radlib = self.radlib |
99 |
> |
supmod.raypath = raypathlist |
100 |
> |
supmod.pyradlib = pyradlib |
101 |
> |
sys.modules['testsupport'] = supmod |
102 |
|
|
103 |
< |
util_units = [ |
104 |
< |
'test_rad', |
105 |
< |
'test_findglare', |
106 |
< |
'test_glarendx', |
107 |
< |
'test_rpiece', |
108 |
< |
'test_vwrays', |
157 |
< |
'test_vwright', |
158 |
< |
'test_getinfo', |
159 |
< |
'test_makedist', |
160 |
< |
#'test_xglaresrc', |
161 |
< |
'test_glrad', |
162 |
< |
'test_ranimate', |
163 |
< |
'test_ranimove', |
164 |
< |
] |
103 |
> |
self._run_all() |
104 |
> |
finally: |
105 |
> |
if hasattr(sys.modules, 'testsupport'): |
106 |
> |
del sys.modules['testsupport'] |
107 |
> |
os.environ = old_osenv |
108 |
> |
sys.path = old_syspath |
109 |
|
|
110 |
+ |
def _run_all(self): |
111 |
+ |
runner = unittest.TextTestRunner(verbosity=self.V) |
112 |
+ |
if self.testcats: |
113 |
+ |
cats = self.testcats |
114 |
+ |
else: cats = TESTCATS |
115 |
+ |
for dir in cats: |
116 |
+ |
loader = unittest.defaultTestLoader |
117 |
+ |
fulldir = os.path.join(self.testdir, dir) |
118 |
+ |
if not os.path.isdir(fulldir): |
119 |
+ |
raise Error('No such directory: "%s"' % fulldir) |
120 |
+ |
suite = loader.discover(fulldir, 'test*.py', |
121 |
+ |
top_level_dir=self.thisdir) |
122 |
+ |
count = suite.countTestCases() |
123 |
+ |
if count: |
124 |
+ |
print('\n--', dir, '----', file=sys.stderr) |
125 |
+ |
runner.run(suite) |
126 |
|
|
167 |
– |
def run_tests(unitgroup): |
168 |
– |
print '---- unit group %s ----' % unitgroup |
169 |
– |
for unit in globals()[unitgroup + '_units']: |
170 |
– |
try: |
171 |
– |
mod = __import__('py_tests.'+unit,globals(),locals(),['py_tests']) |
172 |
– |
print '%-18s' % unit, |
173 |
– |
sys.stdout.flush() |
174 |
– |
mod.main() |
175 |
– |
except ImportError, e: |
176 |
– |
#raise |
177 |
– |
pass |
127 |
|
|
128 |
|
def main(): |
129 |
< |
run_tests('cal') |
130 |
< |
run_tests('cv') |
131 |
< |
run_tests('gen') |
132 |
< |
run_tests('hd') |
133 |
< |
run_tests('meta') |
134 |
< |
run_tests('ot') |
135 |
< |
run_tests('px') |
136 |
< |
run_tests('rt') |
137 |
< |
run_tests('util') |
129 |
> |
'''Main function for invocation as script. See usage instructions with -H''' |
130 |
> |
parser = argparse.ArgumentParser(add_help=False, |
131 |
> |
description='Run Radiance test suite',) |
132 |
> |
parser.add_argument('-V', action='store_true', |
133 |
> |
help='Verbose: Print all executed test cases to stderr') |
134 |
> |
parser.add_argument('-H', action='help', |
135 |
> |
help='Help: print this text to stderr and exit') |
136 |
> |
parser.add_argument('-p', action='store', nargs=1, |
137 |
> |
dest='bindir', metavar='bindir', help='Path to Radiance binaries') |
138 |
> |
parser.add_argument('-l', action='store', nargs=1, |
139 |
> |
dest='radlib', metavar='radlib', help='Path to Radiance library') |
140 |
> |
parser.add_argument('-c', action='store', nargs=1, |
141 |
> |
dest='cat', metavar='cat', help='Category of tests to run (else all)') |
142 |
> |
args = parser.parse_args() |
143 |
> |
RadianceTests(**vars(args)) |
144 |
|
|
145 |
+ |
|
146 |
|
if __name__ == '__main__': |
147 |
< |
main() |
147 |
> |
try: main() |
148 |
> |
except KeyboardInterrupt: |
149 |
> |
sys.stderr.write('*cancelled*\n') |
150 |
> |
exit(1) |
151 |
> |
except Error as e: |
152 |
> |
sys.stderr.write('%s: %s\n' % (SHORTPROGN, str(e))) |
153 |
> |
exit(-1) |
154 |
|
|
155 |
+ |
# vi: set ts=4 sw=4 : |