equal
deleted
inserted
replaced
4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 |
8 |
9 from logilab.common.testlib import TestCase, unittest_main |
9 import re |
10 |
|
11 import simplejson |
|
12 import decimal |
10 import decimal |
13 import datetime |
11 import datetime |
14 |
12 |
15 from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList, CubicWebJsonEncoder |
13 from logilab.common.testlib import TestCase, unittest_main |
|
14 from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList |
16 |
15 |
|
16 try: |
|
17 import simplejson |
|
18 from cubicweb.utils import CubicWebJsonEncoder |
|
19 except ImportError: |
|
20 simplejson = None |
17 |
21 |
18 class MakeUidTC(TestCase): |
22 class MakeUidTC(TestCase): |
19 def test_1(self): |
23 def test_1(self): |
20 self.assertNotEquals(make_uid('xyz'), make_uid('abcd')) |
24 self.assertNotEquals(make_uid('xyz'), make_uid('abcd')) |
21 self.assertNotEquals(make_uid('xyz'), make_uid('xyz')) |
25 self.assertNotEquals(make_uid('xyz'), make_uid('xyz')) |
24 d = set() |
28 d = set() |
25 while len(d)<10000: |
29 while len(d)<10000: |
26 uid = make_uid('xyz') |
30 uid = make_uid('xyz') |
27 if uid in d: |
31 if uid in d: |
28 self.fail(len(d)) |
32 self.fail(len(d)) |
|
33 if re.match('\d', uid): |
|
34 self.fail('make_uid must not return something begining with ' |
|
35 'some numeric character, got %s' % uid) |
29 d.add(uid) |
36 d.add(uid) |
30 |
37 |
31 |
38 |
32 class UStringIOTC(TestCase): |
39 class UStringIOTC(TestCase): |
33 def test_boolean_value(self): |
40 def test_boolean_value(self): |
51 l = SizeConstrainedList(10) |
58 l = SizeConstrainedList(10) |
52 l.extend(extension) |
59 l.extend(extension) |
53 yield self.assertEquals, l, expected |
60 yield self.assertEquals, l, expected |
54 |
61 |
55 class JSONEncoerTests(TestCase): |
62 class JSONEncoerTests(TestCase): |
|
63 def setUp(self): |
|
64 if simplejson is None: |
|
65 self.skip('simplejson not available') |
56 |
66 |
57 def encode(self, value): |
67 def encode(self, value): |
58 return simplejson.dumps(value, cls=CubicWebJsonEncoder) |
68 return simplejson.dumps(value, cls=CubicWebJsonEncoder) |
59 |
69 |
60 def test_encoding_dates(self): |
70 def test_encoding_dates(self): |