Skip to content

Commit

Permalink
fea: add walk_up test -> note broken for azure?
Browse files Browse the repository at this point in the history
  • Loading branch information
CompRhys committed Apr 17, 2024
1 parent 782d4a2 commit a157fc4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion upath/implementations/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def iterdir(self):

def relative_to(self, other, /, *_deprecated, walk_up=False):
# use the parent implementation for the ValueError logic
return super().relative_to(other, *_deprecated, walk_up=False)
return super().relative_to(other, *_deprecated, walk_up=walk_up)


class GCSPath(CloudPath):
Expand Down
6 changes: 5 additions & 1 deletion upath/tests/implementations/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ def test_broken_mkdir(self):

def test_relative_to(self):
rel_path = UPath("az:///test_bucket/file.txt").relative_to(UPath("az:///test_bucket"))

assert isinstance(rel_path, PosixUPath)
assert not rel_path.is_absolute()
assert 'file.txt' == rel_path.path

walk_path = UPath("az:///test_bucket/file.txt").relative_to(UPath("az:///other_test_bucket"), walk_up=True)
assert isinstance(walk_path, PosixUPath)
assert not walk_path.is_absolute()
assert '../test_bucket/file.txt' == walk_path.path

with pytest.raises(ValueError):
UPath("az:///test_bucket/file.txt").relative_to(UPath("az:///prod_bucket"))

Expand Down
7 changes: 6 additions & 1 deletion upath/tests/implementations/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@ def test_is_LocalPath(self):

def test_relative_to(self):
rel_path = UPath("file:///test_bucket/file.txt").relative_to(UPath("file:///test_bucket"))

assert isinstance(rel_path, PosixUPath)
assert not rel_path.is_absolute()
assert 'file.txt' == rel_path.path

walk_path = UPath("file:///test_bucket/file.txt").relative_to(UPath("file:///other_test_bucket"), walk_up=True)
assert isinstance(walk_path, PosixUPath)
assert not walk_path.is_absolute()
assert '../test_bucket/file.txt' == walk_path.path

with pytest.raises(ValueError):
UPath("file:///test_bucket/file.txt").relative_to(UPath("file:///prod_bucket"))

with pytest.raises(ValueError):
UPath("file:///test_bucket/file.txt").relative_to(UPath("s3:///test_bucket"))



@skip_on_windows
@xfail_if_version("fsspec", lt="2023.10.0", reason="requires fsspec>=2023.10.0")
class TestRayIOFSSpecLocal(BaseTests):
Expand Down
6 changes: 5 additions & 1 deletion upath/tests/implementations/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ def test_rmdir(self):

def test_relative_to(self):
rel_path = UPath("s3:///test_bucket/file.txt").relative_to(UPath("s3:///test_bucket"))

assert isinstance(rel_path, PosixUPath)
assert not rel_path.is_absolute()
assert 'file.txt' == rel_path.path

walk_path = UPath("s3:///test_bucket/file.txt").relative_to(UPath("s3:///other_test_bucket"), walk_up=True)
assert isinstance(walk_path, PosixUPath)
assert not walk_path.is_absolute()
assert '../test_bucket/file.txt' == walk_path.path

with pytest.raises(ValueError):
UPath("s3:///test_bucket/file.txt").relative_to(UPath("s3:///prod_bucket"))

Expand Down

0 comments on commit a157fc4

Please sign in to comment.