aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_pathlib/test_pathlib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2025-02-17 19:15:59 +0000
committerGitHub <noreply@github.com>2025-02-17 19:15:59 +0000
commit6f07016bf01366da5939c4029c91b7f37ddddd55 (patch)
tree346eadb8b4061933ef041322769f1a61aec21899 /Lib/test/test_pathlib/test_pathlib.py
parent7fcace99bbe1716c3e9713804e5bffaebdc8dd8f (diff)
downloadcpython-6f07016bf01366da5939c4029c91b7f37ddddd55.tar.gz
cpython-6f07016bf01366da5939c4029c91b7f37ddddd55.zip
GH-127381: pathlib ABCs: remove `ReadablePath.rglob()` (#130207)
Remove `ReadablePath.rglob()` from the private pathlib ABCs. This method is a trivial wrapper around `glob()` and easily replaced.
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib.py')
-rw-r--r--Lib/test/test_pathlib/test_pathlib.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py
index 8900b292ad0..182d054de9d 100644
--- a/Lib/test/test_pathlib/test_pathlib.py
+++ b/Lib/test/test_pathlib/test_pathlib.py
@@ -2766,6 +2766,64 @@ class PathTest(test_pathlib_abc.RWPathTest, PurePathTest):
_check(p, "*.txt", ["dirC/novel.txt"])
_check(p, "*.*", ["dirC/novel.txt"])
+ def test_rglob_recurse_symlinks_false(self):
+ def _check(path, glob, expected):
+ actual = set(path.rglob(glob, recurse_symlinks=False))
+ self.assertEqual(actual, { P(self.base, q) for q in expected })
+ P = self.cls
+ p = P(self.base)
+ it = p.rglob("fileA")
+ self.assertIsInstance(it, collections.abc.Iterator)
+ _check(p, "fileA", ["fileA"])
+ _check(p, "fileB", ["dirB/fileB"])
+ _check(p, "**/fileB", ["dirB/fileB"])
+ _check(p, "*/fileA", [])
+
+ if self.can_symlink:
+ _check(p, "*/fileB", ["dirB/fileB", "dirB/linkD/fileB",
+ "linkB/fileB", "dirA/linkC/fileB"])
+ _check(p, "*/", [
+ "dirA/", "dirA/linkC/", "dirB/", "dirB/linkD/", "dirC/",
+ "dirC/dirD/", "dirE/", "linkB/"])
+ else:
+ _check(p, "*/fileB", ["dirB/fileB"])
+ _check(p, "*/", ["dirA/", "dirB/", "dirC/", "dirC/dirD/", "dirE/"])
+
+ _check(p, "file*", ["fileA", "dirB/fileB", "dirC/fileC", "dirC/dirD/fileD"])
+ _check(p, "", ["", "dirA/", "dirB/", "dirC/", "dirE/", "dirC/dirD/"])
+ p = P(self.base, "dirC")
+ _check(p, "*", ["dirC/fileC", "dirC/novel.txt",
+ "dirC/dirD", "dirC/dirD/fileD"])
+ _check(p, "file*", ["dirC/fileC", "dirC/dirD/fileD"])
+ _check(p, "**/file*", ["dirC/fileC", "dirC/dirD/fileD"])
+ _check(p, "dir*/**", ["dirC/dirD/", "dirC/dirD/fileD"])
+ _check(p, "dir*/**/", ["dirC/dirD/"])
+ _check(p, "*/*", ["dirC/dirD/fileD"])
+ _check(p, "*/", ["dirC/dirD/"])
+ _check(p, "", ["dirC/", "dirC/dirD/"])
+ _check(p, "**", ["dirC/", "dirC/fileC", "dirC/dirD", "dirC/dirD/fileD", "dirC/novel.txt"])
+ _check(p, "**/", ["dirC/", "dirC/dirD/"])
+ # gh-91616, a re module regression
+ _check(p, "*.txt", ["dirC/novel.txt"])
+ _check(p, "*.*", ["dirC/novel.txt"])
+
+ @needs_posix
+ def test_rglob_posix(self):
+ P = self.cls
+ p = P(self.base, "dirC")
+ q = p / "dirD" / "FILEd"
+ given = set(p.rglob("FILEd"))
+ expect = {q} if q.exists() else set()
+ self.assertEqual(given, expect)
+ self.assertEqual(set(p.rglob("FILEd*")), set())
+
+ @needs_windows
+ def test_rglob_windows(self):
+ P = self.cls
+ p = P(self.base, "dirC")
+ self.assertEqual(set(p.rglob("FILEd")), { P(self.base, "dirC/dirD/fileD") })
+ self.assertEqual(set(p.rglob("*\\")), { P(self.base, "dirC/dirD/") })
+
@needs_symlinks
def test_rglob_symlink_loop(self):
# Don't get fooled by symlink loops (Issue #26012).