Skip to content

Commit e8cfae8

Browse files
committed
Test that PermissionError is only wrapped on Windows
This changes tests in test_util to verify the opposite behavior from what was enforced before, in the unusual case (that hopefully never happens outside of monkey-patching in test_util.py itself) where the system is not Windows but HIDE_WINDOWS_KNOWN_ERRORS is set to True. The same-named environment variable will not, and never has, set HIDE_WINDOWS_KNOWN_ERRORS to True on non-Windows systems, but it is possible to set it to True directly. Since it is named as a constant and no documentation has ever suggested changing its value directly, nor otherwise attempting to use it outside Windows, it shouldn't matter what happens in this unusual case. But asserting that wrapping never occurs in this combination of circumstances is what makes the most sense in light of the recent change to pass no callback to shutil.rmtree on non-Windows systems.
1 parent 6de8e67 commit e8cfae8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: test/test_util.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ def test_avoids_changing_permissions_outside_tree(self, tmp_path: pathlib.Path):
135135
assert old_mode == new_mode, f"Should stay {old_mode:#o}, became {new_mode:#o}."
136136

137137
@pytest.mark.skipif(
138-
sys.platform == "cygwin",
139-
reason="Cygwin can't set the permissions that make the test meaningful.",
138+
os.name != "nt",
139+
reason="PermissionError is only ever wrapped on Windows",
140140
)
141141
def test_wraps_perm_error_if_enabled(self, mocker, permission_error_tmpdir):
142-
"""rmtree wraps PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is true."""
142+
"""rmtree wraps PermissionError on Windows when HIDE_WINDOWS_KNOWN_ERRORS is true."""
143143
# Access the module through sys.modules so it is unambiguous which module's
144144
# attribute we patch: the original git.util, not git.index.util even though
145145
# git.index.util "replaces" git.util and is what "import git.util" gives us.
@@ -157,10 +157,17 @@ def test_wraps_perm_error_if_enabled(self, mocker, permission_error_tmpdir):
157157
sys.platform == "cygwin",
158158
reason="Cygwin can't set the permissions that make the test meaningful.",
159159
)
160-
def test_does_not_wrap_perm_error_unless_enabled(self, mocker, permission_error_tmpdir):
161-
"""rmtree does not wrap PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is false."""
160+
@pytest.mark.parametrize(
161+
"hide_windows_known_errors",
162+
[
163+
pytest.param(False),
164+
pytest.param(True, marks=pytest.mark.skipif(os.name == "nt", reason="We would wrap on Windows")),
165+
],
166+
)
167+
def test_does_not_wrap_perm_error_unless_enabled(self, mocker, permission_error_tmpdir, hide_windows_known_errors):
168+
"""rmtree does not wrap PermissionError on non-Windows systems or when HIDE_WINDOWS_KNOWN_ERRORS is false."""
162169
# See comments in test_wraps_perm_error_if_enabled for details about patching.
163-
mocker.patch.object(sys.modules["git.util"], "HIDE_WINDOWS_KNOWN_ERRORS", False)
170+
mocker.patch.object(sys.modules["git.util"], "HIDE_WINDOWS_KNOWN_ERRORS", hide_windows_known_errors)
164171
mocker.patch.object(os, "chmod")
165172
mocker.patch.object(pathlib.Path, "chmod")
166173

0 commit comments

Comments
 (0)