def __init__(self, start_time=None, end_time=None, size=0, source='SOHO', instrument='aia', extent_type=None): self.size = size self.time = MockObject(start=start_time, end=end_time) self.source = va.Source(source) self.instrument = core_attrs.Instrument(instrument) self.extent = MockObject( type=None if extent_type is None else extent_type.type)
def test_vso_hmi(client, tmpdir): """ This is a regression test for https://github.com/sunpy/sunpy/issues/2284 """ res = client.search( core_attrs.Time('2020-01-02 23:52:00', '2020-01-02 23:54:00'), core_attrs.Instrument('HMI') | core_attrs.Instrument('AIA'), response_format="table") dr = client.make_getdatarequest(res) # Extract the DRIs from the request dris = dr.request.datacontainer.datarequestitem # 3 HMI series and one AIA assert len(dris) == 4 # For each DataRequestItem assert that there is only one series in it. for dri in dris: fileids = dri.fileiditem.fileid series = list(map(lambda x: x.split(':')[0], fileids)) assert all([s == series[0] for s in series])
def test_simpleattr_and_duplicate(): attr = core_attrs.Instrument('foo') pytest.raises(TypeError, lambda: attr & core_attrs.Instrument('bar')) attr |= a.Source('foo') pytest.raises(TypeError, lambda: attr & core_attrs.Instrument('bar')) otherattr = core_attrs.Instrument('foo') | a.Source('foo') pytest.raises(TypeError, lambda: attr & otherattr) pytest.raises(TypeError, lambda: (attr | otherattr) & core_attrs.Instrument('bar')) tst = core_attrs.Instrument('foo') & a.Source('foo') pytest.raises(TypeError, lambda: tst & tst)
def test_path(client, tmpdir): """ Test that '{file}' is automatically appended to the end of a custom path if it is not specified. """ qr = client.search( core_attrs.Time('2011-06-07 06:33', '2011-06-07 06:33:08'), core_attrs.Instrument('aia'), core_attrs.Wavelength(171 * u.AA)) tmp_dir = tmpdir / "{file}" files = client.fetch(qr, path=tmp_dir) assert len(files) == 1 # The construction of a VSO filename is bonkers complex, so there is no # practical way to determine what it should be in this test, so we just # put it here. assert "aia_lev1_171a_2011_06_07t06_33_02_77z_image_lev1.fits" in files[0]
def test_no_download(client): """ Test for https://github.com/sunpy/sunpy/issues/3292 """ class MockDownloader: download_called = False def __init__(self): pass def download(self, *args, **kwargs): self.download_called = True # this should fail stereo = (core_attrs.Detector('STEREO_B') & core_attrs.Instrument('EUVI') & core_attrs.Time('1900-01-01', '1900-01-01T00:10:00')) qr = client.search(stereo, response_format="table") downloader = MockDownloader() res = client.fetch(qr, wait=False, downloader=downloader) assert downloader.download_called is False assert res == Results()
def vso_instrument(self): if self['obs_instrument'] == 'HEK': raise ValueError("No instrument contained.") return core_attrs.Instrument(self['obs_instrument'])
def eit(): return core_attrs.Instrument('eit')
def test_non_str_instrument(): # Sanity Check assert isinstance(core_attrs.Instrument("lyra"), core_attrs.Instrument) with pytest.raises(ValueError): core_attrs.Instrument(1234)
def test_attror_and(): attr = core_attrs.Instrument('foo') | core_attrs.Instrument('bar') one = attr & a.Source('bar') other = ((core_attrs.Instrument('foo') & a.Source('bar')) | (core_attrs.Instrument('bar') & a.Source('bar'))) assert one == other
def test_simpleattr_or_eq(): attr = core_attrs.Instrument('eit') assert attr | attr == attr assert attr | core_attrs.Instrument('eit') == attr
def eit(request): return core_attrs.Instrument('eit')
def test_vso_error(client): with pytest.warns(SunpyUserWarning, match="VSO-C500 :soap:Server.Transport : 404 Not Found"): client.search(core_attrs.Time('2019/12/30', '2019/12/31'), core_attrs.Instrument('ovsa'))
def __init__(self, start_time=None, end_time=None, size=0, source='SOHO', instrument='aia', extent_type=None): self.data = {"size": size, "time": dict(start=start_time, end=end_time), "source": a.Source(source), "instrument": core_attrs.Instrument(instrument), "extent": dict(type=None if extent_type is None else extent_type.type)}