Skip to content

Commit ae98724

Browse files
Use specific temp directory for other icechunk tests (#719)
* use specific temp directory for other icechunk tests * missed a file * remove rogue imports * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3bf9f85 commit ae98724

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

virtualizarr/tests/test_integration.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
requires_zarr_python,
3030
slow_test,
3131
)
32+
from virtualizarr.tests.utils import PYTEST_TMP_DIRECTORY_URL_PREFIX
3233

3334
icechunk = pytest.importorskip("icechunk")
3435

@@ -143,19 +144,16 @@ def roundtrip_as_in_memory_icechunk(
143144

144145
config = icechunk.RepositoryConfig.default()
145146

146-
url_prefixes = ["file:///private/var/folders/70", "file:///tmp/"]
147-
148-
for url_prefix in url_prefixes:
149-
container = icechunk.VirtualChunkContainer(
150-
url_prefix=url_prefix,
151-
store=icechunk.local_filesystem_store(url_prefix),
152-
)
153-
config.set_virtual_chunk_container(container)
147+
container = icechunk.VirtualChunkContainer(
148+
url_prefix=PYTEST_TMP_DIRECTORY_URL_PREFIX,
149+
store=icechunk.local_filesystem_store(PYTEST_TMP_DIRECTORY_URL_PREFIX),
150+
)
151+
config.set_virtual_chunk_container(container)
154152

155153
repo = icechunk.Repository.create(
156154
storage=storage,
157155
config=config,
158-
authorize_virtual_chunk_access={prefix: None for prefix in url_prefixes},
156+
authorize_virtual_chunk_access={PYTEST_TMP_DIRECTORY_URL_PREFIX: None},
159157
)
160158
session = repo.writable_session("main")
161159

virtualizarr/tests/test_writers/test_icechunk.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
import tempfile
31
import time
42
from datetime import datetime, timedelta, timezone
53
from pathlib import Path
@@ -15,6 +13,7 @@
1513
from zarr.core.metadata import ArrayV3Metadata
1614

1715
from virtualizarr.manifests import ChunkManifest, ManifestArray
16+
from virtualizarr.tests.utils import PYTEST_TMP_DIRECTORY_URL_PREFIX
1817
from virtualizarr.writers.icechunk import generate_chunk_key
1918
from virtualizarr.xarray import separate_coords
2019

@@ -28,11 +27,6 @@
2827
)
2928

3029

31-
# Find location of pytest temporary data in what should be a cross-platform way. This should be the same as what pytest actually does - see https://docs.pytest.org/en/stable/how-to/tmp_path.html#temporary-directory-location-and-retention
32-
# The realpath call is there to resolve any symbolic links, such as from /var/ to /private/var/ on MacOS, as Icechunk needs the entire URL prefix without symlinks.
33-
PYTEST_TMP_DIRECTORY_URL_PREFIX = f"file://{os.path.realpath(tempfile.gettempdir())}"
34-
35-
3630
@pytest.fixture(scope="function")
3731
def icechunk_storage(tmp_path: Path) -> "Storage":
3832
from icechunk import Storage

virtualizarr/tests/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
import tempfile
45
from pathlib import Path
56
from urllib.parse import urlparse
67

@@ -9,6 +10,10 @@
910
from virtualizarr.parsers import HDFParser
1011
from virtualizarr.registry import ObjectStoreRegistry
1112

13+
# Find location of pytest temporary data in what should be a cross-platform way. This should be the same as what pytest actually does - see https://docs.pytest.org/en/stable/how-to/tmp_path.html#temporary-directory-location-and-retention
14+
# The realpath call is there to resolve any symbolic links, such as from /var/ to /private/var/ on MacOS, as Icechunk needs the entire URL prefix without symlinks.
15+
PYTEST_TMP_DIRECTORY_URL_PREFIX = f"file://{os.path.realpath(tempfile.gettempdir())}"
16+
1217

1318
def obstore_local(url: str) -> ObjectStore:
1419
parsed = urlparse(url)

0 commit comments

Comments
 (0)