Skip to content

Commit 07263a2

Browse files
committed
Add test for copying across filesystems.
1 parent d60c4e9 commit 07263a2

File tree

3 files changed

+83
-28
lines changed

3 files changed

+83
-28
lines changed

tiledb/tests/common.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,31 @@ def create_vfs_dir(path):
7070
vfs.create_dir(path)
7171

7272

73-
def vfs_path(scheme: str, prefix: str = None) -> str:
74-
"""Create a VFS-compatible path"""
75-
if not prefix:
76-
if scheme == "s3":
77-
prefix: str = "tiledb-" + str(random.randint(0, 10e10))
78-
else:
79-
prefix: str = "tiledb-" + str(uuid.uuid4())
73+
def vfs_path(scheme: str) -> str:
74+
prefix = "tiledb-"
75+
if scheme == "s3":
76+
prefix += str(random.randint(0, 10000000000))
77+
else:
78+
prefix += str(uuid.uuid4())
79+
8080
if scheme == "file":
8181
return f"{scheme}://{tempfile.mktemp(prefix=prefix)}"
82-
if "/" not in prefix:
83-
prefix: str = f"{uuid.uuid4()}/{prefix}"
84-
return f"{scheme}://{prefix}"
82+
else:
83+
return f"{scheme}://{prefix}"
84+
85+
86+
# def vfs_path(scheme: str, prefix: str = None) -> str:
87+
# """Create a VFS-compatible path"""
88+
# if not prefix:
89+
# if scheme == "s3":
90+
# prefix: str = "tiledb-" + str(random.randint(0, 10e10))
91+
# else :
92+
# prefix: str = "tiledb-" + str(uuid.uuid4())
93+
# if scheme == "file":
94+
# return f"{scheme}://{tempfile.mktemp(prefix=prefix)}"
95+
# if "/" not in prefix:
96+
# prefix: str = f"{uuid.uuid4()}/{prefix}"
97+
# return f"{scheme}://{prefix}"
8598

8699

87100
class DiskTestCase:

tiledb/tests/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,36 @@ def original_os_fork():
7272
"""Provides the original unpatched os.fork."""
7373
if sys.platform != "win32":
7474
return os.fork
75+
76+
77+
@pytest.fixture
78+
def vfs_config() -> dict[str, str]:
79+
config: dict[str, str] = {}
80+
# Configure S3
81+
if os.getenv("AWS_ACCESS_KEY_ID") and os.getenv("AWS_SECRET_ACCESS_KEY"):
82+
config["vfs.s3.aws_access_key_id"] = os.getenv("AWS_ACCESS_KEY_ID")
83+
config["vfs.s3.aws_secret_access_key"] = os.getenv("AWS_SECRET_ACCESS_KEY")
84+
if os.getenv("VFS_S3_USE_MINIO"):
85+
config["vfs.s3.endpoint_override"] = "localhost:9999"
86+
config["vfs.s3.scheme"] = "https"
87+
config["vfs.s3.use_virtual_addressing"] = "false"
88+
config["vfs.s3.verify_ssl"] = "false"
89+
90+
# Configure Azure
91+
if os.getenv("AZURE_BLOB_ENDPOINT"):
92+
config["vfs.azure.blob_endpoint"] = os.getenv("AZURE_BLOB_ENDPOINT")
93+
if os.getenv("AZURE_STORAGE_ACCOUNT_TOKEN"):
94+
config["vfs.azure.storage_sas_token"] = os.getenv("AZURE_STORAGE_ACCOUNT_TOKEN")
95+
elif os.getenv("AZURE_STORAGE_ACCOUNT_NAME") and os.getenv(
96+
"AZURE_STORAGE_ACCOUNT_KEY"
97+
):
98+
config["vfs.azure.storage_account_name"] = os.getenv(
99+
"AZURE_STORAGE_ACCOUNT_NAME"
100+
)
101+
config["vfs.azure.storage_account_key"] = os.getenv("AZURE_STORAGE_ACCOUNT_KEY")
102+
103+
# Configure Google Cloud
104+
if os.getenv("TILEDB_TEST_GCS_ENDPOINT"):
105+
config["vfs.gcs.endpoint"] = os.getenv("TILEDB_TEST_GCS_ENDPOINT")
106+
107+
return config

tiledb/tests/test_vfs.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,32 +118,46 @@ def test_copy(self):
118118
with self.assertRaises(tiledb.TileDBError):
119119
vfs.copy_dir(self.path("foo/baz"), self.path("do_not_exist/baz"))
120120

121+
# Note: Azure tests are intermittently failing.
122+
# Seemingly mostly azure->azure, but also test teardown.
123+
# I think it's an Azurite bucket storage thing, actually.
121124
@pytest.mark.skipif(
122125
sys.platform == "win32",
123126
reason="Windows paths are difficult; Posix is sufficient for testing.",
124127
)
125-
@pytest.mark.parametrize("src", ["file"])
126-
@pytest.mark.parametrize("dst", ["file"])
127-
# @pytest.mark.parametrize("src", ["file", "s3", "azure", "gcs"])
128-
# @pytest.mark.parametrize("dst", ["file", "s3", "azure", "gcs"])
129-
def test_copy_across(self, src: str, dst: str):
128+
@pytest.mark.parametrize("src", ["file", "s3", "azure", "gcs"])
129+
@pytest.mark.parametrize("dst", ["file", "s3", "azure", "gcs"])
130+
def test_copy_across(self, src: str, dst: str, vfs_config):
130131
# Currently, skip if both FSes are the same. This is covered above.
131132
# However, this test might ought to replace the above.
132-
# if src == dst:
133-
# return
133+
if src == dst:
134+
return
134135

135-
vfs = tiledb.VFS()
136+
# Set configuration options
137+
if (src == "s3" or dst == "s3") and not vfs_config.get(
138+
"vfs.s3.aws_access_key_id"
139+
):
140+
return
141+
if (src == "azure" or dst == "azure") and not any(
142+
x.startswith("vfs.azure") for x in vfs_config.keys()
143+
):
144+
return
145+
if (src == "gcs" or dst == "gcs") and not vfs_config.get("vfs.gcs.endpoint"):
146+
return
147+
vfs = tiledb.VFS(vfs_config)
136148

137149
# Return if neither filesystem is supported.
138150
if not vfs.supports(src) or not vfs.supports(dst):
139151
return
140152

141153
# Create source file, and write to it.
142-
srcdir: str = vfs_path(src, prefix="tiledb-copy-src")
154+
srcdir: str = vfs_path(src)
143155
if src == "file":
144156
vfs.create_dir(srcdir)
157+
self.assertTrue(vfs.is_dir(srcdir))
145158
else:
146159
vfs.create_bucket(srcdir)
160+
self.assertTrue(vfs.is_bucket(srcdir))
147161
srcfile: str = f"{srcdir}/testfile"
148162
vfs.touch(srcfile)
149163
self.assertTrue(vfs.isfile(srcfile))
@@ -154,23 +168,18 @@ def test_copy_across(self, src: str, dst: str):
154168
self.assertEqual(handle.read(), contents)
155169

156170
# Copy src -> dst and assert the file contents are unchanged.
157-
dstdir: str = vfs_path(dst, prefix="tiledb-copy-dst")
171+
dstdir: str = vfs_path(dst)
158172
if dst == "file":
159173
vfs.create_dir(dstdir)
174+
self.assertTrue(vfs.is_dir(dstdir))
160175
else:
161176
vfs.create_bucket(dstdir)
177+
self.assertTrue(vfs.is_bucket(dstdir))
162178
dstfile: str = f"{dstdir}/testfile"
163-
vfs.copy_file(srcfile, dstfile)
179+
vfs.copy_dir(srcdir, dstdir)
164180
with vfs.open(dstfile) as handle:
165181
self.assertEqual(handle.read(), contents)
166182

167-
# Copy back dst -> src and assert the file contents are unchanged.
168-
vfs.remove_file(srcfile)
169-
self.assertFalse(vfs.isfile(srcfile))
170-
vfs.copy_file(dstfile, srcfile)
171-
with vfs.open(srcfile) as handle:
172-
self.assertEqual(handle.read(), contents)
173-
174183
# Clean up
175184
if src == "file":
176185
vfs.remove_dir(srcdir)

0 commit comments

Comments
 (0)