@@ -54,15 +54,14 @@ def test_handle_build_dry_run():
5454def test_read_valid_json (mocker ):
5555 """Tests reading a valid JSON file."""
5656 mock_content = '{"key": "value"}'
57- mocker .patch ("os.path.exists" , return_value = True )
5857 mocker .patch ("builtins.open" , mocker .mock_open (read_data = mock_content ))
5958 result = _read_json_file ("fake/path.json" )
6059 assert result == {"key" : "value" }
6160
6261
6362def test_file_not_found (mocker ):
6463 """Tests behavior when the file does not exist."""
65- mocker .patch ("os.path.exists " , return_value = False )
64+ mocker .patch ("builtins.open " , side_effect = FileNotFoundError ( "No such file" ) )
6665
6766 with pytest .raises (FileNotFoundError ):
6867 _read_json_file ("non/existent/path.json" )
@@ -71,19 +70,7 @@ def test_file_not_found(mocker):
7170def test_invalid_json (mocker ):
7271 """Tests reading a file with malformed JSON."""
7372 mock_content = '{"key": "value",}'
74- mocker .patch ("os.path.exists" , return_value = True )
7573 mocker .patch ("builtins.open" , mocker .mock_open (read_data = mock_content ))
7674
7775 with pytest .raises (json .JSONDecodeError ):
7876 _read_json_file ("fake/path.json" )
79-
80-
81- def test_io_error_on_read (mocker ):
82- """Tests for a generic IOError."""
83- mocker .patch ("os.path.exists" , return_value = True )
84- mocked_open = mocker .mock_open ()
85- mocked_open .side_effect = IOError ("permission denied" )
86- mocker .patch ("builtins.open" , mocked_open )
87-
88- with pytest .raises (IOError ):
89- _read_json_file ("fake/path.json" )
0 commit comments