Пример #1
0
 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")
Пример #2
0
 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"
Пример #3
0
 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")
Пример #4
0
 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")