Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
improve integration test (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
malmans2 authored Sep 18, 2024
1 parent 5790c43 commit eb10f24
Showing 1 changed file with 41 additions and 61 deletions.
102 changes: 41 additions & 61 deletions tests/integration_test_30_remote.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import datetime
import filecmp
import os
import pathlib

import pytest
Expand Down Expand Up @@ -40,51 +43,46 @@ def test_collection_retrieve_with_dummy_adaptor(
target = str(tmp_path / "dummy.txt")

res = dataset.retrieve(
_timestamp=datetime.datetime.now().isoformat(),
target=target,
)

assert isinstance(res, str)
assert res.endswith(target)
assert res == target
assert os.path.exists(target)


def test_collection_retrieve_with_url_cds_adaptor(
cat: catalogue.Catalogue, tmp_path: pathlib.Path
) -> None:
collection_id = "test-adaptor-url"
dataset = cat.collection(collection_id)
target = str(tmp_path / "wfde1.zip")

request = {
"variable": "grid_point_altitude",
"reference_dataset": "cru",
"version": "2.1",
"format": "zip",
"_timestamp": datetime.datetime.now().isoformat(),
}
target1 = str(tmp_path / "wfde1.zip")
res = dataset.retrieve(
variable="grid_point_altitude",
reference_dataset="cru",
version="2.1",
target=target,
**request,
target=target1,
)
assert res == target1
assert os.path.exists(target1)

assert isinstance(res, str)
assert res.endswith(target)

target = str(tmp_path / "wfde2.zip")

target2 = str(tmp_path / "wfde2.zip")
res = dataset.retrieve(
variable="grid_point_altitude",
reference_dataset="cru",
version="2.1",
format="zip",
target=target,
**request,
target=target2,
)

assert isinstance(res, str)
assert res.endswith(target)
assert filecmp.cmp(target1, target2)


def test_collection_retrieve_with_direct_mars_cds_adaptor(
cat: catalogue.Catalogue, tmp_path: pathlib.Path
) -> None:
collection_id = "test-adaptor-direct-mars"
dataset = cat.collection(collection_id)
target = str(tmp_path / "era5-complete.grib")

request = {
"levelist": "1",
"dataset": "reanalysis",
Expand All @@ -96,52 +94,34 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor(
"number": "all",
"class": "ea",
}
res = dataset.retrieve(target=target, **request)

assert isinstance(res, str)
assert res.endswith(target)


def test_collection_retrieve_with_mars_cds_adaptor(
cat: catalogue.Catalogue, tmp_path: pathlib.Path
) -> None:
collection_id = "test-adaptor-mars"
dataset = cat.collection(collection_id)
target = str(tmp_path / "era5.grib")

target = str(tmp_path / "era5-complete.grib")
res = dataset.retrieve(
product_type="reanalysis",
variable="2m_temperature",
year="2016",
month="01",
day="02",
time="00:00",
target=target,
_timestamp=datetime.datetime.now().isoformat(),
**request,
)
assert res == target
assert os.path.exists(target)

assert isinstance(res, str)
assert res.endswith(target)


@pytest.mark.skip(reason="discontinued adaptor")
def test_collection_retrieve_with_legacy_cds_adaptor(
def test_collection_retrieve_with_mars_cds_adaptor(
cat: catalogue.Catalogue, tmp_path: pathlib.Path
) -> None:
collection_id = "test-adaptor-legacy"
collection_id = "test-adaptor-mars"
dataset = cat.collection(collection_id)
request = {
"product_type": "reanalysis",
"variable": "2m_temperature",
"year": "2016",
"month": "01",
"day": "02",
"time": "00:00",
}
target = str(tmp_path / "era5.grib")

res = dataset.retrieve(
product_type="reanalysis",
variable="temperature",
year="2016",
month="01",
day="02",
time="00:00",
level="1000",
**request,
_timestamp=datetime.datetime.now().isoformat(),
target=target,
retry_options={"maximum_tries": 0},
)

assert isinstance(res, str)
assert res.endswith(target)
assert res == target
assert os.path.exists(target)

0 comments on commit eb10f24

Please sign in to comment.