def mockgetdevicemeta(rack, board, device): """Mock method to monkeypatch the get_device_meta method.""" # the plugin name 'foo' here corresponds to the plugin generated by # the `make_plugin` fixture return 'foo', api.MetainfoResponse( timestamp='october', uid='12345', type='thermistor', model='test', manufacturer='vapor io', protocol='foo', # this will be the name of the plugin we look up info='bar', location=api.MetaLocation( rack='rack-1', board='vec' ), output=[ api.MetaOutput( type='temperature', data_type='float', precision=3, unit=api.MetaOutputUnit( name='celsius', symbol='C' ), range=api.MetaOutputRange( min=0, max=100 ) ) ] )
def test_metaoutput_to_dict(): """Convert a MetaOutput object to dictionary.""" meta = api.MetaOutput( type='temperature', data_type='float', precision=3, unit=api.MetaOutputUnit( name='celsius', symbol='C' ), range=api.MetaOutputRange( min=0, max=100 ) ) actual = util.metaoutput_to_dict(meta) assert actual == { 'type': 'temperature', 'data_type': 'float', 'precision': 3, 'unit': { 'name': 'celsius', 'symbol': 'C', }, 'range': { 'min': 0, 'max': 100 } }
def make_metainfo_response(): """Convenience method to create MetainfoResponse test data.""" return api.MetainfoResponse(timestamp='october', uid='12345', type='thermistor', model='test', manufacturer='vapor io', protocol='foo', info='bar', location=api.MetaLocation(rack='rack-1', board='vec'), output=[ api.MetaOutput( type='temperature', data_type='float', precision=3, unit=api.MetaOutputUnit(name='celsius', symbol='C'), range=api.MetaOutputRange(min=0, max=100)) ])
def make_metainfo_response(rack, board, device): """Helper method to make a new MetainfoResponse object.""" return api.MetainfoResponse(timestamp='october', uid=device, type='thermistor', model='test', manufacturer='vapor io', protocol='foo', info='bar', location=api.MetaLocation(rack=rack, board=board), output=[ api.MetaOutput( type='temperature', data_type='float', precision=3, unit=api.MetaOutputUnit(name='celsius', symbol='C'), range=api.MetaOutputRange(min=0, max=100)) ])
def mock_metainfo(req, timeout): """Mock the internal metainfo call.""" return [ synse_api.MetainfoResponse( timestamp='october', uid='12345', type='thermistor', model='test', manufacturer='vapor io', protocol='foo', info='bar', location=synse_api.MetaLocation(rack='rack-1', board='vec'), output=[ synse_api.MetaOutput(type='temperature', data_type='float', precision=3, unit=synse_api.MetaOutputUnit( name='celsius', symbol='C'), range=synse_api.MetaOutputRange(min=0, max=100)) ]) ]
def test_metainfo_to_dict(): """Convert a MetainfoResponse object to dictionary.""" meta = api.MetainfoResponse( timestamp='october', uid='12345', type='thermistor', model='test', manufacturer='vapor io', protocol='foo', info='bar', location=api.MetaLocation( rack='rack-1', board='vec' ), output=[ api.MetaOutput( type='temperature', data_type='float', precision=3, unit=api.MetaOutputUnit( name='celsius', symbol='C' ), range=api.MetaOutputRange( min=0, max=100 ) ) ] ) actual = util.metainfo_to_dict(meta) assert actual == { 'timestamp': 'october', 'uid': '12345', 'type': 'thermistor', 'model': 'test', 'manufacturer': 'vapor io', 'protocol': 'foo', 'info': 'bar', 'comment': '', 'location': { 'rack': 'rack-1', 'board': 'vec' }, 'output': [ { 'type': 'temperature', 'data_type': 'float', 'precision': 3, 'unit': { 'name': 'celsius', 'symbol': 'C', }, 'range': { 'min': 0, 'max': 100 } } ] }