Exemplo n.º 1
0
    def __init__(self,
                 name,
                 acquisition_parameter=None,
                 discriminant=None,
                 silent=True,
                 **kwargs):
        SettingsClass.__init__(self)
        MultiParameter.__init__(self, name, snapshot_value=False, **kwargs)

        if self.layout is None:
            try:
                MeasurementParameter.layout = Instrument.find_instrument(
                    'layout')
            except KeyError:
                logger.warning(f'No layout found for {self}')

        self.discriminant = discriminant

        self.silent = silent
        self.acquisition_parameter = acquisition_parameter

        self._meta_attrs.extend(['acquisition_parameter_name'])
Exemplo n.º 2
0
    def test_has_set_get(self):
        name = 'mixed_dimensions'
        names = ['0D', '1D', '2D']
        shapes = ((), (3, ), (2, 2))
        with self.assertRaises(AttributeError):
            MultiParameter(name, names, shapes)

        p = SimpleMultiParam([0, [1, 2, 3], [[4, 5], [6, 7]]], name, names,
                             shapes)

        self.assertTrue(hasattr(p, 'get'))
        self.assertFalse(hasattr(p, 'set'))
        # We allow creation of Multiparameters with set to support
        # instruments that already make use of them.
        with self.assertWarns(UserWarning):
            SettableMulti([0, [1, 2, 3], [[4, 5], [6, 7]]], name, names,
                          shapes)
Exemplo n.º 3
0
def test_has_set_get():
    name = 'mixed_dimensions'
    names = ['0D', '1D', '2D']
    shapes = ((), (3,), (2, 2))
    with pytest.raises(AttributeError):
        MultiParameter(name, names, shapes)

    original_value = [0, [1, 2, 3], [[4, 5], [6, 7]]]
    p = SimpleMultiParam(original_value, name, names, shapes)

    assert hasattr(p, 'get')
    assert p.gettable
    assert not hasattr(p, 'set')
    assert not p.settable
    # Ensure that ``cache.set`` works
    new_cache = [10, [10, 20, 30], [[40, 50], [60, 70]]]
    p.cache.set(new_cache)
    assert p.get_latest() == new_cache
    # However, due to the implementation of this ``SimpleMultiParam``
    # test parameter it's ``get`` call will return the originally passed
    # list
    assert p.get() == original_value
    assert p.get_latest() == original_value

    # We allow creation of Multiparameters with set to support
    # instruments that already make use of them.
    p = SettableMulti([0, [1, 2, 3], [[4, 5], [6, 7]]], name, names, shapes)
    assert hasattr(p, 'get')
    assert p.gettable
    assert hasattr(p, 'set')
    assert p.settable
    value_to_set = [2, [1, 5, 2], [[8, 2], [4, 9]]]
    p.set(value_to_set)
    assert p.get() == value_to_set
    # Also, ``cache.set`` works as expected
    p.cache.set(new_cache)
    assert p.get_latest() == new_cache
    assert p.get() == value_to_set