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.
This commit is contained in:
Barney Gale 2025-03-12 19:06:43 +00:00 committed by GitHub
parent ea57ffa02e
commit db6a998b18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 178 additions and 43 deletions

View file

@ -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 @@ def iterdir(self):
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)