summaryrefslogtreecommitdiff
path: root/Lib/test/json_tests
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-04-12 21:09:18 -0400
committerR David Murray <rdmurray@bitdance.com>2011-04-12 21:09:18 -0400
commit45da14952361baa3441a4ff3bc9120051ff9ad5e (patch)
tree82c3ea8acae0cea86cd2b4aa544d73dfdcc9a8c7 /Lib/test/json_tests
parente6181e8d6619719812fe41fee72b8ced76daf29c (diff)
parent836f7e3c0abb7671531a7b7c63ea47c9ac6feedc (diff)
downloadcpython-45da14952361baa3441a4ff3bc9120051ff9ad5e.tar.gz
Merge #10019: Fix regression relative to 2.6: add newlines if indent=0
Patch by Amaury Forgeot d'Arc, updated by Sando Tosi.
Diffstat (limited to 'Lib/test/json_tests')
-rw-r--r--Lib/test/json_tests/test_indent.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/json_tests/test_indent.py b/Lib/test/json_tests/test_indent.py
index d8030aaade..692a494cfe 100644
--- a/Lib/test/json_tests/test_indent.py
+++ b/Lib/test/json_tests/test_indent.py
@@ -2,6 +2,7 @@ from unittest import TestCase
import json
import textwrap
+from io import StringIO
class TestIndent(TestCase):
def test_indent(self):
@@ -43,3 +44,18 @@ class TestIndent(TestCase):
self.assertEqual(h3, h)
self.assertEqual(d2, expect.expandtabs(2))
self.assertEqual(d3, expect)
+
+ def test_indent0(self):
+ h = {3: 1}
+ def check(indent, expected):
+ d1 = json.dumps(h, indent=indent)
+ self.assertEqual(d1, expected)
+
+ sio = StringIO()
+ json.dump(h, sio, indent=indent)
+ self.assertEqual(sio.getvalue(), expected)
+
+ # indent=0 should emit newlines
+ check(0, '{\n"3": 1\n}')
+ # indent=None is more compact
+ check(None, '{"3": 1}')