-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract test for shutil.rmtree callback to its own file
- Loading branch information
1 parent
bb93502
commit db2b206
Showing
2 changed files
with
24 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import stat | ||
import sys | ||
from unittest.mock import Mock | ||
|
||
from setuptools import _shutil | ||
|
||
|
||
def test_rmtree_readonly(monkeypatch, tmp_path): | ||
"""Verify onerr works as expected""" | ||
|
||
tmp_dir = tmp_path / "with_readonly" | ||
tmp_dir.mkdir() | ||
some_file = tmp_dir.joinpath("file.txt") | ||
some_file.touch() | ||
some_file.chmod(stat.S_IREAD) | ||
|
||
expected_count = 1 if sys.platform.startswith("win") else 0 | ||
chmod_fn = Mock(wraps=_shutil.attempt_chmod_verbose) | ||
monkeypatch.setattr(_shutil, "attempt_chmod_verbose", chmod_fn) | ||
|
||
_shutil.rmtree(tmp_dir) | ||
assert chmod_fn.call_count == expected_count | ||
assert not tmp_dir.is_dir() |