comparison _test_lookup_list.py @ 280:b39327d5506f

passed test_lookup_list.py to unittest
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Fri, 06 Jun 2008 13:34:25 -0400
parents test_lookup_list.py@323909110d1c
children 29f394813c3c
comparison
equal deleted inserted replaced
279:2e22cc120688 280:b39327d5506f
1 from lookup_list import *
2 import unittest
3 def have_raised(to_eval, **var):
4 have_thrown = False
5 try:
6 eval(to_eval)
7 except :
8 have_thrown = True
9 return have_thrown
10
11 def have_raised2(f, *args, **kwargs):
12 have_thrown = False
13 try:
14 f(*args, **kwargs)
15 except :
16 have_thrown = True
17 return have_thrown
18
19 class T_LookUpList(unittest.TestCase):
20 def test_LookupList(self):
21 #test only the example in the doc???
22 example = LookupList(['x','y','z'],[1,2,3])
23 example['x'] = [1, 2, 3] # set or change a field
24 x, y, z = example
25 x = example[0]
26 x = example["x"]
27 assert example.keys()==['x','y','z']
28 assert example.values()==[[1,2,3],2,3]
29 assert example.items()==[('x',[1,2,3]),('y',2),('z',3)]
30 example.append_keyval('u',0) # adds item with name 'u' and value 0
31 assert len(example)==4 # number of items = 4 here
32 example2 = LookupList(['v','w'], ['a','b'])
33 example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b'])
34 assert example+example2==example3
35 assert have_raised("var['x']+var['x']",x=example)
36
37 del example, example2, example3, x, y ,z
38
39 if __name__=='__main__':
40 unittest.main()