simplejson may not be available with python 2.4 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 24 Feb 2010 15:00:37 +0100
branchstable
changeset 4694 c19366a12281
parent 4693 1eaf5ce04844
child 4695 4aaf87e7f79e
simplejson may not be available with python 2.4
test/unittest_utils.py
--- a/test/unittest_utils.py	Wed Feb 24 15:00:15 2010 +0100
+++ b/test/unittest_utils.py	Wed Feb 24 15:00:37 2010 +0100
@@ -6,14 +6,18 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 
-from logilab.common.testlib import TestCase, unittest_main
-
-import simplejson
+import re
 import decimal
 import datetime
 
-from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList, CubicWebJsonEncoder
+from logilab.common.testlib import TestCase, unittest_main
+from cubicweb.utils import make_uid, UStringIO, SizeConstrainedList
 
+try:
+    import simplejson
+    from cubicweb.utils import CubicWebJsonEncoder
+except ImportError:
+    simplejson = None
 
 class MakeUidTC(TestCase):
     def test_1(self):
@@ -26,6 +30,9 @@
             uid = make_uid('xyz')
             if uid in d:
                 self.fail(len(d))
+            if re.match('\d', uid):
+                self.fail('make_uid must not return something begining with '
+                          'some numeric character, got %s' % uid)
             d.add(uid)
 
 
@@ -53,6 +60,9 @@
             yield self.assertEquals, l, expected
 
 class JSONEncoerTests(TestCase):
+    def setUp(self):
+        if simplejson is None:
+            self.skip('simplejson not available')
 
     def encode(self, value):
         return simplejson.dumps(value, cls=CubicWebJsonEncoder)