예제 #1
0
def test_can_handle_query(time):
    ans1 = goes.XRSClient._can_handle_query(time, Instrument('XRS'))
    assert ans1 is True
    ans2 = goes.XRSClient._can_handle_query(time)
    assert ans2 is False
    ans3 = goes.XRSClient._can_handle_query(time, Instrument('eve'))
    assert ans3 is False
예제 #2
0
파일: test_eve.py 프로젝트: zimmaz/sunpy
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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')
예제 #6
0
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
예제 #7
0
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'
예제 #8
0
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()
예제 #9
0
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'
예제 #10
0
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
예제 #11
0
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)
예제 #12
0
파일: test_noaa.py 프로젝트: wtbarnes/sunpy
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"))
예제 #13
0
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"))
예제 #14
0
def test_no_satellite(LCClient):
    with pytest.raises(ValueError):
        LCClient.search(Time("1950/01/01", "1950/02/02"), Instrument('XRS'))
예제 #15
0

@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(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')),
    (Time('2013/2/4', '2013/2/6'), Instrument('lyra')),
])
def test_get(time, instrument):
    qr1 = LCClient.search(time, instrument)
    download_list = LCClient.fetch(qr1)
    assert len(download_list) == len(qr1)


@pytest.mark.remote_data
@pytest.mark.parametrize(
    "time, instrument",
    [(a.Time('2012/10/4', '2012/10/6'), a.Instrument('lyra')),
     (a.Time('2013/10/5', '2013/10/7'), a.Instrument('lyra'))])
def test_fido(time, instrument):
    qr = Fido.search(time, instrument)
예제 #16
0
def test_fido(time, instrument):
    qr = Fido.search(time, Instrument('XRS'))
    assert isinstance(qr, UnifiedResponse)
    response = Fido.fetch(qr)
    assert len(response) == qr._numfile
예제 #17
0
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)
예제 #18
0
def test_query_error(LCClient):
    times = [a.Time("1983-05-01", "1983-05-02")]
    for time in times:
        with pytest.raises(ValueError):
            LCClient.search(time, Instrument('XRS'))
예제 #19
0
    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
def test_query_error(LCClient):
    times = [a.Time("1983-05-01", "1983-05-02")]
    for time in times:
        with pytest.raises(ValueError):
            LCClient.search(time, Instrument('XRS'))


@pytest.mark.remote_data
@pytest.mark.parametrize("time, instrument", [
    (Time('1983/06/17', '1983/06/18'), Instrument('XRS')),
    (Time('2012/10/4', '2012/10/6'), Instrument('XRS')),
])
def test_get(LCClient, time, instrument):
    qr1 = LCClient.search(time, instrument)
    download_list = LCClient.fetch(qr1)
    assert len(download_list) == len(qr1)


@pytest.mark.remote_data
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)

예제 #20
0
    "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):
예제 #21
0
def test_query(LCClient, time):
    qr1 = LCClient.search(time, Instrument('lyra'))
    assert isinstance(qr1, QueryResponse)
    assert qr1.time_range().start == time.start
    almost_day = TimeDelta(1 * u.day - 1 * u.millisecond)
    assert qr1.time_range().end == time.end + almost_day
예제 #22
0

@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)
    download_list = LCClient.fetch(qr1)
    assert len(download_list) == len(qr1)


@pytest.mark.remote_data
@pytest.mark.parametrize(
    "time, instrument",
    [(a.Time('2012/10/4', '2012/10/6'), a.Instrument.lyra)])
def test_fido(time, instrument):
    qr = Fido.search(time, instrument)
    assert isinstance(qr, UnifiedResponse)
    response = Fido.fetch(qr)
예제 #23
0
        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)
예제 #24
0
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
예제 #25
0
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.
예제 #26
0
def test_query(LCClient, time):
    qr1 = LCClient.search(time, Instrument('lyra'))
    assert isinstance(qr1, QueryResponse)
    assert qr1[0]['Start Time'] == time.start
    almost_day = TimeDelta(1 * u.day - 1 * u.millisecond)
    assert qr1[-1]['End Time'] == time.end + almost_day