mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
bpo-45644: Make json.tool read infile before writing to outfile (GH-29273)
so that $ python -m json.tool foo.json foo.json doesn't result in an empty foo.json. Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
e9594f6747
commit
815dad42d5
3 changed files with 26 additions and 7 deletions
|
@ -131,6 +131,15 @@ class TestTool(unittest.TestCase):
|
|||
self.assertEqual(out, b'')
|
||||
self.assertEqual(err, b'')
|
||||
|
||||
def test_writing_in_place(self):
|
||||
infile = self._create_infile()
|
||||
rc, out, err = assert_python_ok('-m', 'json.tool', infile, infile)
|
||||
with open(infile, "r", encoding="utf-8") as fp:
|
||||
self.assertEqual(fp.read(), self.expect)
|
||||
self.assertEqual(rc, 0)
|
||||
self.assertEqual(out, b'')
|
||||
self.assertEqual(err, b'')
|
||||
|
||||
def test_jsonlines(self):
|
||||
args = sys.executable, '-m', 'json.tool', '--json-lines'
|
||||
process = subprocess.run(args, input=self.jsonlines_raw, capture_output=True, text=True, check=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue