Skip to content

Commit

Permalink
[PR #8619/d1c8dfbb backport][3.10] Fix monkey patches for pathlib cha…
Browse files Browse the repository at this point in the history
…nges in Python 3.13 (#8623)

Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
  • Loading branch information
patchback[bot] and steverep authored Aug 7, 2024
1 parent 06eedff commit a55d3e0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/8551.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed monkey patches for ``Path.stat()`` and ``Path.is_dir()`` for python 3.13 compatibility -- by :user:`steverep`.
8 changes: 4 additions & 4 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ def mock_iterdir(self: pathlib.Path) -> Generator[pathlib.Path, None, None]:
raise PermissionError()
return real_iterdir(self)

def mock_is_dir(self: pathlib.Path) -> bool:
def mock_is_dir(self: pathlib.Path, **kwargs: Any) -> bool:
if my_dir.samefile(self.parent):
raise PermissionError()
return real_is_dir(self)
return real_is_dir(self, **kwargs)

monkeypatch.setattr("pathlib.Path.iterdir", mock_iterdir)
monkeypatch.setattr("pathlib.Path.is_dir", mock_is_dir)
Expand Down Expand Up @@ -554,8 +554,8 @@ async def test_access_mock_special_resource(
real_result = my_special.stat()
real_stat = pathlib.Path.stat

def mock_stat(self: pathlib.Path) -> os.stat_result:
s = real_stat(self)
def mock_stat(self: pathlib.Path, **kwargs: Any) -> os.stat_result:
s = real_stat(self, **kwargs)
if os.path.samestat(s, real_result):
mock_mode = S_IFIFO | S_IMODE(s.st_mode)
s = os.stat_result([mock_mode] + list(s)[1:])
Expand Down

0 comments on commit a55d3e0

Please sign in to comment.