diff --git a/upath/implementations/cloud.py b/upath/implementations/cloud.py index a8dd22f..cf0e85f 100644 --- a/upath/implementations/cloud.py +++ b/upath/implementations/cloud.py @@ -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): diff --git a/upath/tests/implementations/test_azure.py b/upath/tests/implementations/test_azure.py index 8605db6..82f88e9 100644 --- a/upath/tests/implementations/test_azure.py +++ b/upath/tests/implementations/test_azure.py @@ -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")) diff --git a/upath/tests/implementations/test_local.py b/upath/tests/implementations/test_local.py index 2e18d87..0751c90 100644 --- a/upath/tests/implementations/test_local.py +++ b/upath/tests/implementations/test_local.py @@ -19,11 +19,15 @@ 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")) @@ -31,6 +35,7 @@ def test_relative_to(self): 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): diff --git a/upath/tests/implementations/test_s3.py b/upath/tests/implementations/test_s3.py index deeb379..9ae1611 100644 --- a/upath/tests/implementations/test_s3.py +++ b/upath/tests/implementations/test_s3.py @@ -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"))