summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_json
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-11-06 18:01:17 (GMT)
committerGitHub <noreply@github.com>2021-11-06 18:01:17 (GMT)
commit6603f6b5bdf0ed164bad4eb432619da2e95fb518 (patch)
tree5235ee34b728843a4f24a1673e5194d023f18765 /Lib/test/test_json
parent804ea41211b042fa20c3cd8c0457bbfa3873128a (diff)
downloadcpython-6603f6b5bdf0ed164bad4eb432619da2e95fb518.zip
cpython-6603f6b5bdf0ed164bad4eb432619da2e95fb518.tar.gz
cpython-6603f6b5bdf0ed164bad4eb432619da2e95fb518.tar.bz2
bpo-45644: Make json.tool read infile before writing to outfile (GH-29273) (GH-29445)
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> (cherry picked from commit 815dad42d53fc40a6dc057e067f4a8a885c3b858) Co-authored-by: Chris Wesseling <chris.wesseling@protonmail.com>
Diffstat (limited to 'Lib/test/test_json')
-rw-r--r--Lib/test/test_json/test_tool.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_json/test_tool.py b/Lib/test/test_json/test_tool.py
index 0386690..1d7fca6 100644
--- a/Lib/test/test_json/test_tool.py
+++ b/Lib/test/test_json/test_tool.py
@@ -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)