codekingpro/portable-devtools
115k
1import stat2import sys3from unittest.mock import Mock4 5from setuptools import _shutil6 7 8def 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 018 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_count23 assert not tmp_dir.is_dir()24 