ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/test/testcases/cal/test_histo.py
Revision: 1.2
Committed: Tue Apr 19 21:19:59 2016 UTC (9 years ago) by schorsch
Content type: text/x-python
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad5R3, HEAD
Changes since 1.1: +2 -1 lines
Log Message:
robustness on failure

File Contents

# Content
1 # -*- coding: utf-8 -*-
2 from __future__ import division, print_function, unicode_literals
3
4 import unittest
5
6 import testsupport as ts
7 from pyradlib import lcompare
8 from pyradlib.pyrad_proc import PIPE, Error, ProcMixin
9
10
11 class HistoTestCase(unittest.TestCase, ProcMixin):
12
13 def _runit(self, cmd, fn):
14 try:
15 proc = self.call_one(cmd, 'call histo', _in=fn, out=PIPE,
16 universal_newlines=True)
17 raw = proc.stdout.read()
18 except Error as e:
19 self.fail('%s [%s]' % (str(e), self.qjoin(cmd)))
20 finally:
21 if 'proc' in locals():
22 proc.wait()
23 return lcompare.split_rad(raw)
24
25 def test_histo(self):
26 infile = ts.datafile('histo.dat')
27 cmd = 'histo -0.5 8.5 9'.split()
28 result = self._runit(cmd, infile)
29 expect = [
30 [0, 720, 240, 432, 1080, 270],
31 [1, 720, 240, 432, 1080, 270],
32 [2, 720, 240, 432, 0, 270],
33 [3, 0, 240, 432, 0, 270],
34 [4, 0, 240, 432, 0, 270],
35 [5, 0, 240, 0, 0, 270],
36 [6, 0, 240, 0, 0, 270],
37 [7, 0, 240, 0, 0, 270],
38 [8, 0, 240, 0, 0, 0],
39 ]
40 try: lcompare.llcompare(result, expect, ignore_empty=1)
41 except lcompare.error as e:
42 self.fail('%s [%s]' % (str(e),cmd))
43
44 def test_histo_c(self):
45 infile = ts.datafile('histo.dat')
46 cmd = 'histo -c -0.5 8.5 9'.split()
47 result = self._runit(cmd, infile)
48 expect = [
49 [-0.5, 0, 0, 0, 0, 0],
50 [0.5, 720, 240, 432, 1080, 270],
51 [1.5, 1440, 480, 864, 2160, 540],
52 [2.5, 2160, 720, 1296, 2160, 810],
53 [3.5, 2160, 960, 1728, 2160, 1080],
54 [4.5, 2160, 1200, 2160, 2160, 1350],
55 [5.5, 2160, 1440, 2160, 2160, 1620],
56 [6.5, 2160, 1680, 2160, 2160, 1890],
57 [7.5, 2160, 1920, 2160, 2160, 2160],
58 [8.5, 2160, 2160, 2160, 2160, 2160],
59 ]
60 try: lcompare.llcompare(result, expect, ignore_empty=1)
61 except lcompare.error as e:
62 self.fail('%s [%s]' % (str(e),cmd))
63
64 def test_histo_p(self):
65 infile = ts.datafile('histo.dat')
66 cmd = 'histo -p -0.5 8.5 9'.split()
67 result = self._runit(cmd, infile)
68 expect = [
69 [0, 33.333333, 11.111111, 20.0, 50.0, 12.5],
70 [1, 33.333333, 11.111111, 20.0, 50.0, 12.5],
71 [2, 33.333333, 11.111111, 20.0, 0.0, 12.5],
72 [3, 0.0, 11.111111, 20.0, 0.0, 12.5],
73 [4, 0.0, 11.111111, 20.0, 0.0, 12.5],
74 [5, 0.0, 11.111111, 0.0, 0.0, 12.5],
75 [6, 0.0, 11.111111, 0.0, 0.0, 12.5],
76 [7, 0.0, 11.111111, 0.0, 0.0, 12.5],
77 [8, 0.0, 11.111111, 0.0, 0.0, 0.0],
78 ]
79 try: lcompare.llcompare(result, expect, ignore_empty=1)
80 except lcompare.error as e:
81 self.fail('%s [%s]' % (str(e),cmd))
82
83 def test_histo_pc(self):
84 infile = ts.datafile('histo.dat')
85 cmd = 'histo -p -c -0.5 8.5 9'.split()
86 result = self._runit(cmd, infile)
87 expect = [
88 [-0.5, 0.0, 0.0, 0.0, 0.0, 0.0],
89 [0.5, 33.333333, 11.111111, 20.0, 50.0, 12.5],
90 [1.5, 66.666667, 22.222222, 40.0, 100.0, 25.0],
91 [2.5, 100.0, 33.333333, 60.0, 100.0, 37.5],
92 [3.5, 100.0, 44.444444, 80.0, 100.0, 50.0],
93 [4.5, 100.0, 55.555556, 100.0, 100.0, 62.5],
94 [5.5, 100.0, 66.666667, 100.0, 100.0, 75.0],
95 [6.5, 100.0, 77.777778, 100.0, 100.0, 87.5],
96 [7.5, 100.0, 88.888889, 100.0, 100.0, 100.0],
97 [8.5, 100.0, 100.0, 100.0, 100.0, 100.0],
98 ]
99 try: lcompare.llcompare(result, expect, ignore_empty=1)
100 except lcompare.error as e:
101 self.fail('%s [%s]' % (str(e),cmd))
102
103
104 # vi: set ts=4 sw=4 :