Skip to content

Commit e309b35

Browse files
committed
Mock out lchmod functions in _patch_for_wrapping_test?
TestRmtree._patch_for_wrapping_test already mocked out the regular chmod functions in the os module and the Path class, to test what happens when changing permissions cannot fix an error. But there are also, on some systems and Python versions, lchmod versions of these functions. This patches those as well. I am not sure this should really be done. The problem is that calling such functions is fairly likely to raise an exception if it is not properly conditioned on a check for their actual usability, and mocking them out could obscure such a bug.
1 parent 5c6a4f4 commit e309b35

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Diff for: test/test_util.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,15 @@ def _patch_for_wrapping_test(self, mocker, hide_windows_known_errors):
140140
# git.index.util "replaces" git.util and is what "import git.util" gives us.
141141
mocker.patch.object(sys.modules["git.util"], "HIDE_WINDOWS_KNOWN_ERRORS", hide_windows_known_errors)
142142

143-
# Disable common chmod functions so the callback can't fix a PermissionError.
143+
# Disable some chmod functions so the callback can't fix a PermissionError.
144144
mocker.patch.object(os, "chmod")
145+
if hasattr(os, "lchmod"):
146+
# Exists on some operating systems. Mocking out os.chmod doesn't affect it.
147+
mocker.patch.object(os, "lchmod")
145148
mocker.patch.object(pathlib.Path, "chmod")
149+
if hasattr(pathlib.Path, "lchmod"):
150+
# Exists on some Python versions. Don't rely on it calling a public chmod.
151+
mocker.patch.object(pathlib.Path, "lchmod")
146152

147153
@pytest.mark.skipif(
148154
os.name != "nt",

0 commit comments

Comments
 (0)