summaryrefslogtreecommitdiff
path: root/simplejson/tests/test_recursion.py
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2008-05-03 17:54:12 +0000
committerBob Ippolito <bob@redivi.com>2008-05-03 17:54:12 +0000
commit37594d7c05c0ceb30e3894950e33236aa07ebf73 (patch)
tree78a5b7e59ce9bd722babdcba44e3b290858a5472 /simplejson/tests/test_recursion.py
parentf750b9beae59bcc8b69fece978202f118c01535e (diff)
downloadsimplejson-37594d7c05c0ceb30e3894950e33236aa07ebf73.tar.gz
convert test suite to unittest, remove jsonfilter, bump version to 0.9
git-svn-id: http://simplejson.googlecode.com/svn/trunk@85 a4795897-2c25-0410-b006-0d3caba88fa1
Diffstat (limited to 'simplejson/tests/test_recursion.py')
-rw-r--r--simplejson/tests/test_recursion.py109
1 files changed, 56 insertions, 53 deletions
diff --git a/simplejson/tests/test_recursion.py b/simplejson/tests/test_recursion.py
index 756b066..d8ffbd5 100644
--- a/simplejson/tests/test_recursion.py
+++ b/simplejson/tests/test_recursion.py
@@ -1,62 +1,65 @@
-import simplejson
+from unittest import TestCase
-def test_listrecursion():
- x = []
- x.append(x)
- try:
- simplejson.dumps(x)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on list recursion"
- x = []
- y = [x]
- x.append(y)
- try:
- simplejson.dumps(x)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on alternating list recursion"
- y = []
- x = [y, y]
- # ensure that the marker is cleared
- simplejson.dumps(x)
+import simplejson as S
-def test_dictrecursion():
- x = {}
- x["test"] = x
- try:
- simplejson.dumps(x)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on dict recursion"
- x = {}
- y = {"a": x, "b": x}
- # ensure that the marker is cleared
- simplejson.dumps(x)
-
-class TestObject:
+class JSONTestObject:
pass
-class RecursiveJSONEncoder(simplejson.JSONEncoder):
+class RecursiveJSONEncoder(S.JSONEncoder):
recurse = False
def default(self, o):
- if o is TestObject:
+ if o is JSONTestObject:
if self.recurse:
- return [TestObject]
+ return [JSONTestObject]
else:
- return 'TestObject'
- simplejson.JSONEncoder.default(o)
+ return 'JSONTestObject'
+ return S.JSONEncoder.default(o)
+
+class TestRecursion(TestCase):
+ def test_listrecursion(self):
+ x = []
+ x.append(x)
+ try:
+ S.dumps(x)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on list recursion")
+ x = []
+ y = [x]
+ x.append(y)
+ try:
+ S.dumps(x)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on alternating list recursion")
+ y = []
+ x = [y, y]
+ # ensure that the marker is cleared
+ S.dumps(x)
+
+ def test_dictrecursion(self):
+ x = {}
+ x["test"] = x
+ try:
+ S.dumps(x)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on dict recursion")
+ x = {}
+ y = {"a": x, "b": x}
+ # ensure that the marker is cleared
+ S.dumps(x)
-def test_defaultrecursion():
- enc = RecursiveJSONEncoder()
- assert enc.encode(TestObject) == '"TestObject"'
- enc.recurse = True
- try:
- enc.encode(TestObject)
- except ValueError:
- pass
- else:
- assert False, "didn't raise ValueError on default recursion"
+ def test_defaultrecursion(self):
+ enc = RecursiveJSONEncoder()
+ self.assertEquals(enc.encode(JSONTestObject), '"JSONTestObject"')
+ enc.recurse = True
+ try:
+ enc.encode(JSONTestObject)
+ except ValueError:
+ pass
+ else:
+ self.fail("didn't raise ValueError on default recursion")