diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-04-13 01:09:18 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-04-13 01:09:18 (GMT) |
commit | d5315482e92d1f3c47460999a790df684bf8b09e (patch) | |
tree | d98dd2c8a709e6401a0c0a577ad9f9de191f73ed /Lib/test/json_tests | |
parent | 62f8bcb0a46fc0d8747ba2ab7e8d7311d73f82f7 (diff) | |
parent | 3dd02d62c90a169a32fb38bed34249a6cf7e1638 (diff) | |
download | cpython-d5315482e92d1f3c47460999a790df684bf8b09e.zip cpython-d5315482e92d1f3c47460999a790df684bf8b09e.tar.gz cpython-d5315482e92d1f3c47460999a790df684bf8b09e.tar.bz2 |
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 d8030aa..692a494 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}') |