Skip to content

Commit 2784b2f

Browse files
add tests
1 parent 9927aeb commit 2784b2f

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

tests/iotools/test_surfrad.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import urllib.error
2+
13
import pandas as pd
24
import pytest
35

46
from pvlib.iotools import surfrad
5-
from tests.conftest import TESTS_DATA_DIR, RERUNS, RERUNS_DELAY
7+
from tests.conftest import (
8+
TESTS_DATA_DIR,
9+
assert_frame_equal,
10+
RERUNS,
11+
RERUNS_DELAY,
12+
)
613

714
testfile = TESTS_DATA_DIR / 'surfrad-slv16001.dat'
815
network_testfile = ('ftp://aftp.cmdl.noaa.gov/data/radiation/surfrad/'
@@ -73,3 +80,39 @@ def test_read_surfrad_metadata():
7380
'tz': 'UTC'}
7481
_, metadata = surfrad.read_surfrad(testfile)
7582
assert metadata == expected
83+
84+
85+
@pytest.mark.remote_data
86+
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
87+
def test_get_surfrad():
88+
df, meta = surfrad.get_surfrad('slv', '2016-01-01', '2016-01-01')
89+
90+
assert meta['station'] == 'slv'
91+
assert isinstance(meta['filenames'], list)
92+
93+
assert len(df) == 1440
94+
assert df.index[0] == pd.to_datetime('2016-01-01 00:00+00:00')
95+
assert df.index[-1] == pd.to_datetime('2016-01-01 23:59+00:00')
96+
97+
expected, _ = surfrad.read_surfrad(testfile)
98+
assert_frame_equal(df, expected)
99+
100+
101+
@pytest.mark.remote_data
102+
def test_get_surfrad_missing_day():
103+
# SURFRAD's Alamosa station data begins 2014-07-28 (slv14209.dat), so
104+
# requesting the day before that will raise a warning
105+
message = 'The following file was not found: slv/2014/slv14208.dat'
106+
with pytest.warns(UserWarning, match=message):
107+
df, meta = surfrad.get_surfrad('slv', '2014-07-27', '2014-07-28')
108+
109+
# but the data for 2014-07-28 is still returned
110+
assert not df.empty
111+
112+
113+
@pytest.mark.remote_data
114+
def test_get_surfrad_no_data():
115+
message = "No data retrieved for station 'xxx'"
116+
with pytest.warns(UserWarning):
117+
with pytest.raises(ValueError, match=message):
118+
surfrad.get_surfrad('xxx', '2016-01-01', '2016-01-01')

0 commit comments

Comments
 (0)