Skip to content

Commit 475f933

Browse files
authored
pythonGH-130614: pathlib ABCs: revise test suite for path joining (python#130988)
Test `pathlib.types._JoinablePath` in a dedicated test module. These tests cover `LexicalPath`, `PurePath` and `Path`, where `LexicalPath` is defined in a new `test.test_pathlib.support` package.
1 parent bbd6d17 commit 475f933

File tree

5 files changed

+406
-381
lines changed

5 files changed

+406
-381
lines changed

Lib/test/test_pathlib/support/__init__.py

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Simple implementation of JoinablePath, for use in pathlib tests.
3+
"""
4+
5+
import os.path
6+
import pathlib.types
7+
8+
9+
class LexicalPath(pathlib.types._JoinablePath):
10+
__slots__ = ('_segments',)
11+
parser = os.path
12+
13+
def __init__(self, *pathsegments):
14+
self._segments = pathsegments
15+
16+
def __hash__(self):
17+
return hash(str(self))
18+
19+
def __eq__(self, other):
20+
if not isinstance(other, LexicalPath):
21+
return NotImplemented
22+
return str(self) == str(other)
23+
24+
def __str__(self):
25+
if not self._segments:
26+
return ''
27+
return self.parser.join(*self._segments)
28+
29+
def __repr__(self):
30+
return f'{type(self).__name__}({str(self)!r})'
31+
32+
def with_segments(self, *pathsegments):
33+
return type(self)(*pathsegments)

0 commit comments

Comments
 (0)