infile = open(options.infile, encoding='utf-8')
try:
if options.json_lines:
- objs = (json.loads(line) for line in infile)
+ lines = infile.readlines()
+ objs = (json.loads(line) for line in lines)
else:
objs = (json.load(infile),)
finally:
--- /dev/null
+{"ingredients":["frog", "water", "chocolate", "glucose"]}
+{"ingredients":["chocolate","steel bolts"]}
import errno
+import pathlib
import os
import sys
import textwrap
self.assertEqual(process.stdout, self.jsonlines_expect)
self.assertEqual(process.stderr, '')
+ @force_not_colorized
+ def test_jsonlines_from_file(self):
+ jsonl = pathlib.Path(__file__).parent / 'json_lines.jsonl'
+ args = sys.executable, '-m', self.module, '--json-lines', jsonl
+ process = subprocess.run(args, capture_output=True, text=True, check=True)
+ self.assertEqual(process.stdout, self.jsonlines_expect)
+ self.assertEqual(process.stderr, '')
+
def test_help_flag(self):
rc, out, err = assert_python_ok('-m', self.module, '-h',
PYTHON_COLORS='0')