1
+ import datetime
2
+ import filecmp
3
+ import os
1
4
import pathlib
2
5
3
6
import pytest
@@ -40,51 +43,46 @@ def test_collection_retrieve_with_dummy_adaptor(
40
43
target = str (tmp_path / "dummy.txt" )
41
44
42
45
res = dataset .retrieve (
46
+ _timestamp = datetime .datetime .now ().isoformat (),
43
47
target = target ,
44
48
)
45
-
46
- assert isinstance (res , str )
47
- assert res .endswith (target )
49
+ assert res == target
50
+ assert os .path .exists (target )
48
51
49
52
50
53
def test_collection_retrieve_with_url_cds_adaptor (
51
54
cat : catalogue .Catalogue , tmp_path : pathlib .Path
52
55
) -> None :
53
56
collection_id = "test-adaptor-url"
54
57
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" )
57
66
res = dataset .retrieve (
58
- variable = "grid_point_altitude" ,
59
- reference_dataset = "cru" ,
60
- version = "2.1" ,
61
- target = target ,
67
+ ** request ,
68
+ target = target1 ,
62
69
)
70
+ assert res == target1
71
+ assert os .path .exists (target1 )
63
72
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" )
69
74
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 ,
75
77
)
76
-
77
- assert isinstance (res , str )
78
- assert res .endswith (target )
78
+ assert filecmp .cmp (target1 , target2 )
79
79
80
80
81
81
def test_collection_retrieve_with_direct_mars_cds_adaptor (
82
82
cat : catalogue .Catalogue , tmp_path : pathlib .Path
83
83
) -> None :
84
84
collection_id = "test-adaptor-direct-mars"
85
85
dataset = cat .collection (collection_id )
86
- target = str (tmp_path / "era5-complete.grib" )
87
-
88
86
request = {
89
87
"levelist" : "1" ,
90
88
"dataset" : "reanalysis" ,
@@ -96,52 +94,34 @@ def test_collection_retrieve_with_direct_mars_cds_adaptor(
96
94
"number" : "all" ,
97
95
"class" : "ea" ,
98
96
}
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" )
112
98
res = dataset .retrieve (
113
- product_type = "reanalysis" ,
114
- variable = "2m_temperature" ,
115
- year = "2016" ,
116
- month = "01" ,
117
- day = "02" ,
118
- time = "00:00" ,
119
99
target = target ,
100
+ _timestamp = datetime .datetime .now ().isoformat (),
101
+ ** request ,
120
102
)
103
+ assert res == target
104
+ assert os .path .exists (target )
121
105
122
- assert isinstance (res , str )
123
- assert res .endswith (target )
124
106
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 (
128
108
cat : catalogue .Catalogue , tmp_path : pathlib .Path
129
109
) -> None :
130
- collection_id = "test-adaptor-legacy "
110
+ collection_id = "test-adaptor-mars "
131
111
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
+ }
132
120
target = str (tmp_path / "era5.grib" )
133
-
134
121
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 (),
142
124
target = target ,
143
- retry_options = {"maximum_tries" : 0 },
144
125
)
145
-
146
- assert isinstance (res , str )
147
- assert res .endswith (target )
126
+ assert res == target
127
+ assert os .path .exists (target )
0 commit comments