Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test_jsonlines_emptylines
  • Loading branch information
ZeeD authored Nov 29, 2021
commit b8401b794ca373a50402e15101d2a8eeddb31cc8
25 changes: 25 additions & 0 deletions Lib/test/test_json/test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ class TestTool(unittest.TestCase):
}
""")

jsonlines_emptlylines_raw = textwrap.dedent("""\
{"foo":1}

{"bar":2}

""")

jsonlines_emptlylines_expect = textwrap.dedent("""\
{
"foo": 1
}

{
"bar": 2
}

""")

def test_stdin_stdout(self):
args = sys.executable, '-m', 'json.tool'
process = subprocess.run(args, input=self.data, capture_output=True, text=True, check=True)
Expand Down Expand Up @@ -146,6 +164,13 @@ def test_jsonlines(self):
self.assertEqual(process.stdout, self.jsonlines_expect)
self.assertEqual(process.stderr, '')

def test_jsonlines_emptylines(self):
args = sys.executable, '-m', 'json.tool', '--json-lines'
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
out, err = proc.communicate(self.jsonlines_emptylines_raw.encode())
self.assertEqual(out.splitlines(), self.jsonlines_emptylines_expect.encode().splitlines())
self.assertEqual(err, b'')

def test_help_flag(self):
rc, out, err = assert_python_ok('-m', 'json.tool', '-h')
self.assertEqual(rc, 0)
Expand Down