source: branches/polybatch/test/test_linecatlog.py@ 2175

Last change on this file since 2175 was 1864, checked in by Malte Marquarding, 14 years ago

added test for linecatalog

File size: 2.5 KB
Line 
1import os
2import shutil
3from nose.tools import *
4from asap import linecatalog
5
6FNAME = "12mmlines.dat"
7
8class TestLinecatalog:
9 @classmethod
10 def setupClass(self):
11 f = file(FNAME, "w")
12 txt = """\
13He88B 18669.75 0.0 1.0
14H87B 19304.69 0.0 2
15He87B 19312.55 0.0 3
16U 19416.0 0.0 0
17"""
18 f.write(txt)
19 f.close()
20
21 @classmethod
22 def teardownClass(self):
23 os.remove(FNAME)
24
25 def setup(self):
26 self.lc = linecatalog(FNAME)
27
28 def test_init(self):
29 pass
30
31 def test_len(self):
32 assert_equals(len(self.lc), 4)
33
34 def test_set_name_pattern(self):
35 self.lc.set_name("H*")
36 assert_equals(len(self.lc), 3)
37
38 @raises(RuntimeError)
39 def test_fail_set_name_pattern(self):
40 self.lc.set_name("Z*")
41
42 def test_set_name_regex(self):
43 self.lc.set_name("^H[0-9]+B$", 'regex')
44 assert_equals(len(self.lc), 1)
45
46 @raises(RuntimeError)
47 def test_fail_set_name_regex(self):
48 self.lc.set_name("^Z[0-9]+B$", 'regex')
49
50 def test_reset(self):
51 self.lc.set_name("^H[0-9]+B$", 'regex')
52 self.lc.reset()
53 assert_equals(len(self.lc), 4)
54
55 def test_set_frequency_limits(self):
56 for args in [(1.0, 19.0, 'GHz', 1),
57 (1000.0, 19000.0, 'MHz', 1),
58 (19.30, 19.4, 'GHz', 2),
59 ]:
60 yield self.freq_limits, args
61
62 def freq_limits(self, args):
63 self.lc.set_frequency_limits(*args[:-1])
64 assert_equals(len(self.lc), args[-1])
65
66 @raises(RuntimeError)
67 def test_fails_set_frequency_limits(self):
68 self.lc.set_frequency_limits(20, 30)
69
70 def test_set_strength_limits(self):
71 self.lc.set_strength_limits(0.5, 2.5)
72 assert_equals(len(self.lc), 2)
73
74 @raises(RuntimeError)
75 def test_fails_set_strength_limits(self):
76 self.lc.set_strength_limits(10, 20)
77
78
79 def test_get_row(self):
80 r = self.lc.get_row(0)
81 refrow = {'name': 'He88B', 'value': 18669.75}
82 assert_equals(r, refrow)
83
84 @raises(IndexError)
85 def test_fail_get_row(self):
86 r = self.lc.get_row(-1)
87
88 def test_get_item(self):
89 r = self.lc[0]
90 refrow = {'name': 'He88B', 'value': 18669.75}
91 assert_equals(r, refrow)
92
93 def test_save(self):
94 outname = 'tmp_lincatalog.tbl'
95 self.lc.save(outname)
96 lc = linecatalog(outname)
97 lctxt = str(lc)
98 origlctxt = str(self.lc)
99 lc = None
100 shutil.rmtree(outname, True)
101 assert lctxt == origlctxt
Note: See TracBrowser for help on using the repository browser.