ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/test/run_tests.py
(Generate patch)

Comparing ray/test/run_tests.py (file contents):
Revision 1.2 by schorsch, Thu Mar 10 01:49:56 2016 UTC vs.
Revision 1.6 by schorsch, Mon Jan 8 13:38:37 2018 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines