diff --git a/setuptools/tests/test_bdist_wheel.py b/setuptools/tests/test_bdist_wheel.py index 3dfa9c850c..d51dfbeb6d 100644 --- a/setuptools/tests/test_bdist_wheel.py +++ b/setuptools/tests/test_bdist_wheel.py @@ -11,7 +11,6 @@ import sysconfig from contextlib import suppress from inspect import cleandoc -from unittest.mock import Mock from zipfile import ZipFile import jaraco.path @@ -19,12 +18,7 @@ from packaging import tags import setuptools -from setuptools.command.bdist_wheel import ( - bdist_wheel, - get_abi_tag, - remove_readonly, - remove_readonly_exc, -) +from setuptools.command.bdist_wheel import bdist_wheel, get_abi_tag from setuptools.dist import Distribution from setuptools.warnings import SetuptoolsDeprecationWarning @@ -510,29 +504,6 @@ def test_platform_with_space(dummy_dist, monkeypatch): bdist_wheel_cmd(plat_name="isilon onefs").run() -def test_rmtree_readonly(monkeypatch, tmp_path): - """Verify onerr works as expected""" - - bdist_dir = tmp_path / "with_readonly" - bdist_dir.mkdir() - some_file = bdist_dir.joinpath("file.txt") - some_file.touch() - some_file.chmod(stat.S_IREAD) - - expected_count = 1 if sys.platform.startswith("win") else 0 - - if sys.version_info < (3, 12): - count_remove_readonly = Mock(side_effect=remove_readonly) - shutil.rmtree(bdist_dir, onerror=count_remove_readonly) - assert count_remove_readonly.call_count == expected_count - else: - count_remove_readonly_exc = Mock(side_effect=remove_readonly_exc) - shutil.rmtree(bdist_dir, onexc=count_remove_readonly_exc) - assert count_remove_readonly_exc.call_count == expected_count - - assert not bdist_dir.is_dir() - - def test_data_dir_with_tag_build(monkeypatch, tmp_path): """ Setuptools allow authors to set PEP 440's local version segments diff --git a/setuptools/tests/test_shutil_wrapper.py b/setuptools/tests/test_shutil_wrapper.py new file mode 100644 index 0000000000..74ff7e9a89 --- /dev/null +++ b/setuptools/tests/test_shutil_wrapper.py @@ -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()