kopia lustrzana https://github.com/micropython/micropython-lib
python-stdlib/pathlib: Add __rtruediv__ magic method to pathlib.Path
rodzic
423f5fa2c2
commit
d5e5c4a707
|
@ -47,6 +47,9 @@ class Path:
|
|||
def __truediv__(self, other):
|
||||
return Path(self._path, str(other))
|
||||
|
||||
def __rtruediv__(self, other):
|
||||
return Path(other, self._path)
|
||||
|
||||
def __repr__(self):
|
||||
return f'{type(self).__name__}("{self._path}")'
|
||||
|
||||
|
|
|
@ -322,3 +322,14 @@ class TestPathlib(unittest.TestCase):
|
|||
self.assertTrue(Path("foo/test").with_suffix(".tar") == Path("foo/test.tar"))
|
||||
self.assertTrue(Path("foo/bar.bin").with_suffix(".txt") == Path("foo/bar.txt"))
|
||||
self.assertTrue(Path("bar.txt").with_suffix("") == Path("bar"))
|
||||
|
||||
def test_rtruediv(self):
|
||||
"""Works as of micropython ea7031f"""
|
||||
res = "foo" / Path("bar")
|
||||
self.assertTrue(res == Path("foo/bar"))
|
||||
|
||||
def test_rtruediv_inplace(self):
|
||||
"""Works as of micropython ea7031f"""
|
||||
res = "foo"
|
||||
res /= Path("bar")
|
||||
self.assertTrue(res == Path("foo/bar"))
|
||||
|
|
Ładowanie…
Reference in New Issue