def test_write_existing_file(self, mocker: MockerFixture, fake_files): mock_open = mocker.mock_open() mocker.patch("builtins.open", mock_open) mocker.patch.object(Path, "exists", side_effect=[True]) open_latest("/path/to/file", mode="w") mock_open.assert_called_once_with(Path("/path/to/file-4"), mode="w", encoding="utf-8")
def test_should_open_in_append_mode_by_default(self, mocker: MockerFixture, fake_files): mock_open = mocker.mock_open() mocker.patch("builtins.open", mock_open) for _ in enumerate(open_latest("/path/to/foo.txt")): assert mock_open.call_args.kwargs["mode"] == "a"
def test_write_no_such_file(self, mocker: MockerFixture, fake_files): mocker.patch("builtins.open", mocker.mock_open()) mocker.patch.object(Path, "exists", side_effect=[False]) open_latest("/path/to/no-such-file", mode="w")
def test_read_no_such_file(self, mocker: MockerFixture, fake_files): mocker.patch.object(Path, "exists", side_effect=[False]) with pytest.raises(FileNotFoundError): open_latest("/path/to/no-such-file", mode="r")