diff options
| author | R David Murray <rdmurray@bitdance.com> | 2011-04-13 01:00:26 (GMT) |
|---|---|---|
| committer | R David Murray <rdmurray@bitdance.com> | 2011-04-13 01:00:26 (GMT) |
| commit | ea8b6ef15f047536d4222f2b810d10756adc0dac (patch) | |
| tree | aa033ebf6bbd5d787a8e4805de9e291292dca458 /Lib/json/tests/test_indent.py | |
| parent | 49c440877e2d13bb545243ad2cb427272f530cab (diff) | |
| download | cpython-ea8b6ef15f047536d4222f2b810d10756adc0dac.zip cpython-ea8b6ef15f047536d4222f2b810d10756adc0dac.tar.gz cpython-ea8b6ef15f047536d4222f2b810d10756adc0dac.tar.bz2 | |
#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/json/tests/test_indent.py')
| -rw-r--r-- | Lib/json/tests/test_indent.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/json/tests/test_indent.py b/Lib/json/tests/test_indent.py index cd608d9..64b9b9c 100644 --- a/Lib/json/tests/test_indent.py +++ b/Lib/json/tests/test_indent.py @@ -2,6 +2,7 @@ from unittest import TestCase import json import textwrap +from StringIO import StringIO class TestIndent(TestCase): def test_indent(self): @@ -39,3 +40,18 @@ class TestIndent(TestCase): self.assertEqual(h1, h) self.assertEqual(h2, h) self.assertEqual(d2, 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}') |
