Skip to content

Commit d9ece4c

Browse files
committed
Add tests for erroneous inputs
1 parent f743b8e commit d9ece4c

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

pvlib/iotools/psm4.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def get_nsrdb_psm4_polar(latitude, longitude, api_key, email,
696696
Returns
697697
-------
698698
data : pandas.DataFrame
699-
timeseries data from NLR PSM4
699+
timeseries data from NLR PSM4 Polar
700700
metadata : dict
701701
metadata from NLR PSM4 about the record, see
702702
:func:`pvlib.iotools.read_nsrdb_psm4` for fields
@@ -843,7 +843,7 @@ def get_nsrdb_psm4_polar_tmy(latitude, longitude, api_key, email, year='tmy',
843843
Returns
844844
-------
845845
data : pandas.DataFrame
846-
timeseries data from NLR PSM4
846+
timeseries data from NLR PSM4 Polar TMY
847847
metadata : dict
848848
metadata from NLR PSM4 about the record, see
849849
:func:`pvlib.iotools.read_nsrdb_psm4` for fields

tests/iotools/test_psm4.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,39 @@ def test_get_nsrdb_psm4_aggregated_errors(
184184
assert "OVER_RATE_LIMIT" not in str(excinfo.value)
185185

186186

187+
@pytest.mark.remote_data
188+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
189+
def test_get_nsrdb_psm4_polar_errors(nlr_api_key):
190+
"""Test get_nsrdb_psm4_polar() for bad input scenarios."""
191+
# Bad latitude/longitude -> Coordinates were outside the polar area.
192+
with pytest.raises(HTTPError) as excinfo:
193+
psm4.get_nsrdb_psm4_polar(55, 0, nlr_api_key, PVLIB_EMAIL, year=2023)
194+
# ensure the HTTPError caught isn't due to overuse of the API key
195+
assert "OVER_RATE_LIMIT" not in str(excinfo.value)
196+
# Bad API key -> HTTP 403 forbidden because api_key is rejected
197+
with pytest.raises(HTTPError) as excinfo:
198+
psm4.get_nsrdb_psm4_polar(
199+
LATITUDE_POLAR, LONGITUDE_POLAR, "bad_key", PVLIB_EMAIL, year=2023)
200+
assert "OVER_RATE_LIMIT" not in str(excinfo.value)
201+
202+
203+
@pytest.mark.remote_data
204+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
205+
def test_get_nsrdb_psm4_polar_tmy_errors(nlr_api_key):
206+
"""Test get_nsrdb_psm4_polar_tmy() for bad input scenarios."""
207+
# Bad latitude/longitude -> Coordinates were outside the polar area.
208+
with pytest.raises(HTTPError) as excinfo:
209+
psm4.get_nsrdb_psm4_polar_tmy(
210+
55, 0, nlr_api_key, PVLIB_EMAIL, year="tmy-2023")
211+
# ensure the HTTPError caught isn't due to overuse of the API key
212+
assert "OVER_RATE_LIMIT" not in str(excinfo.value)
213+
# Bad API key -> HTTP 403 forbidden because api_key is rejected
214+
with pytest.raises(HTTPError) as excinfo:
215+
psm4.get_nsrdb_psm4_polar_tmy(
216+
LATITUDE_POLAR, LONGITUDE_POLAR, "bad_key", PVLIB_EMAIL,
217+
year="tmy-2023")
218+
assert "OVER_RATE_LIMIT" not in str(excinfo.value)
219+
187220
@pytest.fixture
188221
def io_input(request):
189222
"""file-like object for read_nsrdb_psm4"""

0 commit comments

Comments
 (0)