aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_pathlib/support/local_path.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2025-03-12 19:06:43 +0000
committerGitHub <noreply@github.com>2025-03-12 19:06:43 +0000
commitdb6a998b18e9476226507144b3b2fab854095dbc (patch)
tree1b3cabf1663573d00c1e166c0f9d777cd4326b98 /Lib/test/test_pathlib/support/local_path.py
parentea57ffa02e42dc430f2cb2312cdfc3d7ff7a5c70 (diff)
downloadcpython-db6a998b18e9476226507144b3b2fab854095dbc.tar.gz
cpython-db6a998b18e9476226507144b3b2fab854095dbc.zip
GH-130614: pathlib ABCs: revise test suite for writable paths (#131112)
Test `pathlib.types._WritablePath` in a dedicated test module. These tests cover `WritableZipPath`, `WritableLocalPath` and `Path`, where the former two classes are implementations of `_WritablePath` for use in tests.
Diffstat (limited to 'Lib/test/test_pathlib/support/local_path.py')
-rw-r--r--Lib/test/test_pathlib/support/local_path.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_pathlib/support/local_path.py b/Lib/test/test_pathlib/support/local_path.py
index 1d2b03df225..1cf64316b40 100644
--- a/Lib/test/test_pathlib/support/local_path.py
+++ b/Lib/test/test_pathlib/support/local_path.py
@@ -1,5 +1,6 @@
"""
-Implementation of ReadablePath for local paths, for use in pathlib tests.
+Implementations of ReadablePath and WritablePath for local paths, for use in
+pathlib tests.
LocalPathGround is also defined here. It helps establish the "ground truth"
about local paths in tests.
@@ -143,3 +144,23 @@ class ReadableLocalPath(pathlib.types._ReadablePath, LexicalPath):
def readlink(self):
return self.with_segments(os.readlink(self))
+
+
+class WritableLocalPath(pathlib.types._WritablePath, LexicalPath):
+ """
+ Simple implementation of a WritablePath class for local filesystem paths.
+ """
+
+ __slots__ = ()
+
+ def __fspath__(self):
+ return str(self)
+
+ def __open_wb__(self, buffering=-1):
+ return open(self, 'wb')
+
+ def mkdir(self, mode=0o777):
+ os.mkdir(self, mode)
+
+ def symlink_to(self, target, target_is_directory=False):
+ os.symlink(target, self, target_is_directory)