author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 14 May 2009 11:38:40 +0200 | |
branch | tls-sprint |
changeset 1802 | d628defebc17 |
parent 720 | 36b64f712ec9 |
child 1977 | 606923dff11b |
permissions | -rw-r--r-- |
0 | 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')) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
720
diff
changeset
|
12 |
|
0 | 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 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
720
diff
changeset
|
21 |
|
0 | 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)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
720
diff
changeset
|
34 |
|
0 | 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 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
720
diff
changeset
|
45 |
|
0 | 46 |
if __name__ == '__main__': |
47 |
unittest_main() |