ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/test/testcases/pyrad/test_lcompare.py
Revision: 1.1
Committed: Wed Mar 30 18:09:00 2016 UTC (9 years, 1 month ago) by schorsch
Content type: text/x-python
Branch: MAIN
Log Message:
The test utilities need testing (and some fixing) as well.

File Contents

# User Rev Content
1 schorsch 1.1 # -*- coding: utf-8 -*-
2     from __future__ import division, print_function, unicode_literals
3    
4     import struct
5     import operator
6     import unittest
7     from functools import reduce
8    
9     import testsupport as ts
10     from pyradlib import lcompare
11     from pyradlib.pyrad_proc import PIPE, Error, ProcMixin
12    
13    
14     class LcompareTestCase(unittest.TestCase, ProcMixin):
15    
16     def test_lc_llcompare(self):
17     # with values higher than 44721, total will return a float in e-format.
18     for xc, data, exp in (
19     ( None,
20     ( ('abcde', 'fgh', '1234', '56.789'),
21     ('xyz', '432', '987.65432')
22     ),
23     ( ('abcde', 'fgh', 1234, 56.789),
24     ('xyz', 432, 987.65432)
25     ),
26     ),
27     ( None,
28     ( (('a', 'b', 'c'),('d', 'e', 'f')),
29     (('0', '1', '2', '3'),('1.1', '2.2', '3.000e-03')),
30     ),
31     ( (('a', 'b', 'c'),('d', 'e', 'f')),
32     (range(4),(1.1, 2.2, 0.003)),
33     ),
34     ),
35     ( lcompare.error, # top level length
36     (('a', 'b', 'c'),('c','d'),('e','f'),),
37     (('a', 'b', 'c'),('c','d'),),
38     ),
39     ( lcompare.error, # top level length
40     (('a', 'b', 'c'),('c','d'),),
41     (('a', 'b', 'c'),('c','d'),('e','f'),),
42     ),
43     ( lcompare.error, # 2nd level length
44     (('a', 'b', 'c'),('c','d'),('e','f','g'),),
45     (('a', 'b', 'c'),('c','d'),('e','f'),),
46     ),
47     ( lcompare.error, # 2nd level length
48     (('a', 'b', 'c'),('c','d'),('e','f'),),
49     (('a', 'b', 'c'),('c','d'),('e','f','g'),),
50     ),
51     ( lcompare.error, # string diff
52     (('a', 'b', 'c'),('c','d'),('e','f','g'),),
53     (('a', 'b', 'c'),('c','d'),('e','f','h'),),
54     ),
55     ( lcompare.error, # int diff
56     (('a', 'b', 'c'),('c','d'),('1','2','3'),),
57     (('a', 'b', 'c'),('c','d'),( 1, 2, 4),),
58     ),
59     ( lcompare.error, # float diff
60     (('a', 'b', 'c'),('c','d'),('1.1','2.2','3.3'),),
61     (('a', 'b', 'c'),('c','d'),( 1.1, 2.2, 3.4),),
62     ),
63     ( lcompare.error, # exponent diff
64     (('a', 'b', 'c'),('c','d'),('1.1','2.2','3.0000e-02'),),
65     (('a', 'b', 'c'),('c','d'),( 1.1, 2.2, 0.003),),
66     ),
67     ( lcompare.error, # fuzzy compare
68     (('a', 'b', 'c'),('c','d'),('1.1','2.2','3.00000003'),),
69     (('a', 'b', 'c'),('c','d'),( 1.1, 2.2, 3.0000003),),
70     ),
71     ( None, # fuzzy compare
72     (('a', 'b', 'c'),('c','d'),('1.1','2.2','3.000000003'),),
73     (('a', 'b', 'c'),('c','d'),( 1.1, 2.2, 3.00000003),),
74     ),
75     ):
76     if xc:
77     self.assertRaises(xc, lcompare.llcompare, data, exp)
78     else:
79     try: lcompare.llcompare(data, exp)
80     except lcompare.error as e:
81     self.fail(('call_one_text ') +str(e))
82    
83     def xtest_lc_split_headers(self):
84     htxt = '''example.hdr:
85     Xim format conversion by:
86     FORMAT=32-bit_rle_rgbe
87     pfilt -e 2 -x 512 -y 512 -p 1 -r .67
88     EXPOSURE=4.926198e+00
89     normpat
90     pfilt -1 -e .2
91     EXPOSURE=2.000000e-01
92     pfilt -x 128 -y 128
93     PIXASPECT=0.500000
94     EXPOSURE=2.571646e+00'''
95     res = lcompare.split_headers(htxt)
96     exp = (
97     ('', ('example.hdr:',)),
98     ('\t\t', ('Xim','format','conversion','by:')),
99     ('\t\t', 'FORMAT', '=', ('32-bit_rle_rgbe',)),
100     ('\t\t',
101     ('pfilt','-e','2','-x','512','-y','512','-p','1','-r','.67')),
102     ('\t\t', 'EXPOSURE', '=', ('4.926198e+00',)),
103     ('\t\t', ('normpat',)),
104     ('\t\t', ('pfilt','-1','-e','.2',)),
105     ('\t\t', 'EXPOSURE', '=', ('2.000000e-01',)),
106     ('\t\t', ('pfilt','-x','128','-y','128',)),
107     ('\t\t', 'PIXASPECT', '=', ('0.500000',)),
108     ('\t\t', 'EXPOSURE', '=', ('2.571646e+00',)),
109     )
110     try: lcompare.llcompare(res, exp)
111     except lcompare.error as e:
112     self.fail(('call_one_text ') +str(e))
113    
114     def xtest_lc_split_radfile(self):
115     df = ts.datafile('window_src.rad')
116     exp = ([['#'],
117     ['#', 'A', 'plain', 'old', 'glass', 'window'],
118     ['#'],
119     [], ['void', 'light', 'window_light'],
120     [0], [0], [3, 1, 1, 1],
121     [], ['window_light', 'polygon', 'window'],
122     [0], [0], [12], [23.5, 43, 30], [23.5, 26, 30],
123     [-23.5, 26, 30], [-23.5, 43, 30], []])
124     resl = lcompare.split_radfile(df)
125     try: lcompare.lcompare(resl, exp)
126     except lcompare.error as e:
127     print(resl, exp)
128     self.fail(('call_one_text n=%d -- ' % n) +str(e))
129    
130     def xtest_lc_split_rad(self):
131     df = ts.datafile('window_src.rad')
132     exp = ([['#'],
133     ['#', 'A', 'plain', 'old', 'glass', 'window'],
134     ['#'],
135     [], ['void', 'light', 'window_light'],
136     [0], [0], [3, 1, 1, 1],
137     [], ['window_light', 'polygon', 'window'],
138     [0], [0], [12], [23.5, 43, 30], [23.5, 26, 30],
139     [-23.5, 26, 30], [-23.5, 43, 30], []])
140     with open(df) as f:
141     res = f.read()
142     resl = lcompare.split_rad(res)
143     try: lcompare.lcompare(resl, exp)
144     except lcompare.error as e:
145     print(resl, exp)
146     self.fail(('call_one_text n=%d -- ' % n) +str(e))
147    
148    
149     # vi: set ts=4 sw=4 :