|
2 | 2 | import numpy as np |
3 | 3 | import pandas as pd |
4 | 4 | import pytest |
| 5 | +import requests |
5 | 6 | from astropy.utils.data import get_pkg_data_filename |
6 | 7 | from pathlib import Path |
7 | 8 | from seppy.loader.bepi import bepi_sixsp_l3_loader |
|
10 | 11 | from seppy.loader.soho import soho_load |
11 | 12 | from seppy.loader.solo import mag_load |
12 | 13 | from seppy.loader.stereo import stereo_load |
13 | | -from seppy.loader.wind import wind3dp_load |
| 14 | +from seppy.loader.wind import wind3dp_load, wind3dp_single_download |
| 15 | +from unittest.mock import patch |
14 | 16 |
|
15 | 17 |
|
16 | 18 | def test_bepi_sixs_load_online(): |
@@ -237,3 +239,22 @@ def test_wind3dp_load_offline(): |
237 | 239 | assert meta['FLUX_LABELS'].flatten()[0] == 'ElecNoFlux_Ch1_Often~27keV ' |
238 | 240 | # Check that fillvals are replaced by NaN |
239 | 241 | assert np.sum(np.isnan(df['FLUX_0'])) == 352 |
| 242 | + |
| 243 | + |
| 244 | +def test_wind3dp_single_download_exceptions(): |
| 245 | + """ |
| 246 | + Test wind3dp_single_download with mocked request exceptions. |
| 247 | + """ |
| 248 | + wind_file = 'wi_sfsp_3dp_20220602_v01.cdf' |
| 249 | + |
| 250 | + with patch('requests.get', side_effect=requests.exceptions.ReadTimeout): |
| 251 | + downloaded_file = wind3dp_single_download(wind_file) |
| 252 | + assert downloaded_file == [] |
| 253 | + |
| 254 | + with patch('requests.get', side_effect=requests.exceptions.Timeout): |
| 255 | + downloaded_file = wind3dp_single_download(wind_file) |
| 256 | + assert downloaded_file == [] |
| 257 | + |
| 258 | + with patch('requests.get', side_effect=requests.exceptions.HTTPError): |
| 259 | + with pytest.raises(requests.exceptions.HTTPError): |
| 260 | + downloaded_file = wind3dp_single_download(wind_file) |
0 commit comments