comparison _test_lookup_list.py @ 281:29f394813c3c

use the unittest function to test that execption is raised
author Frederic Bastien <bastienf@iro.umontreal.ca>
date Fri, 06 Jun 2008 13:44:17 -0400
parents b39327d5506f
children
comparison
equal deleted inserted replaced
280:b39327d5506f 281:29f394813c3c
1 from lookup_list import * 1 from lookup_list import *
2 import unittest 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 3
19 class T_LookUpList(unittest.TestCase): 4 class T_LookUpList(unittest.TestCase):
20 def test_LookupList(self): 5 def test_LookupList(self):
21 #test only the example in the doc??? 6 #test only the example in the doc???
22 example = LookupList(['x','y','z'],[1,2,3]) 7 example = LookupList(['x','y','z'],[1,2,3])
30 example.append_keyval('u',0) # adds item with name 'u' and value 0 15 example.append_keyval('u',0) # adds item with name 'u' and value 0
31 assert len(example)==4 # number of items = 4 here 16 assert len(example)==4 # number of items = 4 here
32 example2 = LookupList(['v','w'], ['a','b']) 17 example2 = LookupList(['v','w'], ['a','b'])
33 example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b']) 18 example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b'])
34 assert example+example2==example3 19 assert example+example2==example3
35 assert have_raised("var['x']+var['x']",x=example) 20 self.assertRaises(AssertionError,example.__add__,example)
36
37 del example, example2, example3, x, y ,z 21 del example, example2, example3, x, y ,z
38 22
39 if __name__=='__main__': 23 if __name__=='__main__':
40 unittest.main() 24 unittest.main()