-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* compatibility with fsspec>=2023.10 * fsspec is typed * template update * restore fsspec in pyproject.toml
- Loading branch information
Showing
7 changed files
with
45 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,6 @@ dependencies: | |
- requests | ||
- s3fs | ||
- sqlalchemy[mypy] | ||
- types-requests | ||
- xarray>=2022.6.0 | ||
- zarr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,57 @@ | ||
import contextlib | ||
import os | ||
import pathlib | ||
import shlex | ||
import subprocess | ||
import time | ||
from typing import Any, Dict, Generator | ||
from typing import Any, Generator, Iterator | ||
|
||
import botocore.session | ||
import psycopg | ||
import pytest | ||
import requests | ||
from moto.moto_server.threaded_moto_server import ThreadedMotoServer | ||
|
||
from cacholote import config | ||
|
||
|
||
def wait_s3_up( | ||
endpoint_url: str, max_sleep: float = 1.0, min_sleep: float = 0.1 | ||
) -> None: | ||
requests = pytest.importorskip("requests") | ||
while max_sleep > 0: | ||
time.sleep(min_sleep) | ||
max_sleep -= min_sleep | ||
try: | ||
r = requests.get(endpoint_url) | ||
if r.ok: | ||
break | ||
except requests.exceptions.ConnectionError: | ||
pass | ||
|
||
|
||
@contextlib.contextmanager | ||
def initialize_s3() -> Generator[Dict[str, str], None, None]: | ||
pytest.importorskip("boto3") | ||
@pytest.fixture(scope="session") | ||
def s3_base() -> Iterator[ThreadedMotoServer]: | ||
if "AWS_SECRET_ACCESS_KEY" not in os.environ: | ||
os.environ["AWS_SECRET_ACCESS_KEY"] = "foo" | ||
if "AWS_ACCESS_KEY_ID" not in os.environ: | ||
os.environ["AWS_ACCESS_KEY_ID"] = "foo" | ||
port = 5555 | ||
proc = subprocess.Popen( | ||
shlex.split(f"moto_server s3 -p {port}"), | ||
stderr=subprocess.DEVNULL, | ||
stdout=subprocess.DEVNULL, | ||
stdin=subprocess.DEVNULL, | ||
) | ||
endpoint_url = f"http://127.0.0.1:{port}/" | ||
wait_s3_up(endpoint_url) | ||
try: | ||
yield {"endpoint_url": endpoint_url} | ||
finally: | ||
proc.terminate() | ||
proc.wait() | ||
server = ThreadedMotoServer(ip_address="127.0.0.1", port=5555) | ||
server.start() | ||
yield server | ||
server.stop() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def set_cache( | ||
tmpdir: pathlib.Path, | ||
tmp_path: pathlib.Path, | ||
postgresql: psycopg.Connection[Any], | ||
request: pytest.FixtureRequest, | ||
s3_base: ThreadedMotoServer, | ||
) -> Generator[str, None, None]: | ||
if not hasattr(request, "param") or request.param == "file": | ||
with config.set( | ||
cache_db_urlpath="sqlite:///" + str(tmpdir / "cacholote.db"), | ||
cache_files_urlpath=str(tmpdir / "cache_files"), | ||
cache_db_urlpath="sqlite:///" + str(tmp_path / "cacholote.db"), | ||
cache_files_urlpath=str(tmp_path / "cache_files"), | ||
): | ||
yield "file" | ||
elif request.param == "cads": | ||
pytest.importorskip("s3fs") | ||
botocore_session = pytest.importorskip("botocore.session") | ||
|
||
endpoint_url = f"http://{s3_base._ip_address}:{s3_base._port}/" | ||
client_kwargs = {"endpoint_url": endpoint_url} | ||
test_bucket_name = "test-bucket" | ||
with initialize_s3() as client_kwargs: | ||
session = botocore_session.Session() | ||
client = session.create_client("s3", **client_kwargs) | ||
client.create_bucket(Bucket=test_bucket_name) | ||
with config.set( | ||
cache_db_urlpath=( | ||
f"postgresql+psycopg2://{postgresql.info.user}:@{postgresql.info.host}:" | ||
f"{postgresql.info.port}/{postgresql.info.dbname}" | ||
), | ||
cache_files_urlpath=f"s3://{test_bucket_name}", | ||
cache_files_storage_options=dict(client_kwargs=client_kwargs), | ||
): | ||
yield request.param | ||
requests.post(f"{endpoint_url}moto-api/reset") | ||
session = botocore.session.Session() | ||
client = session.create_client("s3", **client_kwargs) | ||
client.create_bucket(Bucket=test_bucket_name) | ||
with config.set( | ||
cache_db_urlpath=( | ||
f"postgresql+psycopg2://{postgresql.info.user}:@{postgresql.info.host}:" | ||
f"{postgresql.info.port}/{postgresql.info.dbname}" | ||
), | ||
cache_files_urlpath=f"s3://{test_bucket_name}", | ||
cache_files_storage_options={"client_kwargs": client_kwargs}, | ||
): | ||
yield request.param | ||
else: | ||
raise ValueError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters