]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Lib/json/tests/test_indent.py
AppPkg/Applications/Python/Python-2.7.10: Initial Checkin part 4/5.
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Lib / json / tests / test_indent.py
CommitLineData
3257aa99
DM
1import textwrap\r
2from StringIO import StringIO\r
3from json.tests import PyTest, CTest\r
4\r
5\r
6class TestIndent(object):\r
7 def test_indent(self):\r
8 h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',\r
9 {'nifty': 87}, {'field': 'yes', 'morefield': False} ]\r
10\r
11 expect = textwrap.dedent("""\\r
12 [\r
13 [\r
14 "blorpie"\r
15 ],\r
16 [\r
17 "whoops"\r
18 ],\r
19 [],\r
20 "d-shtaeou",\r
21 "d-nthiouh",\r
22 "i-vhbjkhnth",\r
23 {\r
24 "nifty": 87\r
25 },\r
26 {\r
27 "field": "yes",\r
28 "morefield": false\r
29 }\r
30 ]""")\r
31\r
32\r
33 d1 = self.dumps(h)\r
34 d2 = self.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))\r
35\r
36 h1 = self.loads(d1)\r
37 h2 = self.loads(d2)\r
38\r
39 self.assertEqual(h1, h)\r
40 self.assertEqual(h2, h)\r
41 self.assertEqual(d2, expect)\r
42\r
43 def test_indent0(self):\r
44 h = {3: 1}\r
45 def check(indent, expected):\r
46 d1 = self.dumps(h, indent=indent)\r
47 self.assertEqual(d1, expected)\r
48\r
49 sio = StringIO()\r
50 self.json.dump(h, sio, indent=indent)\r
51 self.assertEqual(sio.getvalue(), expected)\r
52\r
53 # indent=0 should emit newlines\r
54 check(0, '{\n"3": 1\n}')\r
55 # indent=None is more compact\r
56 check(None, '{"3": 1}')\r
57\r
58\r
59class TestPyIndent(TestIndent, PyTest): pass\r
60class TestCIndent(TestIndent, CTest): pass\r