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

Commit2a32e25

Browse files
committed
Fix test bug that assumed staticmethod callability
staticmethod objects are descriptors that cause the same-namedattribute on a class or its instances to be callable (and the firstargument, representing a class or instance, not to be passed). Butthe actual staticmethod objects themselves are only callablestarting in Python 3.10. This reorgnizes the just-added test codeso it no longer wrongly relies on being able to call such objects.
1 parentd42cd72 commit2a32e25

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

‎test/test_util.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ def __repr__(self):
8080
return"TestIterableMember(%r)"%self.name
8181

8282

83+
@contextlib.contextmanager
84+
def_tmpdir_to_force_permission_error():
85+
"""Context manager to test permission errors in situations where we do not fix them."""
86+
ifsys.platform=="cygwin":
87+
raiseSkipTest("Cygwin can't set the permissions that make the test meaningful.")
88+
ifsys.version_info< (3,8):
89+
raiseSkipTest("In 3.7, TemporaryDirectory doesn't clean up after weird permissions.")
90+
91+
withtempfile.TemporaryDirectory()asparent:
92+
td=pathlib.Path(parent,"testdir")
93+
td.mkdir()
94+
(td/"x").write_bytes(b"")
95+
(td/"x").chmod(stat.S_IRUSR)# Set up PermissionError on Windows.
96+
td.chmod(stat.S_IRUSR|stat.S_IXUSR)# Set up PermissionError on Unix.
97+
yieldtd
98+
99+
100+
@contextlib.contextmanager
101+
def_tmpdir_for_file_not_found():
102+
"""Context manager to test errors deleting a directory that are not due to permissions."""
103+
withtempfile.TemporaryDirectory()asparent:
104+
yieldpathlib.Path(parent,"testdir")# It is deliberately never created.
105+
106+
83107
@ddt.ddt
84108
classTestUtils(TestBase):
85109
defsetup(self):
@@ -107,6 +131,7 @@ def test_rmtree_deletes_nested_dir_with_files(self):
107131
@skipIf(sys.platform=="cygwin","Cygwin can't set the permissions that make the test meaningful.")
108132
deftest_rmtree_deletes_dir_with_readonly_files(self):
109133
# Automatically works on Unix, but requires special handling on Windows.
134+
# Not to be confused with _tmpdir_to_force_permission_error (which is used below).
110135
withtempfile.TemporaryDirectory()asparent:
111136
td=pathlib.Path(parent,"testdir")
112137
fordintd,td/"sub":
@@ -122,31 +147,9 @@ def test_rmtree_deletes_dir_with_readonly_files(self):
122147

123148
self.assertFalse(td.exists())
124149

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-
133-
withtempfile.TemporaryDirectory()asparent:
134-
td=pathlib.Path(parent,"testdir")
135-
td.mkdir()
136-
(td/"x").write_bytes(b"")
137-
(td/"x").chmod(stat.S_IRUSR)# Set up PermissionError on Windows.
138-
td.chmod(stat.S_IRUSR|stat.S_IXUSR)# Set up PermissionError on Unix.
139-
yieldtd
140-
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-
147150
deftest_rmtree_can_wrap_exceptions(self):
148151
"""Our rmtree wraps PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is true."""
149-
withself._tmpdir_to_force_permission_error()astd:
152+
with_tmpdir_to_force_permission_error()astd:
150153
# Access the module through sys.modules so it is unambiguous which module's
151154
# attribute we patch: the original git.util, not git.index.util even though
152155
# git.index.util "replaces" git.util and is what "import git.util" gives us.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp