test/unittest_utils.py
branchtls-sprint
changeset 720 36b64f712ec9
parent 0 b97547f5f1fa
child 1802 d628defebc17
equal deleted inserted replaced
719:2a610efe21ce 720:36b64f712ec9
       
     1 """unit tests for module cubicweb.common.utils"""
       
     2 
       
     3 from logilab.common.testlib import TestCase, unittest_main
       
     4 
       
     5 from cubicweb.common.utils import make_uid, UStringIO, SizeConstrainedList
       
     6 
       
     7 
       
     8 class MakeUidTC(TestCase):
       
     9     def test_1(self):
       
    10         self.assertNotEquals(make_uid('xyz'), make_uid('abcd'))
       
    11         self.assertNotEquals(make_uid('xyz'), make_uid('xyz'))
       
    12         
       
    13     def test_2(self):
       
    14         d = {}
       
    15         while len(d)<10000:
       
    16             uid = make_uid('xyz')
       
    17             if d.has_key(uid):
       
    18                 self.fail(len(d))
       
    19             d[uid] = 1
       
    20 
       
    21         
       
    22 class UStringIOTC(TestCase):
       
    23     def test_boolean_value(self):
       
    24         self.assert_(UStringIO())
       
    25 
       
    26 
       
    27 class SizeConstrainedListTC(TestCase):
       
    28 
       
    29     def test_append(self):
       
    30         l = SizeConstrainedList(10)
       
    31         for i in xrange(12):
       
    32             l.append(i)
       
    33         self.assertEquals(l, range(2, 12))
       
    34     
       
    35     def test_extend(self):
       
    36         testdata = [(range(5), range(5)),
       
    37                     (range(10), range(10)),
       
    38                     (range(12), range(2, 12)),
       
    39                     ]
       
    40         for extension, expected in testdata:
       
    41             l = SizeConstrainedList(10)
       
    42             l.extend(extension)
       
    43             yield self.assertEquals, l, expected
       
    44 
       
    45    
       
    46 if __name__ == '__main__':
       
    47     unittest_main()