From eb10f24866b62b6387a3916264dab675e3c799e7 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Wed, 18 Sep 2024 10:00:56 +0200 Subject: [PATCH] improve integration test (#76) --- tests/integration_test_30_remote.py | 102 +++++++++++----------------- 1 file changed, 41 insertions(+), 61 deletions(-) diff --git a/tests/integration_test_30_remote.py b/tests/integration_test_30_remote.py index 95fe321..fad54ce 100644 --- a/tests/integration_test_30_remote.py +++ b/tests/integration_test_30_remote.py @@ -1,3 +1,6 @@ +import datetime +import filecmp +import os import pathlib import pytest @@ -40,11 +43,11 @@ 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( @@ -52,30 +55,27 @@ def test_collection_retrieve_with_url_cds_adaptor( ) -> 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( @@ -83,8 +83,6 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor( ) -> None: collection_id = "test-adaptor-direct-mars" dataset = cat.collection(collection_id) - target = str(tmp_path / "era5-complete.grib") - request = { "levelist": "1", "dataset": "reanalysis", @@ -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)