author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Fri, 17 Jul 2009 20:18:39 +0200 | |
changeset 2391 | 59a2def75e93 |
parent 1977 | 606923dff11b |
child 2635 | c94df21f7ab2 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
1 |
"""unit tests for module cubicweb.common.utils |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
7 |
""" |
0 | 8 |
|
9 |
from logilab.common.testlib import TestCase, unittest_main |
|
10 |
||
11 |
from cubicweb.common.utils import make_uid, UStringIO, SizeConstrainedList |
|
12 |
||
13 |
||
14 |
class MakeUidTC(TestCase): |
|
15 |
def test_1(self): |
|
16 |
self.assertNotEquals(make_uid('xyz'), make_uid('abcd')) |
|
17 |
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
|
18 |
|
0 | 19 |
def test_2(self): |
20 |
d = {} |
|
21 |
while len(d)<10000: |
|
22 |
uid = make_uid('xyz') |
|
23 |
if d.has_key(uid): |
|
24 |
self.fail(len(d)) |
|
25 |
d[uid] = 1 |
|
26 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
720
diff
changeset
|
27 |
|
0 | 28 |
class UStringIOTC(TestCase): |
29 |
def test_boolean_value(self): |
|
30 |
self.assert_(UStringIO()) |
|
31 |
||
32 |
||
33 |
class SizeConstrainedListTC(TestCase): |
|
34 |
||
35 |
def test_append(self): |
|
36 |
l = SizeConstrainedList(10) |
|
37 |
for i in xrange(12): |
|
38 |
l.append(i) |
|
39 |
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
|
40 |
|
0 | 41 |
def test_extend(self): |
42 |
testdata = [(range(5), range(5)), |
|
43 |
(range(10), range(10)), |
|
44 |
(range(12), range(2, 12)), |
|
45 |
] |
|
46 |
for extension, expected in testdata: |
|
47 |
l = SizeConstrainedList(10) |
|
48 |
l.extend(extension) |
|
49 |
yield self.assertEquals, l, expected |
|
50 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
720
diff
changeset
|
51 |
|
0 | 52 |
if __name__ == '__main__': |
53 |
unittest_main() |