Skip to content

Commit

Permalink
Extract test for shutil.rmtree callback to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Nov 11, 2024
1 parent bb93502 commit db2b206
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
31 changes: 1 addition & 30 deletions setuptools/tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,14 @@
import sysconfig
from contextlib import suppress
from inspect import cleandoc
from unittest.mock import Mock
from zipfile import ZipFile

import jaraco.path
import pytest
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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions setuptools/tests/test_shutil_wrapper.py
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()

0 comments on commit db2b206

Please sign in to comment.