#10019: Fix regression relative to 2.6: add newlines if indent=0

Patch by Amaury Forgeot d'Arc, updated by Sando Tosi.
This commit is contained in:
R David Murray 2011-04-12 21:02:45 -04:00
parent abdeeff3d1
commit 3dd02d62c9
4 changed files with 23 additions and 4 deletions

View file

@ -2,6 +2,7 @@ from unittest import TestCase
import json
import textwrap
from io 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}')