Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix broken test_glob_permissions test.
  • Loading branch information
barneygale committed Jan 1, 2022
commit 3dfefdfee037205809c69e208cc51bf023cc4a92
24 changes: 11 additions & 13 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import collections.abc
import io
import os
Expand Down Expand Up @@ -1716,21 +1717,18 @@ def test_glob_permissions(self):
# Patching is needed to avoid relying on the filesystem
# to return the order of the files as the error will not
# happen if the symlink is the last item.

with mock.patch("os.scandir") as scandir:
scandir.return_value = sorted(os.scandir(base))
real_scandir = os.scandir
def my_scandir(path):
with real_scandir(path) as scandir_it:
entries = list(scandir_it)
entries.sort(key=lambda entry: entry.name)
return contextlib.nullcontext(entries)

with mock.patch("os.scandir", my_scandir):
self.assertEqual(len(set(base.glob("*"))), 3)

subdir.mkdir()

with mock.patch("os.scandir") as scandir:
scandir.return_value = sorted(os.scandir(base))
subdir.mkdir()
self.assertEqual(len(set(base.glob("*"))), 4)

subdir.chmod(000)

with mock.patch("os.scandir") as scandir:
scandir.return_value = sorted(os.scandir(base))
subdir.chmod(000)
self.assertEqual(len(set(base.glob("*"))), 4)

def _check_resolve(self, p, expected, strict=True):
Expand Down