diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-04-12 21:09:18 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-04-12 21:09:18 -0400 |
commit | 45da14952361baa3441a4ff3bc9120051ff9ad5e (patch) | |
tree | 82c3ea8acae0cea86cd2b4aa544d73dfdcc9a8c7 /Lib/test/json_tests | |
parent | e6181e8d6619719812fe41fee72b8ced76daf29c (diff) | |
parent | 836f7e3c0abb7671531a7b7c63ea47c9ac6feedc (diff) | |
download | cpython-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.py | 16 |
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}') |