aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_pathlib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2025-03-10 17:50:48 +0000
committerGitHub <noreply@github.com>2025-03-10 17:50:48 +0000
commit93fc3d34f9285d337c1e19e84764b02629eaab68 (patch)
tree65861eaa604ea59cc6e3d934c5f79a13d2348475 /Lib/test/test_pathlib
parentc3487c941dfa252bde7e69f9d953d4ca9a56408d (diff)
downloadcpython-93fc3d34f9285d337c1e19e84764b02629eaab68.tar.gz
cpython-93fc3d34f9285d337c1e19e84764b02629eaab68.zip
GH-127381: pathlib ABCs: remove `case_sensitive` argument (#131024)
Remove the *case_sensitive* argument from `_JoinablePath.full_match()` and `_ReadablePath.glob()`. Using a non-native case sensitivity forces the use of "case-pedantic" globbing, where we `iterdir()` even for non-wildcard pattern segments. But it's hard to know when to enable this mode, as case-sensitivity can vary by directory, so `_PathParser.normcase()` doesn't always give the full picture. The `Path.glob()` implementation is forced to make an educated guess, but we can avoid the issue in the ABCs by dropping the *case_sensitive* argument. (I probably shouldn't have added these arguments in `PurePath` and `Path` in the first place!) Also drop support for `_ReadablePath.glob(recurse_symlinks=False)`, which makes recursive globbing much slower.
Diffstat (limited to 'Lib/test/test_pathlib')
-rw-r--r--Lib/test/test_pathlib/test_join.py5
-rw-r--r--Lib/test/test_pathlib/test_pathlib.py19
-rw-r--r--Lib/test/test_pathlib/test_pathlib_abc.py12
3 files changed, 19 insertions, 17 deletions
diff --git a/Lib/test/test_pathlib/test_join.py b/Lib/test/test_pathlib/test_join.py
index 93fd1e6488c..03a3ecfd248 100644
--- a/Lib/test/test_pathlib/test_join.py
+++ b/Lib/test/test_pathlib/test_join.py
@@ -130,11 +130,6 @@ class JoinTestBase:
self.assertFalse(P('a/b/c.py').full_match('**/a/b/c./**'))
self.assertFalse(P('a/b/c.py').full_match('/a/b/c.py/**'))
self.assertFalse(P('a/b/c.py').full_match('/**/a/b/c.py'))
- # Case-sensitive flag
- self.assertFalse(P('A.py').full_match('a.PY', case_sensitive=True))
- self.assertTrue(P('A.py').full_match('a.PY', case_sensitive=False))
- self.assertFalse(P('c:/a/B.Py').full_match('C:/A/*.pY', case_sensitive=True))
- self.assertTrue(P('/a/b/c.py').full_match('/A/*/*.Py', case_sensitive=False))
# Matching against empty path
self.assertFalse(P('').full_match('*'))
self.assertTrue(P('').full_match('**'))
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py
index 830bfa4ca78..1996bbb65a3 100644
--- a/Lib/test/test_pathlib/test_pathlib.py
+++ b/Lib/test/test_pathlib/test_pathlib.py
@@ -433,6 +433,13 @@ class PurePathTest(test_pathlib_abc.JoinablePathTest):
with self.assertWarns(DeprecationWarning):
p.is_reserved()
+ def test_full_match_case_sensitive(self):
+ P = self.cls
+ self.assertFalse(P('A.py').full_match('a.PY', case_sensitive=True))
+ self.assertTrue(P('A.py').full_match('a.PY', case_sensitive=False))
+ self.assertFalse(P('c:/a/B.Py').full_match('C:/A/*.pY', case_sensitive=True))
+ self.assertTrue(P('/a/b/c.py').full_match('/A/*/*.Py', case_sensitive=False))
+
def test_match_empty(self):
P = self.cls
self.assertRaises(ValueError, P('a').match, '')
@@ -2737,6 +2744,18 @@ class PathTest(test_pathlib_abc.RWPathTest, PurePathTest):
self.assertEqual(expect, set(p.glob(P(pattern))))
self.assertEqual(expect, set(p.glob(FakePath(pattern))))
+ def test_glob_case_sensitive(self):
+ P = self.cls
+ def _check(path, pattern, case_sensitive, expected):
+ actual = {str(q) for q in path.glob(pattern, case_sensitive=case_sensitive)}
+ expected = {str(P(self.base, q)) for q in expected}
+ self.assertEqual(actual, expected)
+ path = P(self.base)
+ _check(path, "DIRB/FILE*", True, [])
+ _check(path, "DIRB/FILE*", False, ["dirB/fileB"])
+ _check(path, "dirb/file*", True, [])
+ _check(path, "dirb/file*", False, ["dirB/fileB"])
+
@needs_symlinks
def test_glob_dot(self):
P = self.cls
diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py
index c6038d61b89..1b9db475138 100644
--- a/Lib/test/test_pathlib/test_pathlib_abc.py
+++ b/Lib/test/test_pathlib/test_pathlib_abc.py
@@ -709,18 +709,6 @@ class ReadablePathTest(JoinablePathTest):
p = P(self.base)
self.assertEqual(list(p.glob("")), [p.joinpath("")])
- def test_glob_case_sensitive(self):
- P = self.cls
- def _check(path, pattern, case_sensitive, expected):
- actual = {str(q) for q in path.glob(pattern, case_sensitive=case_sensitive)}
- expected = {str(P(self.base, q)) for q in expected}
- self.assertEqual(actual, expected)
- path = P(self.base)
- _check(path, "DIRB/FILE*", True, [])
- _check(path, "DIRB/FILE*", False, ["dirB/fileB"])
- _check(path, "dirb/file*", True, [])
- _check(path, "dirb/file*", False, ["dirB/fileB"])
-
def test_info_exists(self):
p = self.cls(self.base)
self.assertTrue(p.info.exists())