|
14 | 14 | from _pytest import pathlib |
15 | 15 | from _pytest.config import Config |
16 | 16 | from _pytest.monkeypatch import MonkeyPatch |
| 17 | +from _pytest.pathlib import _chmod_rwx |
17 | 18 | from _pytest.pathlib import cleanup_numbered_dir |
18 | 19 | from _pytest.pathlib import create_cleanup_lock |
19 | 20 | from _pytest.pathlib import make_numbered_dir |
@@ -668,6 +669,35 @@ def test_on_rm_rf_error_os_open_parent_perms(self, tmp_path: Path) -> None: |
668 | 669 | assert not child.exists() |
669 | 670 | assert not [x.message for x in w] |
670 | 671 |
|
| 672 | + def test_chmod_rwx_returns_false_on_nonexistent_path(self, tmp_path: Path) -> None: |
| 673 | + """_chmod_rwx returns False when the path doesn't exist (OSError).""" |
| 674 | + nonexistent = tmp_path / "does_not_exist" |
| 675 | + assert _chmod_rwx(str(nonexistent)) is False |
| 676 | + |
| 677 | + def test_chmod_rwx_returns_false_when_already_sufficient( |
| 678 | + self, tmp_path: Path |
| 679 | + ) -> None: |
| 680 | + """_chmod_rwx returns False when permissions are already sufficient.""" |
| 681 | + d = tmp_path / "dir" |
| 682 | + d.mkdir(mode=0o700) |
| 683 | + assert _chmod_rwx(str(d)) is False |
| 684 | + |
| 685 | + f = tmp_path / "file" |
| 686 | + f.touch(mode=0o600) |
| 687 | + assert _chmod_rwx(str(f)) is False |
| 688 | + |
| 689 | + def test_on_rm_rf_error_os_open_returns_false_when_chmod_ineffective( |
| 690 | + self, tmp_path: Path |
| 691 | + ) -> None: |
| 692 | + """os.open handler returns False when neither parent nor path chmod |
| 693 | + changes anything (recursion guard).""" |
| 694 | + adir = tmp_path / "dir" |
| 695 | + adir.mkdir(mode=0o700) |
| 696 | + exc_info = PermissionError() |
| 697 | + result = on_rm_rf_error(os.open, str(adir), exc_info, start_path=tmp_path) |
| 698 | + assert result is False |
| 699 | + assert adir.exists() |
| 700 | + |
671 | 701 |
|
672 | 702 | def attempt_symlink_to(path, to_path): |
673 | 703 | """Try to make a symlink from "path" to "to_path", skipping in case this platform |
|
0 commit comments