Skip to content

Commit e5bfe87

Browse files
committed
tests: add AzurePath test for copy_into (xfail)
1 parent aef48e5 commit e5bfe87

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

upath/tests/implementations/test_azure.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import warnings
2+
3+
import fsspec
14
import pytest
25

36
from upath import UPath
@@ -7,6 +10,7 @@
710
from ..utils import OverrideMeta
811
from ..utils import extends_base
912
from ..utils import overrides_base
13+
from ..utils import posixify
1014
from ..utils import skip_on_windows
1115

1216

@@ -61,3 +65,56 @@ def test_broken_mkdir(self):
6165

6266
(path / "file").write_text("foo")
6367
assert path.exists()
68+
69+
70+
@skip_on_windows
71+
@pytest.mark.xfail(reason="adlfs returns isdir false")
72+
def test_copy__object_key_collides_with_dir_prefix(azurite_credentials, tmp_path):
73+
account_name, connection_string = azurite_credentials
74+
storage_options = {
75+
"account_name": account_name,
76+
"connection_string": connection_string,
77+
}
78+
79+
az = fsspec.filesystem("az", **storage_options, use_listings_cache=False)
80+
container = "copy-into-collision-container"
81+
az.mkdir(container)
82+
# store more objects with same prefix
83+
az.pipe_file(f"{container}/src/common_prefix/file1.txt", b"1")
84+
az.pipe_file(f"{container}/src/common_prefix/file2.txt", b"2")
85+
# object under common prefix as key
86+
az.pipe_file(f"{container}/src/common_prefix", b"hello world")
87+
az.invalidate_cache()
88+
89+
# make sure the sources have a collision
90+
assert az.isfile(f"{container}/src/common_prefix")
91+
assert az.isdir(f"{container}/src/common_prefix")
92+
assert az.isfile(f"{container}/src/common_prefix/file1.txt")
93+
assert az.isfile(f"{container}/src/common_prefix/file2.txt")
94+
# prepare source and destination
95+
src = UPath(f"az://{container}/src", **storage_options)
96+
dst = UPath(tmp_path)
97+
98+
def on_collision_rename_file(src, dst):
99+
warnings.warn(
100+
f"{src!s} collides with prefix. Renaming target file object to {dst!s}",
101+
UserWarning,
102+
stacklevel=3,
103+
)
104+
return (
105+
dst.with_suffix(dst.suffix + ".COLLISION"),
106+
dst,
107+
)
108+
109+
# perform copy
110+
src.copy_into(dst, on_name_collision=on_collision_rename_file)
111+
112+
# check results
113+
dst_files = sorted(posixify(x.relative_to(tmp_path)) for x in dst.glob("**/*"))
114+
assert dst_files == [
115+
"src",
116+
"src/common_prefix",
117+
"src/common_prefix.COLLISION",
118+
"src/common_prefix/file1.txt",
119+
"src/common_prefix/file2.txt",
120+
]

0 commit comments

Comments
 (0)