author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 11 Sep 2009 08:39:17 +0200 | |
branch | stable |
changeset 3174 | 97273eeaaead |
parent 2635 | c94df21f7ab2 |
child 3146 | cfc4344023f2 |
child 3231 | 3ee43e2f8560 |
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 |
||
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
11 |
from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList |
0 | 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() |