Skip to content

Commit

Permalink
Run git-annex' testremote on the cds remote (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss authored Apr 6, 2024
1 parent 19fa800 commit bb7d987
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
30 changes: 30 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,41 @@

import datalad.api as da
import pytest
from _pytest.fixtures import SubRequest
from datalad.conftest import setup_package # noqa: F401


@pytest.fixture
def empty_dataset(tmp_path: pathlib.Path) -> da.Dataset:
dataset = da.create(tmp_path)
dataset.configuration("set", [("remote.cds.dry-run", "true")], scope="local")
yield dataset
dataset.drop(what="all", reckless="kill", recursive=True)


@pytest.fixture(params=["non-lazy", "lazy"])
def single_file_dataset(request: SubRequest, empty_dataset: da.Dataset) -> da.Dataset:
request_dict = {
"dataset": "reanalysis-era5-pressure-levels",
"sub-selection": {
"variable": "temperature",
"pressure_level": "1000",
"product_type": "reanalysis",
"date": "2017-12-01/2017-12-31",
"time": "12:00",
"format": "grib",
},
}
dataset = empty_dataset
dataset.download_cds(
request_dict,
lazy=request.param == "lazy",
path="download.grib",
)
if request.param == "lazy":
dataset.configuration(
"set",
[("remote.cds.annex-security-allow-unverified-downloads", "ACKTHPPT")],
scope="local",
)
return dataset
23 changes: 23 additions & 0 deletions tests/test_cds_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import subprocess

import datalad.api as da


def test_with_git_annex_testremote(single_file_dataset: da.Dataset) -> None:
dataset = single_file_dataset
dataset.get("download.grib")
result = subprocess.run(
[
"git",
"-C",
dataset.path,
"annex",
"testremote",
"cds",
"--test-readonly",
"download.grib",
],
capture_output=True,
text=True,
)
assert result.returncode == 0, f"{result.stdout=}\n{result.stderr=}"
1 change: 0 additions & 1 deletion tests/test_download_cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@pytest.mark.parametrize("cds_request", [request_dict, json.dumps(request_dict)])
def test_download_cds(cds_request: Union[str, dict], empty_dataset: da.Dataset) -> None:
dataset = empty_dataset
dataset.configuration("set", [("remote.cds.dry-run", "true")], scope="local")
dataset.download_cds(
cds_request,
path="download.grib",
Expand Down

0 comments on commit bb7d987

Please sign in to comment.