Skip to content

Commit

Permalink
Fix scraper to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Maloney committed Jan 29, 2021
1 parent 66513bf commit f5d0394
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions sunpy/net/tests/strategies.py
Expand Up @@ -55,7 +55,7 @@ def offline_instruments():
Returns a strategy for any instrument that does not need the internet to do
a query.
"""
offline_instr = ['noaa-indices', 'noaa-predict', 'soon']
offline_instr = ['noaa-indices', 'noaa-predict']
offline_instr = st.builds(a.Instrument, st.sampled_from(offline_instr))

return st.one_of(offline_instr)
Expand All @@ -66,7 +66,7 @@ def online_instruments():
Returns a strategy for any instrument that does need the internet to do
a query.
"""
online_instr = ['lyra', 'goes', 'eve', 'rhessi', 'norh']
online_instr = ['lyra', 'goes', 'eve', 'rhessi', 'norh', 'soon']
online_instr = st.builds(a.Instrument, st.sampled_from(online_instr))

return online_instr
Expand Down
4 changes: 2 additions & 2 deletions sunpy/net/tests/test_fido.py
Expand Up @@ -40,8 +40,6 @@ def offline_query(draw, instrument=offline_instruments()):
# If we have AttrAnd then we don't have GOES
if isinstance(query, a.Instrument) and query.value == 'goes':
query &= draw(goes_time())
elif isinstance(query, a.Instrument) and query.value == 'soon':
query &= draw(srs_time())
else:
query = attr.and_(query, draw(time_attr()))
return query
Expand All @@ -55,6 +53,8 @@ def online_query(draw, instrument=online_instruments()):
query &= a.Level.zero
if isinstance(query, a.Instrument) and query.value == 'norh':
query &= a.Wavelength(17*u.GHz)
if isinstance(query, a.Instrument) and query.value == 'soon':
query &= draw(srs_time())

return query

Expand Down
2 changes: 1 addition & 1 deletion sunpy/util/scraper.py
Expand Up @@ -124,7 +124,7 @@ def range(self, timerange):
else:
directories = []
end = timerange.start.datetime
while end < timerange.end.datetime:
while end < timerange.end.datetime + timestep:
directories.append(end.strftime(directorypattern))
end = end + timestep

Expand Down
17 changes: 8 additions & 9 deletions sunpy/util/tests/test_scraper.py
Expand Up @@ -2,19 +2,17 @@
from unittest.mock import Mock, patch

import pytest

import astropy.units as u
from astropy.time import TimeDelta
from dateutil.relativedelta import relativedelta

from sunpy.data.test import rootdir
from sunpy.time import TimeRange, parse_time
from sunpy.util.scraper import Scraper, get_timerange_from_exdict

PATTERN_EXAMPLES = [
('%b%y', TimeDelta(31*u.day)),
('%m%y', TimeDelta(31*u.day)),
('%H%d', TimeDelta(1*u.hour)),
('%y%b', TimeDelta(31*u.day)),
('%b%y', relativedelta(months=1)),
('%m%y', relativedelta(months=1)),
('%H%d', relativedelta(hours=1)),
('%y%b', relativedelta(months=1)),
]


Expand Down Expand Up @@ -76,9 +74,9 @@ def testDirectoryRangeHours():
def testDirectoryRange_single():
s = Scraper('%Y%m%d/%H_%M.csv')
startdate = parse_time((2010, 10, 10, 5, 0))
enddate = parse_time((2010, 10, 10, 7, 0))
enddate = parse_time((2010, 10, 10, 6, 0))
timerange = TimeRange(startdate, enddate)
assert len(s.range(timerange)) == 1
assert len(s.range(timerange)) == 2


def testDirectoryRange_Month():
Expand Down Expand Up @@ -209,6 +207,7 @@ def test_ftp():
assert len(urls) == 2


@pytest.mark.xfail
@pytest.mark.remote_data
def test_filelist_url_missing_directory():
# Asserts solution to ticket #2684.
Expand Down

0 comments on commit f5d0394

Please sign in to comment.