mirror of
https://github.com/python/cpython.git
synced 2025-10-23 09:53:47 +00:00
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:
parent
ea57ffa02e
commit
db6a998b18
4 changed files with 178 additions and 43 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue