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

Commitd42cd72

Browse files
committed
Test situations git.util.rmtree shouldn't wrap
One of the new test cases fails, showing the bug wheregit.util.rmtree wraps any exception in SkipTest whenHIDE_WINDOWS_KNOWN_ERRORS is true, even though the message it uses(and its purpose) is specific to PermissionError.The other new cases pass, because wrapping exceptions in SkipTestrightly does not occur when HIDE_WINDOWS_KNOWN_ERRORS is false.
1 parent2fe7f3c commitd42cd72

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

‎test/test_util.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: https://opensource.org/license/bsd-3-clause/
66

7+
importcontextlib
78
importos
89
importpathlib
910
importpickle
@@ -121,16 +122,31 @@ def test_rmtree_deletes_dir_with_readonly_files(self):
121122

122123
self.assertFalse(td.exists())
123124

124-
@skipIf(sys.platform=="cygwin","Cygwin can't set the permissions that make the test meaningful.")
125-
@skipIf(sys.version_info< (3,8),"In 3.7, TemporaryDirectory doesn't clean up after weird permissions.")
126-
deftest_rmtree_can_wrap_exceptions(self):
125+
@staticmethod
126+
@contextlib.contextmanager
127+
def_tmpdir_to_force_permission_error():
128+
ifsys.platform=="cygwin":
129+
raiseSkipTest("Cygwin can't set the permissions that make the test meaningful.")
130+
ifsys.version_info< (3,8):
131+
raiseSkipTest("In 3.7, TemporaryDirectory doesn't clean up after weird permissions.")
132+
127133
withtempfile.TemporaryDirectory()asparent:
128134
td=pathlib.Path(parent,"testdir")
129135
td.mkdir()
130136
(td/"x").write_bytes(b"")
131137
(td/"x").chmod(stat.S_IRUSR)# Set up PermissionError on Windows.
132138
td.chmod(stat.S_IRUSR|stat.S_IXUSR)# Set up PermissionError on Unix.
139+
yieldtd
133140

141+
@staticmethod
142+
@contextlib.contextmanager
143+
def_tmpdir_for_file_not_found():
144+
withtempfile.TemporaryDirectory()asparent:
145+
yieldpathlib.Path(parent,"testdir")# It is deliberately never created.
146+
147+
deftest_rmtree_can_wrap_exceptions(self):
148+
"""Our rmtree wraps PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is true."""
149+
withself._tmpdir_to_force_permission_error()astd:
134150
# Access the module through sys.modules so it is unambiguous which module's
135151
# attribute we patch: the original git.util, not git.index.util even though
136152
# git.index.util "replaces" git.util and is what "import git.util" gives us.
@@ -141,6 +157,25 @@ def test_rmtree_can_wrap_exceptions(self):
141157
withself.assertRaises(SkipTest):
142158
rmtree(td)
143159

160+
@ddt.data(
161+
(False,PermissionError,_tmpdir_to_force_permission_error),
162+
(False,FileNotFoundError,_tmpdir_for_file_not_found),
163+
(True,FileNotFoundError,_tmpdir_for_file_not_found),
164+
)
165+
deftest_rmtree_does_not_wrap_unless_called_for(self,case):
166+
"""Our rmtree doesn't wrap non-PermissionError, nor when HIDE_WINDOWS_KNOWN_ERRORS is false."""
167+
hide_windows_known_errors,exception_type,tmpdir_context_factory=case
168+
169+
withtmpdir_context_factory()astd:
170+
# See comments in test_rmtree_can_wrap_exceptions regarding the patching done here.
171+
withmock.patch.object(sys.modules["git.util"],"HIDE_WINDOWS_KNOWN_ERRORS",hide_windows_known_errors):
172+
withmock.patch.object(os,"chmod"),mock.patch.object(pathlib.Path,"chmod"):
173+
withself.assertRaises(exception_type):
174+
try:
175+
rmtree(td)
176+
exceptSkipTestasex:
177+
self.fail(f"rmtree unexpectedly attempts skip:{ex!r}")
178+
144179
# FIXME: Mark only the /proc-prefixing cases xfail, somehow (or fix them).
145180
@pytest.mark.xfail(
146181
reason="Many return paths prefixed /proc/cygdrive instead.",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp