Skip to content

Commit 8f4da88

Browse files
committed
fix tests, again
1 parent fd7f06d commit 8f4da88

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

pvlib/iotools/ecmwf.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def get_era5(latitude, longitude, start, end, variables, api_key,
126126
}
127127
}
128128
slug = "processes/reanalysis-era5-single-levels-timeseries/execution"
129-
response = requests.post(url + slug, json=params, headers=headers)
129+
response = requests.post(url + slug, json=params, headers=headers,
130+
timeout=timeout)
130131
submission_response = response.json()
131132
if not response.ok:
132133
raise Exception(submission_response) # likely need to accept license
@@ -138,7 +139,7 @@ def get_era5(latitude, longitude, start, end, variables, api_key,
138139
poll_interval = 1
139140
num_polls = 0
140141
while True:
141-
response = requests.get(url + slug, headers=headers)
142+
response = requests.get(url + slug, headers=headers, timeout=timeout)
142143
poll_response = response.json()
143144
job_status = poll_response['status']
144145

@@ -162,12 +163,12 @@ def get_era5(latitude, longitude, start, end, variables, api_key,
162163

163164
# Step 3: get the download link for our requested dataset
164165
slug = "jobs/" + job_id + "/results"
165-
response = requests.get(url + slug, headers=headers)
166+
response = requests.get(url + slug, headers=headers, timeout=timeout)
166167
results_response = response.json()
167168
download_url = results_response['asset']['value']['href']
168169

169170
# Step 4: finally, download our dataset. it's a zipfile of one CSV
170-
response = requests.get(download_url)
171+
response = requests.get(download_url, timeout=timeout)
171172
zipbuffer = BytesIO(response.content)
172173
archive = zipfile.ZipFile(zipbuffer)
173174
filename = archive.filelist[0].filename

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def nrel_api_key():
139139
has_ecmwf_credentials = False
140140

141141
requires_ecmwf_credentials = pytest.mark.skipif(
142-
not has_solaranywhere_credentials,
142+
not has_ecmwf_credentials,
143143
reason='requires ECMWF credentials')
144144

145145

tests/iotools/test_ecmwf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def params():
1515

1616
return {
1717
'latitude': 40.01, 'longitude': -80.01,
18-
'start': '2020-06-01', 'end': '2020-06-02',
18+
'start': '2020-06-01', 'end': '2020-06-01',
1919
'variables': ['ghi', 'temp_air'],
2020
'api_key': api_key,
2121
}
@@ -41,7 +41,7 @@ def expected():
4141
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
4242
def test_get_era5(params, expected):
4343
df, meta = pvlib.iotools.get_era5(**params)
44-
pd.testing.assert_frame_equal(df, expected, check_freq=False)
44+
pd.testing.assert_frame_equal(df, expected, check_freq=False, atol=0.1)
4545
assert meta['longitude'] == -80.0
4646
assert meta['latitude'] == 40.0
4747
assert isinstance(meta['jobID'], str)
@@ -53,7 +53,9 @@ def test_get_era5(params, expected):
5353
def test_get_era5_map_variables(params, expected):
5454
df, meta = pvlib.iotools.get_era5(**params, map_variables=False)
5555
expected = expected.rename(columns={'temp_air': 't2m', 'ghi': 'ssrd'})
56-
pd.testing.assert_frame_equal(df, expected, check_freq=False)
56+
expected['t2m'] += 273.15 # undo unit conversions
57+
expected['ssrd'] *= 3600
58+
pd.testing.assert_frame_equal(df, expected, check_freq=False, atol=0.1)
5759
assert meta['longitude'] == -80.0
5860
assert meta['latitude'] == 40.0
5961
assert isinstance(meta['jobID'], str)

0 commit comments

Comments
 (0)