1 |
|
2 |
import os |
3 |
import math |
4 |
import string |
5 |
import unittest |
6 |
|
7 |
from unit_tools import support |
8 |
from unit_tools import lcompare |
9 |
|
10 |
_bindir = None |
11 |
|
12 |
class EvTestCase(unittest.TestCase): |
13 |
def setUp(self): |
14 |
if _bindir: |
15 |
self.oldpath = os.environ['PATH'] |
16 |
os.environ['PATH'] = _bindir |
17 |
|
18 |
def tearDown(self): |
19 |
if _bindir: |
20 |
os.environ['PATH'] = self.oldpath |
21 |
|
22 |
ltest = [ |
23 |
['2.3 + 5 * 21.7 / 1.43', [2.3 + 5 * 21.7 / 1.43]], |
24 |
['if(1, 1, 0)', [1]], |
25 |
['if(0, 1, 0)', [0]], |
26 |
['select(3, 1, 2, 3, 4, 5)', [3]], |
27 |
['floor(5.743)', [5]], |
28 |
['ceil(5.743)', [6]], |
29 |
['sqrt(7.4)', [math.sqrt(7.4)]], |
30 |
['exp(3.4)', [math.exp(3.4)]], |
31 |
['log(2.4)', [math.log(2.4)]], |
32 |
['log10(5.4)', [math.log10(5.4)]], |
33 |
['sin(.51)', [math.sin(.51)]], |
34 |
['cos(.41)', [math.cos(.41)]], |
35 |
['tan(0.77)', [math.tan(0.77)]], |
36 |
['asin(0.83)', [math.asin(0.83)]], |
37 |
['acos(.94)', [math.acos(.94)]], |
38 |
['atan(0.22)', [math.atan(0.22)]], |
39 |
['atan2(0.72, 0.54)', [math.atan2(0.72, 0.54)]], |
40 |
] |
41 |
|
42 |
def test_singleres(self): |
43 |
for expr, expect in self.ltest: |
44 |
cmd = 'ev "%s"' % expr |
45 |
result = [string.strip(os.popen(cmd).read())] |
46 |
try: lcompare.lcompare(result, expect) |
47 |
except lcompare.error, e: |
48 |
self.fail('%s [%s]' % (str(e),cmd)) |
49 |
|
50 |
def test_multipleres(self): |
51 |
pass # XXX implement |
52 |
|
53 |
def main(bindir=None): |
54 |
global _bindir |
55 |
_bindir=bindir |
56 |
support.run_case(EvTestCase) |
57 |
|
58 |
if __name__ == '__main__': |
59 |
main() |
60 |
|
61 |
# vi: set ts=4 sw=4 : |