def test_can_handle_query(): ans1 = eve.EVEClient._can_handle_query(Time('2012/8/9', '2012/8/10'), Instrument('eve'), Level(0)) assert ans1 is True ans2 = eve.EVEClient._can_handle_query(Time('2012/7/7', '2012/7/7')) assert ans2 is False ans3 = eve.EVEClient._can_handle_query(Time('2012/8/9', '2012/8/10'), Instrument('eve'), Source('sdo')) assert ans3 is False
def test_can_handle_query(): ans1 = noaa.NOAAIndicesClient._can_handle_query( Time('2012/8/9', '2012/8/10'), Instrument('noaa-indices')) assert ans1 ans2 = noaa.NOAAIndicesClient._can_handle_query( Time('2012/7/7', '2012/7/7')) assert not ans2 ans3 = noaa.NOAAIndicesClient._can_handle_query( Time('2012/8/9', '2012/8/10'), Instrument('eve')) assert not ans3
def test_fetch_working(LCClient, tmpdir): """ Tests if the online server for noaa is working. Uses the url : https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json """ qr1 = LCClient.search(Time('2012/10/4', '2012/10/6'), Instrument('noaa-indices')) # Mock QueryResponse object mock_qr = mock_query_object('2012/10/4', '2012/10/6') # Compare if two objects have the same attribute mock_qr = mock_qr.blocks[0] qr = qr1.blocks[0] assert mock_qr['Source'] == qr['Source'] assert mock_qr['Provider'] == qr['Provider'] assert mock_qr['Physobs'] == qr['Physobs'] assert mock_qr['Instrument'] == qr['Instrument'] assert mock_qr['url'] == qr['url'] assert mock_qr['Time'] == qr['Time'] # Assert if the timerange is same assert qr1.time_range() == TimeRange('2012/10/4', '2012/10/6') target_dir = tmpdir.mkdir("down") download_list = LCClient.fetch(qr1, path=target_dir) assert len(download_list) == len(qr1) assert download_list[0].split( '/')[-1] == 'observed-solar-cycle-indices.json'
def test_query(mock_search): qr1 = LCClient.search(Time('2012/8/9', '2012/8/10'), Instrument('noaa-indices')) assert isinstance(qr1, QueryResponse) assert len(qr1) == 1 assert qr1.time_range().start == parse_time('2012/08/09') assert qr1.time_range().end == parse_time('2012/08/10')
def test_fetch_working(tmpdir): """ Tests if the online server for noaa is working. Uses the url : ftp://ftp.swpc.noaa.gov/pub/weekly/RecentIndices.txt """ qr1 = LCClient.search(Time('2012/10/4', '2012/10/6'), Instrument('noaa-indices')) # Mock QueryResponse object mock_qr = mock_query_object('2012/10/4', '2012/10/6') # Compare if two objects have the same attribute mock_qr = mock_qr[0] qr = qr1[0] assert mock_qr.source == qr.source assert mock_qr.provider == qr.provider assert mock_qr.physobs == qr.physobs assert mock_qr.instrument == qr.instrument assert mock_qr.url == qr.url assert mock_qr.time == qr.time # Assert if the timerange is same assert qr1.time_range() == TimeRange('2012/10/4', '2012/10/6') target_dir = tmpdir.mkdir("down") download_list = LCClient.fetch(qr1, path=target_dir) assert len(download_list) == len(qr1) assert download_list[0].split('/')[-1] == 'RecentIndices.txt'
def test_query(LCClient): qr1 = LCClient.search(Time('2012/8/9', '2012/8/10'), Instrument('eve')) assert isinstance(qr1, QueryResponse) assert len(qr1) == 2 assert qr1.time_range().start == parse_time('2012/08/09').to_datetime() assert qr1.time_range().end == parse_time( '2012/08/10 23:59:59.999').to_datetime()
def test_query(LCClient): qr1 = LCClient.search(Time('2012/8/9', '2012/8/10'), Instrument('eve')) assert isinstance(qr1, QueryResponse) assert len(qr1) == 2 assert qr1['Start Time'][0].datetime == parse_time('2012/08/09').datetime assert qr1['End Time'][1].datetime == parse_time( '2012/08/10 23:59:59.999').datetime
def test_fido(mock_wait, mock_search, mock_enqueue, tmp_path, indices_client): path = tmp_path / "sub" path.mkdir() qr1 = Fido.search(Time('2012/10/4', '2012/10/6'), Instrument('noaa-indices')) Fido.fetch(qr1, path=path) # Here we assert that the `fetch` function has called the parfive # Downloader.enqueue_file method with the correct arguments. Everything # that happens after this point should either be tested in the # GenericClient tests or in parfive itself. assert mock_enqueue.called_once_with(("https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json", path / "observed-solar-cycle-indices.json"))
def test_fido(mock_wait, mock_search, mock_enqueue, tmp_path): path = tmp_path / "sub" path.mkdir() qr1 = Fido.search(Time('2012/10/4', '2012/10/6'), Instrument('noaa-indices')) Fido.fetch(qr1, path=path) # Here we assert that the `fetch` function has called the parfive # Downloader.enqueue_file method with the correct arguments. Everything # that happens after this point should either be tested in the # GenericClient tests or in parfive itself. assert mock_enqueue.called_once_with(("ftp://ftp.swpc.noaa.gov/pub/weekly/RecentIndices.txt", path / "RecentIndices.txt"))
def test_can_handle_query(LCClient): ans1 = LCClient._can_handle_query(Time('2012/8/9', '2012/8/10'), Instrument('eve'), Level(0)) assert ans1 is True ans2 = LCClient._can_handle_query(Time('2012/7/7', '2012/7/7')) assert ans2 is False ans3 = LCClient._can_handle_query(Time('2012/8/9', '2012/8/10'), Instrument('eve'), a.Source('sdo')) assert ans3 is True ans4 = LCClient._can_handle_query(Time('2012/8/9', '2012/8/10'), Instrument('eve'), Level('0CS')) assert ans4 is False ans5 = LCClient._can_handle_query(Time('2012/8/9', '2012/8/10'), Instrument('eve'), Level('wibble')) assert ans5 is False ans6 = LCClient._can_handle_query(Time('2012/8/9', '2012/8/10'), Instrument('eve'), Level(0.5)) assert ans6 is False
def test_no_satellite(LCClient): with pytest.raises(ValueError): LCClient.search(Time("1950/01/01", "1950/02/02"), Instrument('XRS'))
def test_new_logic(LCClient): qr = LCClient.search(Time('2012/10/4', '2012/10/6'), Instrument('XRS')) download_list = LCClient.fetch(qr) assert len(download_list) == len(qr)
a.Instrument.xrs, a.goes.SatelliteNumber(13)) for resp in ans1: assert "go13" in resp.url ans1 = LCClient.search(a.Time("1999/1/13", "1999/1/16"), a.Instrument.xrs, a.goes.SatelliteNumber(8)) for resp in ans1: assert "go08" in resp.url @pytest.mark.parametrize("time", [ Time('2005/4/27', '2005/4/27'), Time('2016/2/4', '2016/2/10')]) @pytest.mark.remote_data def test_query(LCClient, time): qr1 = LCClient.search(time, Instrument('XRS')) assert isinstance(qr1, QueryResponse) # We only compare dates here as the start time of the qr will always be the # start of the day. assert qr1.time_range().start.strftime('%Y-%m-%d') == time.start.strftime('%Y-%m-%d') almost_day = TimeDelta(1*u.day - 1*u.millisecond) end = parse_time(time.end.strftime('%Y-%m-%d')) + almost_day assert is_time_equal(qr1.time_range().end, end) @pytest.mark.remote_data
from sunpy.net import attrs as a from sunpy.net._attrs import Instrument, Time from sunpy.net.dataretriever.client import QueryResponse from sunpy.net.fido_factory import UnifiedResponse from sunpy.net.tests.strategies import goes_time from sunpy.time import is_time_equal, parse_time @pytest.fixture def LCClient(): return goes.XRSClient() @pytest.mark.remote_data @pytest.mark.parametrize("timerange,url_start,url_end", [ (Time('1995/06/03 1:00', '1995/06/05'), 'https://umbra.nascom.nasa.gov/goes/fits/1995/go07950603.fits', 'https://umbra.nascom.nasa.gov/goes/fits/1995/go07950605.fits'), (Time('2008/06/02 12:00', '2008/06/04'), 'https://umbra.nascom.nasa.gov/goes/fits/2008/go1020080602.fits', 'https://umbra.nascom.nasa.gov/goes/fits/2008/go1020080604.fits'), (Time('2020/08/02', '2020/08/04'), 'https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/' 'goes16/l2/data/xrsf-l2-flx1s_science/2020/08/sci_xrsf-l2-flx1s_g16_d20200802_v2-1-0.nc', 'https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/' 'goes17/l2/data/xrsf-l2-flx1s_science/2020/08/sci_xrsf-l2-flx1s_g17_d20200804_v2-1-0.nc' ) ]) def test_get_url_for_time_range(LCClient, timerange, url_start, url_end): qresponse = LCClient.search(timerange) urls = [i['url'] for i in qresponse]
from sunpy.net._attrs import Instrument, Time from sunpy.net.dataretriever.client import QueryResponse from sunpy.net.fido_factory import UnifiedResponse from sunpy.net.tests.strategies import range_time from sunpy.time import parse_time from sunpy.time.timerange import TimeRange @pytest.fixture def LCClient(): return lyra.LYRAClient() @pytest.mark.remote_data @pytest.mark.parametrize("timerange,url_start,url_end", [ (Time('2012/1/7', '2012/1/7'), 'http://proba2.oma.be/lyra/data/bsd/2012/01/07/lyra_20120107-000000_lev2_std.fits', 'http://proba2.oma.be/lyra/data/bsd/2012/01/07/lyra_20120107-000000_lev2_std.fits' ), (Time('2012/12/1', '2012/12/2'), 'http://proba2.oma.be/lyra/data/bsd/2012/12/01/lyra_20121201-000000_lev2_std.fits', 'http://proba2.oma.be/lyra/data/bsd/2012/12/02/lyra_20121202-000000_lev2_std.fits' ), (Time('2012/4/7', '2012/4/14'), 'http://proba2.oma.be/lyra/data/bsd/2012/04/07/lyra_20120407-000000_lev2_std.fits', 'http://proba2.oma.be/lyra/data/bsd/2012/04/14/lyra_20120414-000000_lev2_std.fits' ) ]) def test_get_url_for_time_range(LCClient, timerange, url_start, url_end): qresponse = LCClient.search(timerange, a.Level.two) urls = [i['url'] for i in qresponse]
assert isinstance(urls, list) assert urls[0] == url_start assert urls[-1] == url_end @given(range_time('2010-01-06')) def test_can_handle_query(time): LCClient = lyra.LYRAClient() ans1 = LCClient._can_handle_query(time, Instrument('lyra')) assert ans1 is True ans2 = LCClient._can_handle_query(time) assert ans2 is False @pytest.mark.parametrize( "time", [Time('2015/8/27', '2015/8/27'), Time('2016/2/4', '2016/2/6')]) @pytest.mark.remote_data def test_query(LCClient, time): qr1 = LCClient.search(time, Instrument('lyra')) assert isinstance(qr1, QueryResponse) assert qr1.time_range().start == time.start assert qr1.time_range().end == time.end @pytest.mark.remote_data @pytest.mark.parametrize("time,instrument", [(Time('2013/8/27', '2013/8/27'), Instrument('lyra'))] ) def test_get(LCClient, time, instrument): qr1 = LCClient.search(time, instrument)
from sunpy.net import attrs as a from sunpy.net._attrs import Instrument, Level, Time from sunpy.net.dataretriever.client import QueryResponse from sunpy.net.fido_factory import UnifiedResponse from sunpy.net.vso import VSOClient from sunpy.time import parse_time @pytest.fixture def LCClient(): return eve.EVEClient() @pytest.mark.remote_data @pytest.mark.parametrize("timerange,url_start,url_end", [ (Time('2012/4/21', '2012/4/21'), 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120421_EVE_L0CS_DIODES_1m.txt', 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120421_EVE_L0CS_DIODES_1m.txt' ), ( Time('2012/5/5', '2012/5/6'), 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120505_EVE_L0CS_DIODES_1m.txt', 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120506_EVE_L0CS_DIODES_1m.txt', ), ( Time('2012/7/7', '2012/7/14'), 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120707_EVE_L0CS_DIODES_1m.txt', 'http://lasp.colorado.edu/eve/data_access/evewebdata/quicklook/L0CS/SpWx/2012/20120714_EVE_L0CS_DIODES_1m.txt', ) ]) def test_get_url_for_time_range(LCClient, timerange, url_start, url_end):
"query, result", [((a.Time('2020/1/1', '2020/1/2'), a.Instrument('gong')), True), ((a.Time('2020/1/1', '2020/1/2'), a.Instrument('goes')), False), ((a.Time('2020/1/1', '2020/1/2'), a.Instrument('gong'), a.Physobs('LOS_MAGNETIC_FIELD'), a.ExtentType('synoptic')), True), ((a.Time('2020/1/1', '2020/1/2'), a.Instrument('gong'), a.ExtentType('synoptic')), True), ((a.Time('2020/1/1', '2020/1/2'), a.Instrument('gong'), a.ExtentType('FULL_DISK')), False)]) def test_can_handle_query(query, result): assert gong.GONGClient._can_handle_query(*query) == result @pytest.mark.remote_data @pytest.mark.parametrize("time,instrument", [ (Time('2013/8/27', '2013/8/27'), Instrument('gong')), (Time('2020/4/23 17:00', '2020/4/23 21:00'), Instrument('gong')), ]) def test_get(GSClient, time, instrument): qr1 = GSClient.search(time, instrument) assert isinstance(qr1, QueryResponse) download_list = GSClient.fetch(qr1) assert len(download_list) == len(qr1) @pytest.mark.remote_data @pytest.mark.parametrize( "time, instrument", [(a.Time('2019/10/4', '2019/10/4 2:00'), a.Instrument('gong')), (a.Time('2019/12/31 21:00', '2020/1/1'), a.Instrument('gong'))]) def test_fido(time, instrument):
Time('2012/8/9', '2012/8/10'), Instrument('eve'), Level(0.5)) assert ans6 is False @pytest.mark.remote_data def test_query(): qr1 = LCClient.search(Time('2012/8/9', '2012/8/10'), Instrument('eve')) assert isinstance(qr1, QueryResponse) assert len(qr1) == 2 assert qr1.time_range().start == parse_time('2012/08/09') assert qr1.time_range().end == parse_time('2012/08/11') # includes end. @pytest.mark.remote_data @pytest.mark.parametrize("time,instrument", [ (Time('2012/11/27', '2012/11/27'), Instrument('eve')), ]) def test_get(time, instrument): qr1 = LCClient.search(time, instrument) res = LCClient.fetch(qr1) assert len(res) == len(qr1) @pytest.mark.remote_data @pytest.mark.parametrize( 'query', [(a.Time('2012/10/4', '2012/10/6') & a.Instrument('eve') & a.Level(0))]) def test_fido(query): qr = Fido.search(query) client = qr.get_response(0).client assert isinstance(qr, UnifiedResponse)
def test_query(): qr1 = LCClient.search(Time('2012/8/9', '2012/8/10'), Instrument('eve')) assert isinstance(qr1, QueryResponse) assert len(qr1) == 2 assert qr1.time_range().start == parse_time('2012/08/09') assert qr1.time_range().end == parse_time('2012/08/11') # includes end.
assert mock_qr['Instrument'] == qr['Instrument'] assert mock_qr['url'] == qr['url'] assert mock_qr['Time'] == qr['Time'] # Assert if the timerange is same assert qr1.time_range() == TimeRange('2012/10/4', '2012/10/6') target_dir = tmpdir.mkdir("down") download_list = LCClient.fetch(qr1, path=target_dir) assert len(download_list) == len(qr1) assert download_list[0].split( '/')[-1] == 'observed-solar-cycle-indices.json' @pytest.mark.parametrize("timerange,url_start,url_end", [ (Time('1995/06/03', '1995/06/04'), 'https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json', 'https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json' ), (Time('2008/06/01', '2008/06/02'), 'https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json', 'https://services.swpc.noaa.gov/json/solar-cycle/observed-solar-cycle-indices.json' ) ]) def test_get_url_for_time_range(LCClient, timerange, url_start, url_end): resp = LCClient.search(timerange) urls = [i['url'] for i in resp] assert isinstance(urls, list) assert urls[0] == url_start assert urls[-1] == url_end