The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

Add __lt__ and __gt__ operators to Path

main
Gergely Polonkai 3 months ago
parent 6e8f0fa5a1
commit ae99aba0e0
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
  1. 9
      earthsnake/path.py
  2. 41
      tests/test_path.py

@ -76,6 +76,15 @@ class Path:
def __repr__(self) -> str:
return f'<Path {self.path}>'
def __eq__(self, other: object) -> bool:
return str(self) == str(other)
def __lt__(self, other: object) -> bool:
return str(self) < str(other)
def __gt__(self, other: object) -> bool:
return str(self) > str(other)
def startswith(self, sub: str) -> bool:
"""Check if path starts with sub"""

@ -124,3 +124,44 @@ def test_endswith() -> None:
assert path.endswith('.txt')
assert not path.endswith('.py')
def test_eq_other_path() -> None:
"""Test if Paths can be compared to other Paths"""
assert Path('/test.txt') == Path('/test.txt')
assert Path('/test.txt') != Path('/test.md')
def test_eq_str() -> None:
"""Test if Paths can be compared to strings"""
assert Path('/test.txt') == '/test.txt'
assert Path('/test.txt') != '/test.md'
def test_lt() -> None:
"""Test if Paths can be sorted with other Paths (< direction)"""
assert Path('/test.txt') < Path('/very.txt')
assert not Path('/test.txt') < Path('/much.txt') # pylint: disable=unneeded-not
def test_lt_str() -> None:
"""Test if Paths can be sorted with strings (< direction)"""
assert Path('/very.txt') > '/test.txt'
assert not Path('/much.txt') > '/test.txt' # pylint: disable=unneeded-not
def test_gt() -> None:
"""Test if Paths can be sorted with other Paths (> direction)"""
assert Path('/very.txt') > Path('/test.txt')
assert not Path('/much.txt') > Path('/test.txt') # pylint: disable=unneeded-not
def test_g_str() -> None:
"""Test if Paths can be sorted with strings (> direction)"""
assert Path('/very.txt') > '/test.txt'
assert not Path('/much.txt') > '/test.txt' # pylint: disable=unneeded-not

Loading…
Cancel
Save