summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pathlib/test_pathlib_abc.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-01-08 19:31:52 (GMT)
committerGitHub <noreply@github.com>2024-01-08 19:31:52 (GMT)
commitb3dba18eab96dc95653031863bb2a222af912f2b (patch)
tree99b47c48bba41f56492fdaa18a36ad478eaa12da /Lib/test/test_pathlib/test_pathlib_abc.py
parentbc71ae2b97bb59b1796be056fb821d9abdee840b (diff)
downloadcpython-b3dba18eab96dc95653031863bb2a222af912f2b.zip
cpython-b3dba18eab96dc95653031863bb2a222af912f2b.tar.gz
cpython-b3dba18eab96dc95653031863bb2a222af912f2b.tar.bz2
GH-113528: Speed up pathlib ABC tests. (#113788)
- Add `__slots__` to dummy path classes. - Return namedtuple rather than `os.stat_result` from `DummyPath.stat()`. - Reduce maximum symlink count in `DummyPathWithSymlinks.resolve()`.
Diffstat (limited to 'Lib/test/test_pathlib/test_pathlib_abc.py')
-rw-r--r--Lib/test/test_pathlib/test_pathlib_abc.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py
index f33d497..b088be8 100644
--- a/Lib/test/test_pathlib/test_pathlib_abc.py
+++ b/Lib/test/test_pathlib/test_pathlib_abc.py
@@ -1,4 +1,4 @@
-import collections.abc
+import collections
import io
import os
import errno
@@ -43,6 +43,8 @@ class PurePathBaseTest(unittest.TestCase):
class DummyPurePath(PurePathBase):
+ __slots__ = ()
+
def __eq__(self, other):
if not isinstance(other, DummyPurePath):
return NotImplemented
@@ -660,11 +662,18 @@ class DummyPathIO(io.BytesIO):
super().close()
+DummyPathStatResult = collections.namedtuple(
+ 'DummyPathStatResult',
+ 'st_mode st_ino st_dev st_nlink st_uid st_gid st_size st_atime st_mtime st_ctime')
+
+
class DummyPath(PathBase):
"""
Simple implementation of PathBase that keeps files and directories in
memory.
"""
+ __slots__ = ()
+
_files = {}
_directories = {}
_symlinks = {}
@@ -693,7 +702,7 @@ class DummyPath(PathBase):
st_mode = stat.S_IFLNK
else:
raise FileNotFoundError(errno.ENOENT, "Not found", str(self))
- return os.stat_result((st_mode, hash(str(self)), 0, 0, 0, 0, 0, 0, 0, 0))
+ return DummyPathStatResult(st_mode, hash(str(self)), 0, 0, 0, 0, 0, 0, 0, 0)
def open(self, mode='r', buffering=-1, encoding=None,
errors=None, newline=None):
@@ -1728,6 +1737,11 @@ class DummyPathTest(DummyPurePathTest):
class DummyPathWithSymlinks(DummyPath):
+ __slots__ = ()
+
+ # Reduce symlink traversal limit to make tests run faster.
+ _max_symlinks = 20
+
def readlink(self):
path = str(self.parent.resolve() / self.name)
if path in self._symlinks: