Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion upath/implementations/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def iterdir(self) -> Iterator[Self]:
@property
def path(self) -> str:
path = super().path
return "/" if path == "." else path
return "/" if path in {"", "."} else path

def is_absolute(self) -> bool:
if self._relative_base is None and self.__vfspath__() == "/":
return True
return super().is_absolute()

def __str__(self) -> str:
s = super().__str__()
Expand Down
6 changes: 6 additions & 0 deletions upath/tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,3 +782,9 @@ def test_trailing_slash_is_stripped(self):
else:
assert not self.path.joinpath("key").path.endswith("/")
assert not self.path.joinpath("key/").path.endswith("/")

def test_parents_are_absolute(self):
# this is a cross implementation compatible way to ensure that
# the path representing the root is absolute
is_absolute = [p.is_absolute() for p in self.path.parents]
assert all(is_absolute)
4 changes: 4 additions & 0 deletions upath/tests/implementations/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,7 @@ def test_trailing_slash_joinpath_is_identical(self):
@pytest.mark.skip(reason="DataPath does not support joins")
def test_trailing_slash_is_stripped(self):
pass

@pytest.mark.skip(reason="DataPath does not support joins")
def test_parents_are_absolute(self):
pass
7 changes: 7 additions & 0 deletions upath/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def test_iterdir_no_dir(self):
# so this test would need to have an iterdir fix.
super().test_iterdir_no_dir()

@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="mock fs is not well defined on windows",
)
def test_parents_are_absolute(self):
return super().test_parents_are_absolute()


def test_multiple_backend_paths(local_testdir):
path = "s3://bucket/"
Expand Down