# HG changeset patch # User Frederic Bastien # Date 1212773665 14400 # Node ID b39327d5506fcfecf57a27d4bb43f5965dc42f6b # Parent 2e22cc120688956f1e723c47833bd146046a8e11 passed test_lookup_list.py to unittest diff -r 2e22cc120688 -r b39327d5506f _test_lookup_list.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/_test_lookup_list.py Fri Jun 06 13:34:25 2008 -0400 @@ -0,0 +1,40 @@ +from lookup_list import * +import unittest +def have_raised(to_eval, **var): + have_thrown = False + try: + eval(to_eval) + except : + have_thrown = True + return have_thrown + +def have_raised2(f, *args, **kwargs): + have_thrown = False + try: + f(*args, **kwargs) + except : + have_thrown = True + return have_thrown + +class T_LookUpList(unittest.TestCase): + def test_LookupList(self): + #test only the example in the doc??? + example = LookupList(['x','y','z'],[1,2,3]) + example['x'] = [1, 2, 3] # set or change a field + x, y, z = example + x = example[0] + x = example["x"] + assert example.keys()==['x','y','z'] + assert example.values()==[[1,2,3],2,3] + assert example.items()==[('x',[1,2,3]),('y',2),('z',3)] + example.append_keyval('u',0) # adds item with name 'u' and value 0 + assert len(example)==4 # number of items = 4 here + example2 = LookupList(['v','w'], ['a','b']) + example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b']) + assert example+example2==example3 + assert have_raised("var['x']+var['x']",x=example) + + del example, example2, example3, x, y ,z + +if __name__=='__main__': + unittest.main() diff -r 2e22cc120688 -r b39327d5506f test_lookup_list.py --- a/test_lookup_list.py Fri Jun 06 13:32:20 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -from lookup_list import * -def have_raised(to_eval, **var): - have_thrown = False - try: - eval(to_eval) - except : - have_thrown = True - return have_thrown - -def have_raised2(f, *args, **kwargs): - have_thrown = False - try: - f(*args, **kwargs) - except : - have_thrown = True - return have_thrown - - -def test_LookupList(): - #test only the example in the doc??? - print "test_LookupList" - example = LookupList(['x','y','z'],[1,2,3]) - example['x'] = [1, 2, 3] # set or change a field - x, y, z = example - x = example[0] - x = example["x"] - assert example.keys()==['x','y','z'] - assert example.values()==[[1,2,3],2,3] - assert example.items()==[('x',[1,2,3]),('y',2),('z',3)] - example.append_keyval('u',0) # adds item with name 'u' and value 0 - assert len(example)==4 # number of items = 4 here - example2 = LookupList(['v','w'], ['a','b']) - example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b']) - assert example+example2==example3 - assert have_raised("var['x']+var['x']",x=example) - - del example, example2, example3, x, y ,z - -if __name__=='__main__': - test_LookupList()