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