Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.json_tests.test_recursion.TestPyRecursion Class Reference
Inheritance diagram for test.json_tests.test_recursion.TestPyRecursion:
Inheritance graph
[legend]
Collaboration diagram for test.json_tests.test_recursion.TestPyRecursion:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_listrecursion
def test_dictrecursion
def test_defaultrecursion
def test_highly_nested_objects_decoding
def test_highly_nested_objects_encoding
def test_endless_recursion

Static Public Attributes

 json = pyjson
tuple loads = staticmethod(pyjson.loads)
tuple dumps = staticmethod(pyjson.dumps)

Detailed Description

Definition at line 99 of file test_recursion.py.


Member Function Documentation

Definition at line 46 of file test_recursion.py.

00046 
00047     def test_defaultrecursion(self):
00048         class RecursiveJSONEncoder(self.json.JSONEncoder):
00049             recurse = False
00050             def default(self, o):
00051                 if o is JSONTestObject:
00052                     if self.recurse:
00053                         return [JSONTestObject]
00054                     else:
00055                         return 'JSONTestObject'
00056                 return pyjson.JSONEncoder.default(o)
00057 
00058         enc = RecursiveJSONEncoder()
00059         self.assertEqual(enc.encode(JSONTestObject), '"JSONTestObject"')
00060         enc.recurse = True
00061         try:
00062             enc.encode(JSONTestObject)
00063         except ValueError:
00064             pass
00065         else:
00066             self.fail("didn't raise ValueError on default recursion")
00067 

Here is the call graph for this function:

Definition at line 32 of file test_recursion.py.

00032 
00033     def test_dictrecursion(self):
00034         x = {}
00035         x["test"] = x
00036         try:
00037             self.dumps(x)
00038         except ValueError:
00039             pass
00040         else:
00041             self.fail("didn't raise ValueError on dict recursion")
00042         x = {}
00043         y = {"a": x, "b": x}
00044         # ensure that the marker is cleared
00045         self.dumps(x)

Here is the call graph for this function:

Definition at line 88 of file test_recursion.py.

00088 
00089     def test_endless_recursion(self):
00090         # See #12051
00091         class EndlessJSONEncoder(self.json.JSONEncoder):
00092             def default(self, o):
00093                 """If check_circular is False, this will keep adding another list."""
00094                 return [o]
00095 
00096         with self.assertRaises(RuntimeError):
00097             EndlessJSONEncoder(check_circular=False).encode(5j)
00098 

Here is the call graph for this function:

Definition at line 68 of file test_recursion.py.

00068 
00069     def test_highly_nested_objects_decoding(self):
00070         # test that loading highly-nested objects doesn't segfault when C
00071         # accelerations are used. See #12017
00072         with self.assertRaises(RuntimeError):
00073             self.loads('{"a":' * 100000 + '1' + '}' * 100000)
00074         with self.assertRaises(RuntimeError):
00075             self.loads('{"a":' * 100000 + '[1]' + '}' * 100000)
00076         with self.assertRaises(RuntimeError):
00077             self.loads('[' * 100000 + '1' + ']' * 100000)

Here is the call graph for this function:

Definition at line 78 of file test_recursion.py.

00078 
00079     def test_highly_nested_objects_encoding(self):
00080         # See #12051
00081         l, d = [], {}
00082         for x in range(100000):
00083             l, d = [l], {'k':d}
00084         with self.assertRaises(RuntimeError):
00085             self.dumps(l)
00086         with self.assertRaises(RuntimeError):
00087             self.dumps(d)

Here is the call graph for this function:

Definition at line 9 of file test_recursion.py.

00009 
00010     def test_listrecursion(self):
00011         x = []
00012         x.append(x)
00013         try:
00014             self.dumps(x)
00015         except ValueError:
00016             pass
00017         else:
00018             self.fail("didn't raise ValueError on list recursion")
00019         x = []
00020         y = [x]
00021         x.append(y)
00022         try:
00023             self.dumps(x)
00024         except ValueError:
00025             pass
00026         else:
00027             self.fail("didn't raise ValueError on alternating list recursion")
00028         y = []
00029         x = [y, y]
00030         # ensure that the marker is cleared
00031         self.dumps(x)

Here is the call graph for this function:


Member Data Documentation

tuple test.json_tests.PyTest.dumps = staticmethod(pyjson.dumps) [static, inherited]

Definition at line 17 of file __init__.py.

test.json_tests.PyTest.json = pyjson [static, inherited]

Definition at line 15 of file __init__.py.

tuple test.json_tests.PyTest.loads = staticmethod(pyjson.loads) [static, inherited]

Definition at line 16 of file __init__.py.


The documentation for this class was generated from the following file: