def test_snapshot_value(self): p_snapshot = Parameter('no_snapshot', set_cmd=None, get_cmd=None, snapshot_value=True) p_snapshot(42) snap = p_snapshot.snapshot() self.assertIn('value', snap) p_no_snapshot = Parameter('no_snapshot', set_cmd=None, get_cmd=None, snapshot_value=False) p_no_snapshot(42) snap = p_no_snapshot.snapshot() self.assertNotIn('value', snap)
def test_delegate_parameter_with_changed_source_snapshot_matches_value( value, scale, offset): delegate_param = DelegateParameter(name="delegate", source=None, scale=scale, offset=offset) source_parameter = Parameter(name="source", get_cmd=None, set_cmd=None, initial_value=value) _assert_none_source_is_correct(delegate_param) delegate_param.source = source_parameter calc_value = (value - offset) / scale assert delegate_param.cache.get(get_if_invalid=False) == calc_value assert delegate_param.source.cache.get(get_if_invalid=False) == value snapshot = delegate_param.snapshot() # disregard timestamp that might be slightly different snapshot["source_parameter"].pop("ts") source_snapshot = source_parameter.snapshot() source_snapshot.pop("ts") assert snapshot["source_parameter"] == source_snapshot assert snapshot["value"] == calc_value assert delegate_param.get() == calc_value # now remove the source again delegate_param.source = None _assert_none_source_is_correct(delegate_param) _assert_delegate_cache_none_source(delegate_param)
def test_snapshot_value(): p_snapshot = Parameter('no_snapshot', set_cmd=None, get_cmd=None, snapshot_value=True) p_snapshot(42) snap = p_snapshot.snapshot() assert 'value' in snap assert 'raw_value' in snap assert 'ts' in snap p_no_snapshot = Parameter('no_snapshot', set_cmd=None, get_cmd=None, snapshot_value=False) p_no_snapshot(42) snap = p_no_snapshot.snapshot() assert 'value' not in snap assert 'raw_value' not in snap assert 'ts' in snap
def test_snapshot(): p = Parameter('testparam', set_cmd=None, get_cmd=None, offset=1, scale=2, initial_value=1) d = DelegateParameter('test_delegate_parameter', p, offset=3, scale=5, initial_value=2) delegate_snapshot = d.snapshot() source_snapshot = delegate_snapshot.pop('source_parameter') assert source_snapshot == p.snapshot() assert delegate_snapshot['value'] == 2 assert source_snapshot['value'] == 13
def test_snapshot(): station = Station() empty_snapshot = station.snapshot() assert { 'instruments': {}, 'parameters': {}, 'components': {}, 'config': None, } == empty_snapshot instrument = DummyInstrument('instrument', gates=['one']) station.add_component(instrument) instrument_snapshot = instrument.snapshot() parameter = Parameter('parameter', label='Label', unit='m') station.add_component(parameter) parameter_snapshot = parameter.snapshot() excluded_parameter = Parameter('excluded_parameter', snapshot_exclude=True) station.add_component(excluded_parameter) component = DumyPar('component') component.metadata['smth'] = 'in the way she moves' station.add_component(component) component_snapshot = component.snapshot() snapshot = station.snapshot() assert isinstance(snapshot, dict) assert [ 'instruments', 'parameters', 'components', 'config', ] == list(snapshot.keys()) assert ['instrument'] == list(snapshot['instruments'].keys()) assert instrument_snapshot == snapshot['instruments']['instrument'] # the list should not contain the excluded parameter assert ['parameter'] == list(snapshot['parameters'].keys()) assert parameter_snapshot == snapshot['parameters']['parameter'] assert ['component'] == list(snapshot['components'].keys()) assert component_snapshot == snapshot['components']['component']
def test_snapshot(): station = Station() empty_snapshot = station.snapshot() assert {'instruments': {}, 'parameters': {}, 'components': {}, 'config': None, 'default_measurement': [] } == empty_snapshot instrument = DummyInstrument('instrument', gates=['one']) station.add_component(instrument) instrument_snapshot = instrument.snapshot() parameter = Parameter('parameter', label='Label', unit='m') station.add_component(parameter) parameter_snapshot = parameter.snapshot() component = DumyPar('component') component.metadata['smth'] = 'in the way she moves' station.add_component(component) component_snapshot = component.snapshot() snapshot = station.snapshot() assert isinstance(snapshot, dict) assert ['instruments', 'parameters', 'components', 'config', 'default_measurement' ] == list(snapshot.keys()) assert ['instrument'] == list(snapshot['instruments'].keys()) assert instrument_snapshot == snapshot['instruments']['instrument'] assert ['parameter'] == list(snapshot['parameters'].keys()) assert parameter_snapshot == snapshot['parameters']['parameter'] assert ['component'] == list(snapshot['components'].keys()) assert component_snapshot == snapshot['components']['component'] assert [] == snapshot['default_measurement']