test_shutil_wrapper.py 641 B

1234567891011121314151617181920212223
  1. import stat
  2. import sys
  3. from unittest.mock import Mock
  4. from setuptools import _shutil
  5. def test_rmtree_readonly(monkeypatch, tmp_path):
  6. """Verify onerr works as expected"""
  7. tmp_dir = tmp_path / "with_readonly"
  8. tmp_dir.mkdir()
  9. some_file = tmp_dir.joinpath("file.txt")
  10. some_file.touch()
  11. some_file.chmod(stat.S_IREAD)
  12. expected_count = 1 if sys.platform.startswith("win") else 0
  13. chmod_fn = Mock(wraps=_shutil.attempt_chmod_verbose)
  14. monkeypatch.setattr(_shutil, "attempt_chmod_verbose", chmod_fn)
  15. _shutil.rmtree(tmp_dir)
  16. assert chmod_fn.call_count == expected_count
  17. assert not tmp_dir.is_dir()