11import re
2+ from io import StringIO
23from pathlib import Path
4+ from shutil import copy
35
46import pytest
57
@@ -139,6 +141,28 @@ def test_output(script_runner, tmp_path):
139141 assert tmp_file .read_text () == '{ "bools": {"true": true, "false": false} }\n '
140142
141143
144+ def test_in_place (script_runner , tmp_path ):
145+ tmp_file = tmp_path / "test.json"
146+ copy (Path ("tests/data/test-bool.json" ), tmp_file )
147+ ret = script_runner .run (
148+ ["fractured-json" , "--in-place" , tmp_file ],
149+ )
150+ assert ret .stderr == ""
151+ assert ret .success
152+ assert tmp_file .read_text () == '{ "bools": {"true": true, "false": false} }\n '
153+
154+ timestamp = tmp_file .stat ().st_mtime_ns
155+
156+ ret = script_runner .run (
157+ ["fractured-json" , "--in-place" , tmp_file ],
158+ )
159+ assert ret .stderr == ""
160+ assert ret .success
161+ assert tmp_file .read_text () == '{ "bools": {"true": true, "false": false} }\n '
162+
163+ assert timestamp == tmp_file .stat ().st_mtime_ns
164+
165+
142166def test_output_mismatched_number_of_files (script_runner ):
143167 ret = script_runner .run (
144168 [
@@ -152,3 +176,22 @@ def test_output_mismatched_number_of_files(script_runner):
152176 )
153177 assert ret .stderr == "fractured-json: the numbers of input and output file names do not match\n "
154178 assert ret .returncode == 1
179+
180+
181+ def test_pipe_stdin (script_runner ):
182+ json_input_fh = StringIO (Path ("tests/data/test-bool.json" ).read_text ())
183+ ret = script_runner .run (["fractured-json" , "-" ], stdin = json_input_fh )
184+ assert ret .success
185+ assert ret .stderr == ""
186+ assert ret .success
187+ assert ret .stdout == '{ "bools": {"true": true, "false": false} }\n '
188+
189+
190+ def test_missing_file (script_runner , tmp_path ):
191+ tmp_file = tmp_path / "test.json"
192+ ret = script_runner .run (
193+ ["fractured-json" , "file-does-not-exist.json" ],
194+ )
195+ assert not ret .success
196+ assert "[Errno 2] No such file or directory: 'file-does-not-exist.json'" in ret .stderr
197+ assert ret .stdout == ""
0 commit comments