def test_get_file_stat_raise_value_error(mocker: MockerFixture, tmp_path: Path) -> None: """Test get_file_stat.""" mocker.patch.object(Path, "stat", PropertyMock(side_effect=IOError("msg"))) tmp_file = tmp_path / "test.txt" with pytest.raises(ValueError) as excinfo: get_file_stat(tmp_file) assert str( excinfo.value) == f"Could not retrieve file stat of {tmp_file}: msg"
def test_get_file_stat_handle_timestamp_error(exc: Exception, mocker: MockerFixture, tmp_path: Path) -> None: """Test get_file_stat.""" mocker.patch(f"{MODULE}.datetime", fromtimestamp=Mock(side_effect=exc)) tmp_file = tmp_path / "test.txt" tmp_file.write_text("foo") assert get_file_stat(tmp_file) == (3, None)
def test_on_done_modifies_utime(self, tmp_path: Path) -> None: """Test on_done.""" tmp_file = tmp_path / "test.txt" tmp_file.touch() future = FakeTransferFuture(meta=FakeTransferFutureMeta( call_args=FakeTransferFutureCallArgs(fileobj=tmp_file))) assert not self.subscriber.on_done(future) # type: ignore _, utime = get_file_stat(tmp_file) assert utime == self.desired_utime
def test_get_file_stat(tmp_path: Path) -> None: """Test get_file_stat.""" tmp_file = tmp_path / "test.txt" now = datetime.datetime.now(tzlocal()) epoch_now = time.mktime(now.timetuple()) tmp_file.write_text("foo") size, update_time = get_file_stat(tmp_file) assert size == 3 assert time.mktime(update_time.timetuple()) == epoch_now # type: ignore
def test_set_file_utime(tmp_path: Path) -> None: """Test set_file_utime.""" tmp_file = tmp_path / "test.txt" tmp_file.touch() now = datetime.datetime.now(tzlocal()) epoch_now = time.mktime(now.timetuple()) assert not set_file_utime(tmp_file, epoch_now) _, update_time = get_file_stat(tmp_file) assert time.mktime(update_time.timetuple()) == epoch_now # type: ignore