ยปCore Development>Code coverage>Lib/test/test_json/test_separators.py

Python code coverage for Lib/test/test_json/test_separators.py

#countcontent
1n/aimport textwrap
2n/afrom test.test_json import PyTest, CTest
3n/a
4n/a
5n/aclass TestSeparators:
6n/a def test_separators(self):
7n/a h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
8n/a {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
9n/a
10n/a expect = textwrap.dedent("""\
11n/a [
12n/a [
13n/a "blorpie"
14n/a ] ,
15n/a [
16n/a "whoops"
17n/a ] ,
18n/a [] ,
19n/a "d-shtaeou" ,
20n/a "d-nthiouh" ,
21n/a "i-vhbjkhnth" ,
22n/a {
23n/a "nifty" : 87
24n/a } ,
25n/a {
26n/a "field" : "yes" ,
27n/a "morefield" : false
28n/a }
29n/a ]""")
30n/a
31n/a
32n/a d1 = self.dumps(h)
33n/a d2 = self.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))
34n/a
35n/a h1 = self.loads(d1)
36n/a h2 = self.loads(d2)
37n/a
38n/a self.assertEqual(h1, h)
39n/a self.assertEqual(h2, h)
40n/a self.assertEqual(d2, expect)
41n/a
42n/a def test_illegal_separators(self):
43n/a h = {1: 2, 3: 4}
44n/a self.assertRaises(TypeError, self.dumps, h, separators=(b', ', ': '))
45n/a self.assertRaises(TypeError, self.dumps, h, separators=(', ', b': '))
46n/a self.assertRaises(TypeError, self.dumps, h, separators=(b', ', b': '))
47n/a
48n/a
49n/aclass TestPySeparators(TestSeparators, PyTest): pass
50n/aclass TestCSeparators(TestSeparators, CTest): pass