Beispiel #1
0
    def test_on_rm_rf_error(self, tmp_path):
        from _pytest.pathlib import on_rm_rf_error

        adir = tmp_path / "dir"
        adir.mkdir()

        fn = adir / "foo.txt"
        fn.touch()
        self.chmod_r(fn)

        # unknown exception
        with pytest.warns(pytest.PytestWarning):
            exc_info = (None, RuntimeError(), None)
            on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
            assert fn.is_file()

        # we ignore FileNotFoundError
        file_not_found = OSError()
        file_not_found.errno = errno.ENOENT
        exc_info = (None, file_not_found, None)
        assert not on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)

        permission_error = OSError()
        permission_error.errno = errno.EACCES
        # unknown function
        with pytest.warns(pytest.PytestWarning):
            exc_info = (None, permission_error, None)
            on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)
            assert fn.is_file()

        exc_info = (None, permission_error, None)
        on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
        assert not fn.is_file()
Beispiel #2
0
    def test_on_rm_rf_error(self, tmp_path):
        from _pytest.pathlib import on_rm_rf_error

        adir = tmp_path / "dir"
        adir.mkdir()

        fn = adir / "foo.txt"
        fn.touch()
        self.chmod_r(fn)

        # unknown exception
        with pytest.warns(pytest.PytestWarning):
            exc_info = (None, RuntimeError(), None)
            on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
            assert fn.is_file()

        # unknown function
        with pytest.warns(pytest.PytestWarning):
            exc_info = (None, PermissionError(), None)
            on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)
            assert fn.is_file()

        exc_info = (None, PermissionError(), None)
        on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
        assert not fn.is_file()
Beispiel #3
0
    def test_on_rm_rf_error(self, tmp_path: Path) -> None:
        adir = tmp_path / "dir"
        adir.mkdir()

        fn = adir / "foo.txt"
        fn.touch()
        self.chmod_r(fn)

        # unknown exception
        with pytest.warns(pytest.PytestWarning):
            exc_info1 = (None, RuntimeError(), None)
            on_rm_rf_error(os.unlink, str(fn), exc_info1, start_path=tmp_path)
            assert fn.is_file()

        # we ignore FileNotFoundError
        exc_info2 = (None, FileNotFoundError(), None)
        assert not on_rm_rf_error(
            None, str(fn), exc_info2, start_path=tmp_path)

        # unknown function
        with pytest.warns(
                pytest.PytestWarning,
                match=
                r"^\(rm_rf\) unknown function None when removing .*foo.txt:\nNone: ",
        ):
            exc_info3 = (None, PermissionError(), None)
            on_rm_rf_error(None, str(fn), exc_info3, start_path=tmp_path)
            assert fn.is_file()

        # ignored function
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            with pytest.warns(None) as warninfo:  # type: ignore[call-overload]
                exc_info4 = (None, PermissionError(), None)
                on_rm_rf_error(os.open,
                               str(fn),
                               exc_info4,
                               start_path=tmp_path)
                assert fn.is_file()
            assert not [x.message for x in warninfo]

        exc_info5 = (None, PermissionError(), None)
        on_rm_rf_error(os.unlink, str(fn), exc_info5, start_path=tmp_path)
        assert not fn.is_file()
Beispiel #4
0
    def test_on_rm_rf_error(self, tmp_path):
        from _pytest.pathlib import on_rm_rf_error

        adir = tmp_path / "dir"
        adir.mkdir()

        fn = adir / "foo.txt"
        fn.touch()
        self.chmod_r(fn)

        # unknown exception
        with pytest.warns(pytest.PytestWarning):
            exc_info = (None, RuntimeError(), None)
            on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
            assert fn.is_file()

        # we ignore FileNotFoundError
        exc_info = (None, FileNotFoundError(), None)
        assert not on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)

        # unknown function
        with pytest.warns(
                pytest.PytestWarning,
                match=
                r"^\(rm_rf\) unknown function None when removing .*foo.txt:\nNone: ",
        ):
            exc_info = (None, PermissionError(), None)
            on_rm_rf_error(None, str(fn), exc_info, start_path=tmp_path)
            assert fn.is_file()

        # ignored function
        with pytest.warns(None) as warninfo:
            exc_info = (None, PermissionError(), None)
            on_rm_rf_error(os.open, str(fn), exc_info, start_path=tmp_path)
            assert fn.is_file()
        assert not [x.message for x in warninfo]

        exc_info = (None, PermissionError(), None)
        on_rm_rf_error(os.unlink, str(fn), exc_info, start_path=tmp_path)
        assert not fn.is_file()