summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_json
diff options
context:
space:
mode:
authorHongWeipeng <961365124@qq.com>2018-11-07 10:09:32 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-11-07 10:09:32 (GMT)
commitf19447994983902aa88362d8fffe645f1ea2f2aa (patch)
tree28d11d764423c8838132f9f61f20fced054ddf6b /Lib/test/test_json
parent0e7497cb469b003a45a4abe4105b81ef6d0c4002 (diff)
downloadcpython-f19447994983902aa88362d8fffe645f1ea2f2aa.zip
cpython-f19447994983902aa88362d8fffe645f1ea2f2aa.tar.gz
cpython-f19447994983902aa88362d8fffe645f1ea2f2aa.tar.bz2
bpo-31553: add --json-lines option to json.tool (#10051)
* add jsonlines option to json.tool * code review * fix:avoid read infile after it close * improve doc in whatsnew 3.8
Diffstat (limited to 'Lib/test/test_json')
-rw-r--r--Lib/test/test_json/test_tool.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_json/test_tool.py b/Lib/test/test_json/test_tool.py
index 9d93f93..1e95bc7 100644
--- a/Lib/test/test_json/test_tool.py
+++ b/Lib/test/test_json/test_tool.py
@@ -60,6 +60,28 @@ class TestTool(unittest.TestCase):
]
""")
+ jsonlines_raw = textwrap.dedent("""\
+ {"ingredients":["frog", "water", "chocolate", "glucose"]}
+ {"ingredients":["chocolate","steel bolts"]}
+ """)
+
+ jsonlines_expect = textwrap.dedent("""\
+ {
+ "ingredients": [
+ "frog",
+ "water",
+ "chocolate",
+ "glucose"
+ ]
+ }
+ {
+ "ingredients": [
+ "chocolate",
+ "steel bolts"
+ ]
+ }
+ """)
+
def test_stdin_stdout(self):
args = sys.executable, '-m', 'json.tool'
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) as proc:
@@ -92,6 +114,13 @@ class TestTool(unittest.TestCase):
self.assertEqual(out, b'')
self.assertEqual(err, b'')
+ def test_jsonlines(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_raw.encode())
+ self.assertEqual(out.splitlines(), self.jsonlines_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)