Skip to content

Commit 2b1d015

Browse files
authored
Fix MemoryPath root (#495)
* tests: add test case ensuring all parents are absolute * upath.implementations.memory: fix memorypath root * tests: skip parents mock test on windows
1 parent 78a355a commit 2b1d015

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

upath/implementations/memory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ def iterdir(self) -> Iterator[Self]:
4444
@property
4545
def path(self) -> str:
4646
path = super().path
47-
return "/" if path == "." else path
47+
return "/" if path in {"", "."} else path
48+
49+
def is_absolute(self) -> bool:
50+
if self._relative_base is None and self.__vfspath__() == "/":
51+
return True
52+
return super().is_absolute()
4853

4954
def __str__(self) -> str:
5055
s = super().__str__()

upath/tests/cases.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,3 +782,9 @@ def test_trailing_slash_is_stripped(self):
782782
else:
783783
assert not self.path.joinpath("key").path.endswith("/")
784784
assert not self.path.joinpath("key/").path.endswith("/")
785+
786+
def test_parents_are_absolute(self):
787+
# this is a cross implementation compatible way to ensure that
788+
# the path representing the root is absolute
789+
is_absolute = [p.is_absolute() for p in self.path.parents]
790+
assert all(is_absolute)

upath/tests/implementations/test_data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,7 @@ def test_trailing_slash_joinpath_is_identical(self):
300300
@pytest.mark.skip(reason="DataPath does not support joins")
301301
def test_trailing_slash_is_stripped(self):
302302
pass
303+
304+
@pytest.mark.skip(reason="DataPath does not support joins")
305+
def test_parents_are_absolute(self):
306+
pass

upath/tests/test_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ def test_iterdir_no_dir(self):
7979
# so this test would need to have an iterdir fix.
8080
super().test_iterdir_no_dir()
8181

82+
@pytest.mark.skipif(
83+
sys.platform.startswith("win"),
84+
reason="mock fs is not well defined on windows",
85+
)
86+
def test_parents_are_absolute(self):
87+
return super().test_parents_are_absolute()
88+
8289

8390
def test_multiple_backend_paths(local_testdir):
8491
path = "s3://bucket/"

0 commit comments

Comments
 (0)