Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:31

0001 from __future__ import absolute_import
0002 import unittest
0003 
0004 from .diclist import diclist
0005 
0006 class DiclistTestCase(unittest.TestCase):
0007 
0008     def test_string_key(self):
0009         dl = diclist()
0010         dl.add('a', 1)
0011         dl.add('b', 2)
0012         dl.add('c', 3)
0013         self.assertEqual([1,2,3], [value for value in dl] ) 
0014         self.assertEqual(dl['c'], 3)
0015 
0016     def test_bad_int_key(self):
0017         dl = diclist()
0018         self.assertRaises(ValueError, dl.add, 1, 'a')
0019         self.assertRaises(ValueError, dl.add, 1, 'a')
0020    
0021     def test_float_key(self):
0022         dl = diclist()
0023         dl.add(1., 'a')
0024         dl.add(2., 'b')
0025         self.assertRaises(IndexError, dl.__getitem__, 2)
0026         self.assertEqual(dl[2.], 'b')
0027 
0028 
0029 if __name__ == '__main__':
0030     unittest.main()