12 |
12 |
13 from logilab.common.testlib import TestCase, unittest_main |
13 from logilab.common.testlib import TestCase, unittest_main |
14 from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList, RepeatList |
14 from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList, RepeatList |
15 |
15 |
16 try: |
16 try: |
17 import simplejson |
17 try: |
|
18 import json |
|
19 except ImportError: |
|
20 import simplejson as json |
18 from cubicweb.utils import CubicWebJsonEncoder |
21 from cubicweb.utils import CubicWebJsonEncoder |
19 except ImportError: |
22 except ImportError: |
20 simplejson = None |
23 json = None |
21 |
24 |
22 class MakeUidTC(TestCase): |
25 class MakeUidTC(TestCase): |
23 def test_1(self): |
26 def test_1(self): |
24 self.assertNotEquals(make_uid('xyz'), make_uid('abcd')) |
27 self.assertNotEquals(make_uid('xyz'), make_uid('abcd')) |
25 self.assertNotEquals(make_uid('xyz'), make_uid('xyz')) |
28 self.assertNotEquals(make_uid('xyz'), make_uid('xyz')) |
105 l.extend(extension) |
108 l.extend(extension) |
106 yield self.assertEquals, l, expected |
109 yield self.assertEquals, l, expected |
107 |
110 |
108 class JSONEncoderTC(TestCase): |
111 class JSONEncoderTC(TestCase): |
109 def setUp(self): |
112 def setUp(self): |
110 if simplejson is None: |
113 if json is None: |
111 self.skip('simplejson not available') |
114 self.skip('json not available') |
112 |
115 |
113 def encode(self, value): |
116 def encode(self, value): |
114 return simplejson.dumps(value, cls=CubicWebJsonEncoder) |
117 return json.dumps(value, cls=CubicWebJsonEncoder) |
115 |
118 |
116 def test_encoding_dates(self): |
119 def test_encoding_dates(self): |
117 self.assertEquals(self.encode(datetime.datetime(2009, 9, 9, 20, 30)), |
120 self.assertEquals(self.encode(datetime.datetime(2009, 9, 9, 20, 30)), |
118 '"2009/09/09 20:30:00"') |
121 '"2009/09/09 20:30:00"') |
119 self.assertEquals(self.encode(datetime.date(2009, 9, 9)), |
122 self.assertEquals(self.encode(datetime.date(2009, 9, 9)), |