PageRenderTime 263ms CodeModel.GetById 161ms app.highlight 3ms RepoModel.GetById 97ms app.codeStats 1ms

/Lib/json/tests/test_indent.py

http://unladen-swallow.googlecode.com/
Python | 41 lines | 38 code | 3 blank | 0 comment | 0 complexity | 03b71c00fc8534a70847e9667b69e482 MD5 | raw file
 1from unittest import TestCase
 2
 3import json
 4import textwrap
 5
 6class TestIndent(TestCase):
 7    def test_indent(self):
 8        h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
 9             {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
10
11        expect = textwrap.dedent("""\
12        [
13          [
14            "blorpie"
15          ],
16          [
17            "whoops"
18          ],
19          [],
20          "d-shtaeou",
21          "d-nthiouh",
22          "i-vhbjkhnth",
23          {
24            "nifty": 87
25          },
26          {
27            "field": "yes",
28            "morefield": false
29          }
30        ]""")
31
32
33        d1 = json.dumps(h)
34        d2 = json.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
35
36        h1 = json.loads(d1)
37        h2 = json.loads(d2)
38
39        self.assertEquals(h1, h)
40        self.assertEquals(h2, h)
41        self.assertEquals(d2, expect)