Skip to content

Commit 2dc1f9c

Browse files
committed
more test coverage
1 parent c618dac commit 2dc1f9c

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

solarforecastarbiter/io/reference_observations/srml.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ def request_data(site, year, month):
7777
7878
Parameters
7979
----------
80-
interval_length: int
81-
The number of minutes between each timestep in the data. Used
82-
to lookup filetypes in FILE_TYPE_MAP.
83-
station: string
84-
The two character station abbreviation found in filenames.
80+
site: :py:class:`solarforecastarbiter.datamodel.Site`
8581
year: int
8682
The year of the data to request.
8783
month: int

solarforecastarbiter/io/reference_observations/tests/test_srml.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import datetime as dt
22
import pandas as pd
33
import pytest
4+
from urllib import error
45

56
from pandas import Timestamp
7+
from pandas.testing import assert_frame_equal
68

79
from solarforecastarbiter.io.reference_observations import srml
810
from solarforecastarbiter.datamodel import Site
@@ -150,3 +152,29 @@ def test_init_site_observations(
150152
srml.initialize_site_observations(mock_api, test_site)
151153
assert mock_create_obs.call_count == 5
152154
assert mock_chk_post.call_count == 2
155+
156+
157+
def request_data_test(mocker, exception, test_site, test_data):
158+
get_func = mocker.patch(
159+
'solarforecastarbiter.io.reference_observations.srml.iotools.'
160+
'read_srml_month_from_solardat')
161+
get_func.return_value = test_data
162+
data = srml.request_data(test_site, 1, 1)
163+
assert_frame_equal(data, test_data)
164+
165+
166+
@pytest.mark.parametrize('exception', [
167+
pd.errors.EmptyDataError,
168+
error.URLError,
169+
])
170+
def request_data_test_warnings(mocker, exception, test_site):
171+
logger = mocker.patch(
172+
'solarforecastarbiter.io.reference_observations.srml.iotools.'
173+
'logger.warning')
174+
get_func = mocker.patch(
175+
'solarforecastarbiter.io.reference_observations.srml.iotools.'
176+
'read_srml_month_from_solardat')
177+
get_func.side_effect = exception()
178+
data = srml.request_data(test_site, 1, 1)
179+
assert logger.call_count == 5
180+
assert data is None

0 commit comments

Comments
 (0)