ยปCore Development>Code coverage>Lib/json/tests/test_indent.py

Python code coverage for Lib/json/tests/test_indent.py

#countcontent
1n/afrom unittest import TestCase
2n/a
3n/aimport json
4n/aimport textwrap
5n/a
6n/aclass TestIndent(TestCase):
7n/a def test_indent(self):
8n/a h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
9n/a {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
10n/a
11n/a expect = textwrap.dedent("""\
12n/a [
13n/a \t[
14n/a \t\t"blorpie"
15n/a \t],
16n/a \t[
17n/a \t\t"whoops"
18n/a \t],
19n/a \t[],
20n/a \t"d-shtaeou",
21n/a \t"d-nthiouh",
22n/a \t"i-vhbjkhnth",
23n/a \t{
24n/a \t\t"nifty": 87
25n/a \t},
26n/a \t{
27n/a \t\t"field": "yes",
28n/a \t\t"morefield": false
29n/a \t}
30n/a ]""")
31n/a
32n/a
33n/a d1 = json.dumps(h)
34n/a d2 = json.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
35n/a d3 = json.dumps(h, indent='\t', sort_keys=True, separators=(',', ': '))
36n/a
37n/a h1 = json.loads(d1)
38n/a h2 = json.loads(d2)
39n/a h3 = json.loads(d3)
40n/a
41n/a self.assertEqual(h1, h)
42n/a self.assertEqual(h2, h)
43n/a self.assertEqual(h3, h)
44n/a self.assertEqual(d2, expect.expandtabs(2))
45n/a self.assertEqual(d3, expect)