diff options
| author | Barney Gale <barney.gale@gmail.com> | 2023-05-11 00:01:39 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-11 00:01:39 (GMT) |
| commit | 94f30c75576bb8a20724b2ac758fa33af089a522 (patch) | |
| tree | e6c33824c353d12ff76eafd1af69d1d2aa834760 /Lib/test/test_pathlib.py | |
| parent | 373bca0cc5256dc512ffc22bdff4424f7ee8baa2 (diff) | |
| download | cpython-94f30c75576bb8a20724b2ac758fa33af089a522.zip cpython-94f30c75576bb8a20724b2ac758fa33af089a522.tar.gz cpython-94f30c75576bb8a20724b2ac758fa33af089a522.tar.bz2 | |
GH-90208: Suppress OSError exceptions from `pathlib.Path.glob()` (GH-104141)
`pathlib.Path.glob()` now suppresses all OSError exceptions, except
those raised from calling `is_dir()` on the top-level path.
Previously, `glob()` suppressed ENOENT, ENOTDIR, EBADF and ELOOP
errors and their Windows equivalents. PermissionError was also
suppressed unless it occurred when calling `is_dir()` on the
top-level path. However, the selector would abort prematurely
if a PermissionError was raised, and so `glob()` could return
incomplete results.
Diffstat (limited to 'Lib/test/test_pathlib.py')
| -rw-r--r-- | Lib/test/test_pathlib.py | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index 10dd604..67ca479 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -1949,33 +1949,19 @@ class _BasePathTest(object): P = self.cls base = P(BASE) / 'permissions' base.mkdir() + self.addCleanup(os_helper.rmtree, base) - file1 = base / "file1" - file1.touch() - file2 = base / "file2" - file2.touch() - - subdir = base / "subdir" - - file3 = base / "file3" - file3.symlink_to(subdir / "other") - - # 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. - 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() - self.assertEqual(len(set(base.glob("*"))), 4) - subdir.chmod(000) - self.assertEqual(len(set(base.glob("*"))), 4) + for i in range(100): + link = base / f"link{i}" + if i % 2: + link.symlink_to(P(BASE, "dirE", "nonexistent")) + else: + link.symlink_to(P(BASE, "dirC")) + + self.assertEqual(len(set(base.glob("*"))), 100) + self.assertEqual(len(set(base.glob("*/"))), 50) + self.assertEqual(len(set(base.glob("*/fileC"))), 50) + self.assertEqual(len(set(base.glob("*/file*"))), 50) @os_helper.skip_unless_symlink def test_glob_long_symlink(self): |
