Skip to content

Commit 52bafb0

Browse files
committed
Test indent
1 parent 3413f4f commit 52bafb0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

Lib/test/test_json/test_tool.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
import textwrap
44
import unittest
5-
import subprocess
5+
from subprocess import Popen, PIPE
66
from test import support
77
from test.support.script_helper import assert_python_ok
88

@@ -61,12 +61,11 @@ class TestTool(unittest.TestCase):
6161
""")
6262

6363
def test_stdin_stdout(self):
64-
with subprocess.Popen(
65-
(sys.executable, '-m', 'json.tool'),
66-
stdin=subprocess.PIPE, stdout=subprocess.PIPE) as proc:
64+
args = sys.executable, '-m', 'json.tool'
65+
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
6766
out, err = proc.communicate(self.data.encode())
6867
self.assertEqual(out.splitlines(), self.expect.encode().splitlines())
69-
self.assertEqual(err, None)
68+
self.assertEqual(err, b'')
7069

7170
def _create_infile(self):
7271
infile = support.TESTFN
@@ -114,3 +113,25 @@ def test_no_ensure_ascii_flag(self):
114113
self.assertEqual(out.splitlines(),
115114
self.expect_without_sort_keys.encode().splitlines())
116115
self.assertEqual(err, b'')
116+
117+
def test_indent(self):
118+
json_stdin = b'[1, 2]'
119+
expect = textwrap.dedent(b'''\
120+
[
121+
1,
122+
2
123+
]
124+
''')
125+
args = sys.executable, '-m', 'json.tool', '--indent', '2'
126+
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
127+
json_stdout, err = proc.communicate(json_stdin)
128+
self.assertEqual(expect.splitlines(), json_stdout.splitlines())
129+
self.assertEqual(err, b'')
130+
131+
def test_no_indent(self):
132+
json_stdin = b'[1, 2]'
133+
args = sys.executable, '-m', 'json.tool', '--no-indent'
134+
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
135+
json_stdout, err = proc.communicate(json_stdin)
136+
self.assertEqual(json_stdin, json_stdout)
137+
self.assertEqual(err, b'')

0 commit comments

Comments
 (0)