Skip to content

Commit db2b206

Browse files
committed
Extract test for shutil.rmtree callback to its own file
1 parent bb93502 commit db2b206

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

setuptools/tests/test_bdist_wheel.py

+1-30
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@
1111
import sysconfig
1212
from contextlib import suppress
1313
from inspect import cleandoc
14-
from unittest.mock import Mock
1514
from zipfile import ZipFile
1615

1716
import jaraco.path
1817
import pytest
1918
from packaging import tags
2019

2120
import setuptools
22-
from setuptools.command.bdist_wheel import (
23-
bdist_wheel,
24-
get_abi_tag,
25-
remove_readonly,
26-
remove_readonly_exc,
27-
)
21+
from setuptools.command.bdist_wheel import bdist_wheel, get_abi_tag
2822
from setuptools.dist import Distribution
2923
from setuptools.warnings import SetuptoolsDeprecationWarning
3024

@@ -510,29 +504,6 @@ def test_platform_with_space(dummy_dist, monkeypatch):
510504
bdist_wheel_cmd(plat_name="isilon onefs").run()
511505

512506

513-
def test_rmtree_readonly(monkeypatch, tmp_path):
514-
"""Verify onerr works as expected"""
515-
516-
bdist_dir = tmp_path / "with_readonly"
517-
bdist_dir.mkdir()
518-
some_file = bdist_dir.joinpath("file.txt")
519-
some_file.touch()
520-
some_file.chmod(stat.S_IREAD)
521-
522-
expected_count = 1 if sys.platform.startswith("win") else 0
523-
524-
if sys.version_info < (3, 12):
525-
count_remove_readonly = Mock(side_effect=remove_readonly)
526-
shutil.rmtree(bdist_dir, onerror=count_remove_readonly)
527-
assert count_remove_readonly.call_count == expected_count
528-
else:
529-
count_remove_readonly_exc = Mock(side_effect=remove_readonly_exc)
530-
shutil.rmtree(bdist_dir, onexc=count_remove_readonly_exc)
531-
assert count_remove_readonly_exc.call_count == expected_count
532-
533-
assert not bdist_dir.is_dir()
534-
535-
536507
def test_data_dir_with_tag_build(monkeypatch, tmp_path):
537508
"""
538509
Setuptools allow authors to set PEP 440's local version segments
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import stat
2+
import sys
3+
from unittest.mock import Mock
4+
5+
from setuptools import _shutil
6+
7+
8+
def test_rmtree_readonly(monkeypatch, tmp_path):
9+
"""Verify onerr works as expected"""
10+
11+
tmp_dir = tmp_path / "with_readonly"
12+
tmp_dir.mkdir()
13+
some_file = tmp_dir.joinpath("file.txt")
14+
some_file.touch()
15+
some_file.chmod(stat.S_IREAD)
16+
17+
expected_count = 1 if sys.platform.startswith("win") else 0
18+
chmod_fn = Mock(wraps=_shutil.attempt_chmod_verbose)
19+
monkeypatch.setattr(_shutil, "attempt_chmod_verbose", chmod_fn)
20+
21+
_shutil.rmtree(tmp_dir)
22+
assert chmod_fn.call_count == expected_count
23+
assert not tmp_dir.is_dir()

0 commit comments

Comments
 (0)