summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-01-27 19:59:51 (GMT)
committerGitHub <noreply@github.com>2024-01-27 19:59:51 (GMT)
commit823a38a960c245cbf309ef29120d3690ba1bcd2c (patch)
tree71d67154b8df245aa6256a2fb45a20254f743048 /Lib/test/test_pathlib
parent7a470541e2bbc6f3e87a6d813e2ec42cf726de7a (diff)
downloadcpython-823a38a960c245cbf309ef29120d3690ba1bcd2c.zip
cpython-823a38a960c245cbf309ef29120d3690ba1bcd2c.tar.gz
cpython-823a38a960c245cbf309ef29120d3690ba1bcd2c.tar.bz2
GH-79634: Speed up pathlib globbing by removing `joinpath()` call. (#114623)
Remove `self.joinpath('')` call that should have been removed in 6313cdde. This makes `PathBase.glob('')` yield itself *without* adding a trailing slash. It's hard to say whether this is more or less correct, but at least everything else is faster, and there's no behaviour change in the public classes where empty glob patterns are disallowed.
Diffstat (limited to 'Lib/test/test_pathlib')
-rw-r--r--Lib/test/test_pathlib/test_pathlib.py2
-rw-r--r--Lib/test/test_pathlib/test_pathlib_abc.py7
2 files changed, 5 insertions, 4 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib.py b/Lib/test/test_pathlib/test_pathlib.py
index 9c2b26d..5ce3b60 100644
--- a/Lib/test/test_pathlib/test_pathlib.py
+++ b/Lib/test/test_pathlib/test_pathlib.py
@@ -1232,6 +1232,8 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
list(p.glob(''))
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
list(p.glob('.'))
+ with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
+ list(p.glob('./'))
def test_glob_many_open_files(self):
depth = 30
diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py
index ea70931..ab989cb 100644
--- a/Lib/test/test_pathlib/test_pathlib_abc.py
+++ b/Lib/test/test_pathlib/test_pathlib_abc.py
@@ -1733,12 +1733,11 @@ class DummyPathTest(DummyPurePathTest):
self.assertEqual(set(map(str, p.glob("F*a"))), {f"{p}\\fileA"})
def test_glob_empty_pattern(self):
- def _check(glob, expected):
- self.assertEqual(set(glob), { P(self.base, q) for q in expected })
P = self.cls
p = P(self.base)
- _check(p.glob(""), [""])
- _check(p.glob("."), ["."])
+ self.assertEqual(list(p.glob("")), [p])
+ self.assertEqual(list(p.glob(".")), [p / "."])
+ self.assertEqual(list(p.glob("./")), [p / "./"])
def test_glob_case_sensitive(self):
P = self.cls