Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e309b35

Browse filesBrowse 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
Copy full SHA for e309b35

File tree

Expand file treeCollapse file tree

1 file changed

+7
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-1
lines changed

‎test/test_util.py

Copy file name to clipboardExpand all lines: test/test_util.py
+7-1Lines changed: 7 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.