Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite8cfae8

Browse files
committed
Test that PermissionError is only wrapped on Windows
This changes tests in test_util to verify the opposite behaviorfrom what was enforced before, in the unusual case (that hopefullynever happens outside of monkey-patching in test_util.py itself)where the system is not Windows but HIDE_WINDOWS_KNOWN_ERRORS isset to True.The same-named environment variable will not, and never has, setHIDE_WINDOWS_KNOWN_ERRORS to True on non-Windows systems, but it ispossible to set it to True directly. Since it is named as aconstant and no documentation has ever suggested changing its valuedirectly, nor otherwise attempting to use it outside Windows, itshouldn't matter what happens in this unusual case. But assertingthat wrapping never occurs in this combination of circumstances iswhat makes the most sense in light of the recent change to pass nocallback to shutil.rmtree on non-Windows systems.
1 parent6de8e67 commite8cfae8

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

‎test/test_util.py

Lines changed: 13 additions & 6 deletions
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
assertold_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
deftest_wraps_perm_error_if_enabled(self,mocker,permission_error_tmpdir):
142-
"""rmtree wraps PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is true."""
142+
"""rmtree wraps PermissionErroron Windowswhen 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-
deftest_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+
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp