|
1 | 1 | import datetime as dt |
2 | 2 | import pandas as pd |
3 | 3 | import pytest |
| 4 | +from urllib import error |
4 | 5 |
|
5 | 6 | from pandas import Timestamp |
| 7 | +from pandas.testing import assert_frame_equal |
6 | 8 |
|
7 | 9 | from solarforecastarbiter.io.reference_observations import srml |
8 | 10 | from solarforecastarbiter.datamodel import Site |
@@ -150,3 +152,29 @@ def test_init_site_observations( |
150 | 152 | srml.initialize_site_observations(mock_api, test_site) |
151 | 153 | assert mock_create_obs.call_count == 5 |
152 | 154 | 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