]>
Commit | Line | Data |
---|---|---|
3257aa99 DM |
1 | import textwrap\r |
2 | from json.tests import PyTest, CTest\r | |
3 | \r | |
4 | \r | |
5 | class TestSeparators(object):\r | |
6 | def test_separators(self):\r | |
7 | h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',\r | |
8 | {'nifty': 87}, {'field': 'yes', 'morefield': False} ]\r | |
9 | \r | |
10 | expect = textwrap.dedent("""\\r | |
11 | [\r | |
12 | [\r | |
13 | "blorpie"\r | |
14 | ] ,\r | |
15 | [\r | |
16 | "whoops"\r | |
17 | ] ,\r | |
18 | [] ,\r | |
19 | "d-shtaeou" ,\r | |
20 | "d-nthiouh" ,\r | |
21 | "i-vhbjkhnth" ,\r | |
22 | {\r | |
23 | "nifty" : 87\r | |
24 | } ,\r | |
25 | {\r | |
26 | "field" : "yes" ,\r | |
27 | "morefield" : false\r | |
28 | }\r | |
29 | ]""")\r | |
30 | \r | |
31 | \r | |
32 | d1 = self.dumps(h)\r | |
33 | d2 = self.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))\r | |
34 | \r | |
35 | h1 = self.loads(d1)\r | |
36 | h2 = self.loads(d2)\r | |
37 | \r | |
38 | self.assertEqual(h1, h)\r | |
39 | self.assertEqual(h2, h)\r | |
40 | self.assertEqual(d2, expect)\r | |
41 | \r | |
42 | \r | |
43 | class TestPySeparators(TestSeparators, PyTest): pass\r | |
44 | class TestCSeparators(TestSeparators, CTest): pass\r |