Skip to content

Commit d670b30

Browse files
committed
properly construct remotestore instance in test fixture
1 parent 0045351 commit d670b30

File tree

2 files changed

+7
-67
lines changed

2 files changed

+7
-67
lines changed

tests/conftest.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from dataclasses import dataclass, field
66
from typing import TYPE_CHECKING
77

8-
import botocore
9-
import fsspec
108
import numpy as np
119
import numpy.typing as npt
1210
import pytest
@@ -23,6 +21,7 @@
2321
from collections.abc import Generator
2422
from typing import Any, Literal
2523

24+
import botocore
2625
from _pytest.compat import LEGACY_PATH
2726

2827
from zarr.core.common import ChunkCoords, MemoryOrder, ZarrFormat
@@ -47,8 +46,11 @@ async def parse_store(
4746
if store == "memory":
4847
return await MemoryStore.open(mode="a")
4948
if store == "remote":
50-
fs = fsspec.filesystem("s3", endpoint_url=endpoint_url, anon=False, asynchronous=True)
51-
return await RemoteStore.open(fs, mode="a")
49+
return RemoteStore.from_url(
50+
f"s3://{test_bucket_name}/foo/spam/",
51+
mode="a",
52+
storage_options={"endpoint_url": endpoint_url, "anon": False},
53+
)
5254
if store == "zip":
5355
return await ZipStore.open(path + "/zarr.zip", mode="a")
5456
raise AssertionError
@@ -167,7 +169,7 @@ def get_boto3_client() -> botocore.client.BaseClient:
167169

168170

169171
@pytest.fixture(autouse=True)
170-
def s3(s3_base: None) -> Generator[s3fs.S3FileSystem, None, None]:
172+
def s3(s3_base: None) -> Generator[s3fs.S3FileSystem, None, None]: # type: ignore[name-defined]
171173
"""
172174
Quoting Martin Durant:
173175
pytest-asyncio creates a new event loop for each async test.

tests/test_store/test_remote.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,6 @@
1414

1515
from ..conftest import endpoint_url, test_bucket_name
1616

17-
# s3fs = pytest.importorskip("s3fs")
18-
# requests = pytest.importorskip("requests")
19-
# moto_server = pytest.importorskip("moto.moto_server.threaded_moto_server")
20-
# moto = pytest.importorskip("moto")
21-
22-
# # ### amended from s3fs ### #
23-
# test_bucket_name = "test"
24-
# secure_bucket_name = "test-secure"
25-
# port = 5555
26-
# endpoint_url = f"http://127.0.0.1:{port}/"
27-
28-
29-
# @pytest.fixture(scope="module")
30-
# def s3_base() -> Generator[None, None, None]:
31-
# # writable local S3 system
32-
33-
# # This fixture is module-scoped, meaning that we can reuse the MotoServer across all tests
34-
# server = moto_server.ThreadedMotoServer(ip_address="127.0.0.1", port=port)
35-
# server.start()
36-
# if "AWS_SECRET_ACCESS_KEY" not in os.environ:
37-
# os.environ["AWS_SECRET_ACCESS_KEY"] = "foo"
38-
# if "AWS_ACCESS_KEY_ID" not in os.environ:
39-
# os.environ["AWS_ACCESS_KEY_ID"] = "foo"
40-
41-
# yield
42-
# server.stop()
43-
44-
45-
# def get_boto3_client() -> botocore.client.BaseClient:
46-
# # NB: we use the sync botocore client for setup
47-
# session = Session()
48-
# return session.create_client("s3", endpoint_url=endpoint_url)
49-
50-
51-
# @pytest.fixture(autouse=True)
52-
# def s3(s3_base: None) -> Generator[s3fs.S3FileSystem, None, None]:
53-
# """
54-
# Quoting Martin Durant:
55-
# pytest-asyncio creates a new event loop for each async test.
56-
# When an async-mode s3fs instance is made from async, it will be assigned to the loop from
57-
# which it is made. That means that if you use s3fs again from a subsequent test,
58-
# you will have the same identical instance, but be running on a different loop - which fails.
59-
60-
# For the rest: it's very convenient to clean up the state of the store between tests,
61-
# make sure we start off blank each time.
62-
63-
# https://github.com/zarr-developers/zarr-python/pull/1785#discussion_r1634856207
64-
# """
65-
# client = get_boto3_client()
66-
# client.create_bucket(Bucket=test_bucket_name, ACL="public-read")
67-
# s3fs.S3FileSystem.clear_instance_cache()
68-
# s3 = s3fs.S3FileSystem(anon=False, client_kwargs={"endpoint_url": endpoint_url})
69-
# session = sync(s3.set_session())
70-
# s3.invalidate_cache()
71-
# yield s3
72-
# requests.post(f"{endpoint_url}/moto-api/reset")
73-
# client.close()
74-
# sync(session.close())
75-
76-
77-
# # ### end from s3fs ### #
78-
7917

8018
async def test_basic() -> None:
8119
store = RemoteStore.from_url(

0 commit comments

Comments
 (0)