mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
#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:
parent
abdeeff3d1
commit
3dd02d62c9
4 changed files with 23 additions and 4 deletions
|
@ -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}')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue