Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:30

0001 from __future__ import absolute_import
0002 import unittest
0003 import os 
0004 import shutil
0005 
0006 from .counter import Counter
0007 
0008 class CounterTestCase(unittest.TestCase):
0009 
0010     def test_simple(self):
0011         c = Counter('Test')
0012         c.register('a')
0013         c.register('b')
0014         c.inc('a')
0015         self.assertEqual(c['a'], ['a', 1])
0016         self.assertEqual(c['b'], ['b', 0])
0017         c.inc('a')
0018         self.assertEqual(c['a'], ['a', 2])
0019 
0020     def test_add(self):
0021         c = Counter('Test')
0022         c.register('a')
0023         c.register('b')
0024         c.inc('a')
0025         d = Counter('Test')
0026         d.register('a')
0027         d.register('b')
0028         d.inc('a')
0029         d.inc('b')
0030         d += c 
0031         self.assertEqual(d['a'], ['a', 2])
0032         self.assertEqual(d['b'], ['b', 1])
0033      
0034     def test_bad_add(self):
0035         c = Counter('Test')
0036         c.register('a')
0037         c.register('b')
0038         c.inc('a')
0039         d = Counter('Test')
0040         d.register('b')
0041         self.assertRaises(ValueError, d.__iadd__, c)
0042   
0043     def test_write(self):
0044         c = Counter('Test')
0045         c.register('a')
0046         c.register('b')
0047         c.inc('a')
0048         dirname = 'test_dir'
0049         if os.path.exists(dirname):
0050             shutil.rmtree(dirname)
0051         os.mkdir(dirname)
0052         c.write(dirname)
0053         shutil.rmtree(dirname)
0054         
0055         
0056 
0057 
0058 
0059 
0060 if __name__ == '__main__':
0061     unittest.main()