1 from unittest import TestCase
2 import simplejson as json
4 def default_iterable(obj):
7 class TestCheckCircular(TestCase):
8 def test_circular_dict(self):
11 self.assertRaises(ValueError, json.dumps, dct)
13 def test_circular_list(self):
16 self.assertRaises(ValueError, json.dumps, lst)
18 def test_circular_composite(self):
21 dct2['a'].append(dct2)
22 self.assertRaises(ValueError, json.dumps, dct2)
24 def test_circular_default(self):
25 json.dumps([set()], default=default_iterable)
26 self.assertRaises(TypeError, json.dumps, [set()])
28 def test_circular_off_default(self):
29 json.dumps([set()], default=default_iterable, check_circular=False)
30 self.assertRaises(TypeError, json.dumps, [set()], check_circular=False)