def __init__(self, records=None, errors=None): self.provideritem = list() if records is not None: self.provideritem = [ MockObject(record=MockObject(recorditem=[ri])) for ri in records ] if errors is not None: self.provideritem.extend([MockObject(error=err) for err in errors])
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 = va.Instrument(instrument) self.extent = MockObject( type=None if extent_type is None else extent_type.type)
def __new__(cls, start_time=None, end_time=None, size=0, source='SOHO', instrument='aia', extent=None, fileid="spam"): return MockObject(size=size, time=MockObject(start=start_time, end=end_time), source=source, instrument=instrument, provider="SunPy", extent=extent, fileid=fileid)
def test_MockObject_illegal_kwargs(mocked_mockobject): """ Any attempt to use a kwarg which has the same name as an attribute/method of the underlying object or datastore will raise a ValueError. """ with pytest.raises(ValueError): MockObject(records=[], values=1) with pytest.raises(ValueError): MockObject(items=('a', 'b', 'c')) with pytest.raises(ValueError): MockObject(__hash__=0x23424) # adding a new 'prohibited' attribute will be prevented with pytest.raises(ValueError): mocked_mockobject['keys'] = [3, 4]
def test_repr_MockObject(): """ Test ``MockObject.__repr__``. """ empty = MockObject() mo_p = re.compile(r"^(?P<_><)sunpy\.tests\.mocks\.MockObject \{\} " "at 0x[0-9A-Fa-f]+L?(?(_)>|)$") assert mo_p.match(repr(empty)) is not None
def test_QueryResponse_build_table_with_extent_type(mocker): """ When explicitly suppling an 'Extent' only the 'type' is stored in the built table. """ mocker.patch("sunpy.net.vso.vso.build_client", return_value=True) e_type = MockObject(x=1.0, y=2.5, width=37, length=129.2, type='CORONA') table = VSOQueryResponseTable.from_zeep_response(MockQRResponse( (MockQRRecord(extent=e_type), )), client=None) extent = table['Extent Type'].data assert len(extent) == 1 assert extent[0] == e_type.type
def mocked_mockobject(): return MockObject(records=12)
def test_MockObject_len(): """ Testing ``MockObject.__len__``. """ assert len(MockObject(responses=['a', 'b', 'c', 'd'], requests=(1, 2, 3))) == 2
def mock_response(): # defining unsorted queryresult to mock test `iter_sort_response()`. # Incorporated cases with no None start time and without time attribute too. recs = [ MockObject(record=MockObject(recorditem=[ MockObject(time=MockObject(start=4), fileid='t4'), MockObject(time=MockObject(start=1), fileid='t1'), MockObject(time=MockObject(start=2), fileid='t2') ])) ] rec = MockObject(record=MockObject(recorditem=[ MockObject(time=MockObject(start=None), fileid='f1'), MockObject(fileid='f2'), MockObject(time=MockObject(start=3), fileid='t3') ])) recs.append(rec) return MockQRResponse(records=recs, errors=['FAILED'])