+++ /dev/null
-import textwrap\r
-from StringIO import StringIO\r
-from json.tests import PyTest, CTest\r
-\r
-\r
-class TestIndent(object):\r
- def test_indent(self):\r
- h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',\r
- {'nifty': 87}, {'field': 'yes', 'morefield': False} ]\r
-\r
- expect = textwrap.dedent("""\\r
- [\r
- [\r
- "blorpie"\r
- ],\r
- [\r
- "whoops"\r
- ],\r
- [],\r
- "d-shtaeou",\r
- "d-nthiouh",\r
- "i-vhbjkhnth",\r
- {\r
- "nifty": 87\r
- },\r
- {\r
- "field": "yes",\r
- "morefield": false\r
- }\r
- ]""")\r
-\r
-\r
- d1 = self.dumps(h)\r
- d2 = self.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))\r
-\r
- h1 = self.loads(d1)\r
- h2 = self.loads(d2)\r
-\r
- self.assertEqual(h1, h)\r
- self.assertEqual(h2, h)\r
- self.assertEqual(d2, expect)\r
-\r
- def test_indent0(self):\r
- h = {3: 1}\r
- def check(indent, expected):\r
- d1 = self.dumps(h, indent=indent)\r
- self.assertEqual(d1, expected)\r
-\r
- sio = StringIO()\r
- self.json.dump(h, sio, indent=indent)\r
- self.assertEqual(sio.getvalue(), expected)\r
-\r
- # indent=0 should emit newlines\r
- check(0, '{\n"3": 1\n}')\r
- # indent=None is more compact\r
- check(None, '{"3": 1}')\r
-\r
-\r
-class TestPyIndent(TestIndent, PyTest): pass\r
-class TestCIndent(TestIndent, CTest): pass\r