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

Commit eb10f24

Browse files
authored
improve integration test (#76)
1 parent 5790c43 commit eb10f24

File tree

1 file changed

+41
-61
lines changed

1 file changed

+41
-61
lines changed

tests/integration_test_30_remote.py

Lines changed: 41 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import datetime
2+
import filecmp
3+
import os
14
import pathlib
25

36
import pytest
@@ -40,51 +43,46 @@ def test_collection_retrieve_with_dummy_adaptor(
4043
target = str(tmp_path / "dummy.txt")
4144

4245
res = dataset.retrieve(
46+
_timestamp=datetime.datetime.now().isoformat(),
4347
target=target,
4448
)
45-
46-
assert isinstance(res, str)
47-
assert res.endswith(target)
49+
assert res == target
50+
assert os.path.exists(target)
4851

4952

5053
def test_collection_retrieve_with_url_cds_adaptor(
5154
cat: catalogue.Catalogue, tmp_path: pathlib.Path
5255
) -> None:
5356
collection_id = "test-adaptor-url"
5457
dataset = cat.collection(collection_id)
55-
target = str(tmp_path / "wfde1.zip")
56-
58+
request = {
59+
"variable": "grid_point_altitude",
60+
"reference_dataset": "cru",
61+
"version": "2.1",
62+
"format": "zip",
63+
"_timestamp": datetime.datetime.now().isoformat(),
64+
}
65+
target1 = str(tmp_path / "wfde1.zip")
5766
res = dataset.retrieve(
58-
variable="grid_point_altitude",
59-
reference_dataset="cru",
60-
version="2.1",
61-
target=target,
67+
**request,
68+
target=target1,
6269
)
70+
assert res == target1
71+
assert os.path.exists(target1)
6372

64-
assert isinstance(res, str)
65-
assert res.endswith(target)
66-
67-
target = str(tmp_path / "wfde2.zip")
68-
73+
target2 = str(tmp_path / "wfde2.zip")
6974
res = dataset.retrieve(
70-
variable="grid_point_altitude",
71-
reference_dataset="cru",
72-
version="2.1",
73-
format="zip",
74-
target=target,
75+
**request,
76+
target=target2,
7577
)
76-
77-
assert isinstance(res, str)
78-
assert res.endswith(target)
78+
assert filecmp.cmp(target1, target2)
7979

8080

8181
def test_collection_retrieve_with_direct_mars_cds_adaptor(
8282
cat: catalogue.Catalogue, tmp_path: pathlib.Path
8383
) -> None:
8484
collection_id = "test-adaptor-direct-mars"
8585
dataset = cat.collection(collection_id)
86-
target = str(tmp_path / "era5-complete.grib")
87-
8886
request = {
8987
"levelist": "1",
9088
"dataset": "reanalysis",
@@ -96,52 +94,34 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor(
9694
"number": "all",
9795
"class": "ea",
9896
}
99-
res = dataset.retrieve(target=target, **request)
100-
101-
assert isinstance(res, str)
102-
assert res.endswith(target)
103-
104-
105-
def test_collection_retrieve_with_mars_cds_adaptor(
106-
cat: catalogue.Catalogue, tmp_path: pathlib.Path
107-
) -> None:
108-
collection_id = "test-adaptor-mars"
109-
dataset = cat.collection(collection_id)
110-
target = str(tmp_path / "era5.grib")
111-
97+
target = str(tmp_path / "era5-complete.grib")
11298
res = dataset.retrieve(
113-
product_type="reanalysis",
114-
variable="2m_temperature",
115-
year="2016",
116-
month="01",
117-
day="02",
118-
time="00:00",
11999
target=target,
100+
_timestamp=datetime.datetime.now().isoformat(),
101+
**request,
120102
)
103+
assert res == target
104+
assert os.path.exists(target)
121105

122-
assert isinstance(res, str)
123-
assert res.endswith(target)
124106

125-
126-
@pytest.mark.skip(reason="discontinued adaptor")
127-
def test_collection_retrieve_with_legacy_cds_adaptor(
107+
def test_collection_retrieve_with_mars_cds_adaptor(
128108
cat: catalogue.Catalogue, tmp_path: pathlib.Path
129109
) -> None:
130-
collection_id = "test-adaptor-legacy"
110+
collection_id = "test-adaptor-mars"
131111
dataset = cat.collection(collection_id)
112+
request = {
113+
"product_type": "reanalysis",
114+
"variable": "2m_temperature",
115+
"year": "2016",
116+
"month": "01",
117+
"day": "02",
118+
"time": "00:00",
119+
}
132120
target = str(tmp_path / "era5.grib")
133-
134121
res = dataset.retrieve(
135-
product_type="reanalysis",
136-
variable="temperature",
137-
year="2016",
138-
month="01",
139-
day="02",
140-
time="00:00",
141-
level="1000",
122+
**request,
123+
_timestamp=datetime.datetime.now().isoformat(),
142124
target=target,
143-
retry_options={"maximum_tries": 0},
144125
)
145-
146-
assert isinstance(res, str)
147-
assert res.endswith(target)
126+
assert res == target
127+
assert os.path.exists(target)

0 commit comments

Comments
 (0)