|
6 | 6 | import pytest |
7 | 7 | import pvlib |
8 | 8 | import os |
| 9 | +import requests |
9 | 10 | from tests.conftest import RERUNS, RERUNS_DELAY, requires_earthdata_credentials |
10 | 11 |
|
11 | 12 |
|
@@ -81,3 +82,30 @@ def test_get_merra2_timezones(params, expected, expected_meta): |
81 | 82 | df, meta = pvlib.iotools.get_merra2(**params) |
82 | 83 | pd.testing.assert_frame_equal(df, expected, check_freq=False) |
83 | 84 | 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