annotate Lib/json/tests/test_check_circular.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents d95e5add3ca4
children 5b0fecd2eba0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52199
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
1 from unittest import TestCase
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
2 import json
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
3
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
4 def default_iterable(obj):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
5 return list(obj)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
6
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
7 class TestCheckCircular(TestCase):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
8 def test_circular_dict(self):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
9 dct = {}
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
10 dct['a'] = dct
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
11 self.assertRaises(ValueError, json.dumps, dct)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
12
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
13 def test_circular_list(self):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
14 lst = []
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
15 lst.append(lst)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
16 self.assertRaises(ValueError, json.dumps, lst)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
17
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
18 def test_circular_composite(self):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
19 dct2 = {}
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
20 dct2['a'] = []
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
21 dct2['a'].append(dct2)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
22 self.assertRaises(ValueError, json.dumps, dct2)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
23
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
24 def test_circular_default(self):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
25 json.dumps([set()], default=default_iterable)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
26 self.assertRaises(TypeError, json.dumps, [set()])
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
27
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
28 def test_circular_off_default(self):
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
29 json.dumps([set()], default=default_iterable, check_circular=False)
d95e5add3ca4 merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
diff changeset
30 self.assertRaises(TypeError, json.dumps, [set()], check_circular=False)