Add startswith() and endswith() methods to Path
This commit is contained in:
parent
1299acd463
commit
b9d0221e95
@ -75,3 +75,13 @@ class Path:
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f'<Path {self.path}>'
|
return f'<Path {self.path}>'
|
||||||
|
|
||||||
|
def startswith(self, sub: str) -> bool:
|
||||||
|
"""Check if path starts with sub"""
|
||||||
|
|
||||||
|
return self.path.startswith(sub)
|
||||||
|
|
||||||
|
def endswith(self, sub: str) -> bool:
|
||||||
|
"""Check if path ends with sub"""
|
||||||
|
|
||||||
|
return self.path.endswith(sub)
|
||||||
|
@ -106,3 +106,21 @@ def test_repr() -> None:
|
|||||||
"""Test the __repr__ method"""
|
"""Test the __repr__ method"""
|
||||||
|
|
||||||
assert repr(Path('/test.txt')) == '<Path /test.txt>'
|
assert repr(Path('/test.txt')) == '<Path /test.txt>'
|
||||||
|
|
||||||
|
|
||||||
|
def test_startswith() -> None:
|
||||||
|
"""Test the startswith method"""
|
||||||
|
|
||||||
|
path = Path('/test.txt')
|
||||||
|
|
||||||
|
assert path.startswith('/test')
|
||||||
|
assert not path.startswith('test')
|
||||||
|
|
||||||
|
|
||||||
|
def test_endswith() -> None:
|
||||||
|
"""Test the endswith method"""
|
||||||
|
|
||||||
|
path = Path('/test.txt')
|
||||||
|
|
||||||
|
assert path.endswith('.txt')
|
||||||
|
assert not path.endswith('.py')
|
||||||
|
Loading…
Reference in New Issue
Block a user