Skip to content

Commit 5e80cba

Browse files
committed
add tests for HTTPError on bad inputs
1 parent 12fcd7a commit 5e80cba

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/iotools/test_merra2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
import pvlib
88
import os
9+
import requests
910
from tests.conftest import RERUNS, RERUNS_DELAY, requires_earthdata_credentials
1011

1112

@@ -81,3 +82,30 @@ def test_get_merra2_timezones(params, expected, expected_meta):
8182
df, meta = pvlib.iotools.get_merra2(**params)
8283
pd.testing.assert_frame_equal(df, expected, check_freq=False)
8384
assert meta == expected_meta
85+
86+
87+
@requires_earthdata_credentials
88+
@pytest.mark.remote_data
89+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
90+
def test_get_merra2_bad_credentials(params, expected, expected_meta):
91+
params['username'] = 'nonexistent'
92+
with pytest.raises(requests.exceptions.HTTPError, match='Unauthorized'):
93+
pvlib.iotools.get_merra2(**params)
94+
95+
96+
@requires_earthdata_credentials
97+
@pytest.mark.remote_data
98+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
99+
def test_get_merra2_bad_dataset(params, expected, expected_meta):
100+
params['dataset'] = 'nonexistent'
101+
with pytest.raises(requests.exceptions.HTTPError, match='404 for url'):
102+
pvlib.iotools.get_merra2(**params)
103+
104+
105+
@requires_earthdata_credentials
106+
@pytest.mark.remote_data
107+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
108+
def test_get_merra2_bad_variables(params, expected, expected_meta):
109+
params['variables'] = ['nonexistent']
110+
with pytest.raises(requests.exceptions.HTTPError, match='400 for url'):
111+
pvlib.iotools.get_merra2(**params)

0 commit comments

Comments
 (0)