Beispiel #1
0
def test_soft_derived():
    timestamp = 1.0
    value = 'q'
    original = Signal(name='original', timestamp=timestamp, value=value)

    cb_values = []

    def callback(value=None, **kwargs):
        nonlocal cb_values
        cb_values.append(value)

    derived = DerivedSignal(derived_from=original, name='derived')
    derived.subscribe(callback, event_type=derived.SUB_VALUE)

    assert derived.timestamp == timestamp
    assert derived.get() == value
    assert derived.timestamp == timestamp
    assert derived.describe()[derived.name]['derived_from'] == original.name

    new_value = 'r'
    derived.put(new_value)
    assert original.get() == new_value
    assert derived.get() == new_value
    assert derived.timestamp == original.timestamp
    assert derived.limits == original.limits

    copied = copy.copy(derived)
    assert copied.derived_from.value == original.value
    assert copied.derived_from.timestamp == original.timestamp
    assert copied.derived_from.name == original.name

    derived.put('s')
    assert cb_values == ['r', 's']
Beispiel #2
0
def test_epics_signal_derived():
    signal = EpicsSignalRO('fakepv', name='original')

    derived = DerivedSignal(derived_from=signal, name='derived')
    derived.wait_for_connection()

    derived.connected
Beispiel #3
0
def test_epics_signal_derived():
    signal = EpicsSignalRO('fakepv', name='original')

    derived = DerivedSignal(derived_from=signal, name='derived')
    derived.wait_for_connection()

    derived.connected
Beispiel #4
0
def test_epics_signal_derived(ro_signal):
    assert ro_signal.connected
    assert ro_signal.read_access
    assert not ro_signal.write_access

    derived = DerivedSignal(derived_from=ro_signal, name='derived')
    derived.wait_for_connection()

    assert derived.connected
    assert derived.read_access
    assert not derived.write_access

    assert derived.timestamp == ro_signal.timestamp
    assert derived.get() == ro_signal.get()
Beispiel #5
0
def test_epics_signal_derived(ro_signal):
    assert ro_signal.connected
    assert ro_signal.read_access
    assert not ro_signal.write_access

    derived = DerivedSignal(derived_from=ro_signal, name='derived')
    derived.wait_for_connection()

    assert derived.connected
    assert derived.read_access
    assert not derived.write_access

    assert derived.timestamp == ro_signal.timestamp
    assert derived.get() == ro_signal.value
Beispiel #6
0
def test_epics_signal_derived(cleanup, signal_test_ioc):
    signal = EpicsSignalRO(
        read_pv=signal_test_ioc.pvs['read_only'],
        name='original',
    )
    cleanup.add(signal)

    signal.wait_for_connection()
    assert signal.connected
    assert signal.read_access
    assert not signal.write_access

    derived = DerivedSignal(derived_from=signal, name='derived')
    derived.wait_for_connection()

    assert derived.connected
    assert derived.read_access
    assert not derived.write_access

    assert derived.timestamp == signal.timestamp
    assert derived.get() == signal.value
Beispiel #7
0
    def test_soft_derived(self):
        timestamp = 1.0
        value = 'q'
        original = Signal(name='original', timestamp=timestamp, value=value)

        derived = DerivedSignal(derived_from=original, name='derived')
        self.assertEqual(derived.timestamp, timestamp)
        self.assertEqual(derived.get(), value)
        self.assertEqual(derived.timestamp, timestamp)
        self.assertEqual(derived.describe()[derived.name]['derived_from'],
                         original.name)

        new_value = 'r'
        derived.put(new_value)
        self.assertEqual(original.get(), new_value)
        self.assertEqual(derived.get(), new_value)
        self.assertEqual(derived.timestamp, original.timestamp)
        self.assertEqual(derived.limits, original.limits)

        copied = copy.copy(derived)
        self.assertEqual(copied.derived_from.value, original.value)
        self.assertEqual(copied.derived_from.timestamp, original.timestamp)
        self.assertEqual(copied.derived_from.name, original.name)
Beispiel #8
0
    def test_soft_derived(self):
        timestamp = 1.0
        value = 'q'
        original = Signal(name='original', timestamp=timestamp, value=value)

        derived = DerivedSignal(derived_from=original, name='derived')
        self.assertEqual(derived.timestamp, timestamp)
        self.assertEqual(derived.get(), value)
        self.assertEqual(derived.timestamp, timestamp)
        self.assertEqual(derived.describe()[derived.name]['derived_from'],
                         original.name)

        new_value = 'r'
        derived.put(new_value)
        self.assertEqual(original.get(), new_value)
        self.assertEqual(derived.get(), new_value)
        self.assertEqual(derived.timestamp, original.timestamp)
        self.assertEqual(derived.limits, original.limits)

        copied = copy.copy(derived)
        self.assertEqual(copied.derived_from.value, original.value)
        self.assertEqual(copied.derived_from.timestamp, original.timestamp)
        self.assertEqual(copied.derived_from.name, original.name)
Beispiel #9
0
def test_soft_derived():
    timestamp = 1.0
    value = 'q'
    original = Signal(name='original', timestamp=timestamp, value=value)

    cb_values = []

    def callback(value=None, **kwargs):
        nonlocal cb_values
        cb_values.append(value)

    derived = DerivedSignal(derived_from=original, name='derived')
    derived.subscribe(callback, event_type=derived.SUB_VALUE)

    assert derived.timestamp == timestamp
    assert derived.get() == value
    assert derived.timestamp == timestamp
    assert derived.describe()[derived.name]['derived_from'] == original.name

    new_value = 'r'
    derived.put(new_value)
    assert original.get() == new_value
    assert derived.get() == new_value
    assert derived.timestamp == original.timestamp
    assert derived.limits == original.limits

    copied = copy.copy(derived)
    assert copied.derived_from.value == original.value
    assert copied.derived_from.timestamp == original.timestamp
    assert copied.derived_from.name == original.name

    derived.put('s')
    assert cb_values == ['r', 's']
Beispiel #10
0
def test_soft_derived():
    timestamp = 1.0
    value = 'q'
    original = Signal(name='original', timestamp=timestamp, value=value)

    cb_values = []

    def callback(value=None, **kwargs):
        cb_values.append(value)

    derived = DerivedSignal(derived_from=original, name='derived')
    derived.subscribe(callback, event_type=derived.SUB_VALUE)

    assert derived.timestamp == timestamp
    assert derived.get() == value
    assert derived.timestamp == timestamp
    assert derived.describe()[derived.name]['derived_from'] == original.name
    assert derived.write_access == original.write_access
    assert derived.read_access == original.read_access

    new_value = 'r'
    derived.put(new_value)
    assert original.get() == new_value
    assert derived.get() == new_value
    assert derived.timestamp == original.timestamp
    assert derived.limits == original.limits

    copied = copy.copy(derived)
    assert copied.derived_from.value == original.value
    assert copied.derived_from.timestamp == original.timestamp
    assert copied.derived_from.name == original.name

    derived.put('s')
    assert cb_values == ['r', 's']

    called = []

    event = threading.Event()

    def meta_callback(*, connected, read_access, write_access, **kw):
        called.append(('meta', connected, read_access, write_access))
        event.set()

    derived.subscribe(meta_callback, event_type=derived.SUB_META, run=False)

    original._metadata['write_access'] = False
    original._run_subs(sub_type='meta', **original._metadata)

    event.wait(1)

    assert called == [('meta', True, True, False)]
Beispiel #11
0
def test_soft_derived():
    timestamp = 1.0
    value = 'q'
    original = Signal(name='original', timestamp=timestamp, value=value)

    cb_values = []

    def callback(value=None, **kwargs):
        cb_values.append(value)

    derived = DerivedSignal(derived_from=original, name='derived')
    derived.subscribe(callback, event_type=derived.SUB_VALUE)

    assert derived.timestamp == timestamp
    assert derived.get() == value
    assert derived.timestamp == timestamp
    assert derived.describe()[derived.name]['derived_from'] == original.name
    assert derived.write_access == original.write_access
    assert derived.read_access == original.read_access

    new_value = 'r'
    derived.put(new_value)
    assert original.get() == new_value
    assert derived.get() == new_value
    assert derived.timestamp == original.timestamp
    assert derived.limits == original.limits

    copied = copy.copy(derived)
    assert copied.derived_from.value == original.value
    assert copied.derived_from.timestamp == original.timestamp
    assert copied.derived_from.name == original.name

    derived.put('s')
    assert cb_values == ['r', 's']

    called = []

    event = threading.Event()

    def meta_callback(*, connected, read_access, write_access, **kw):
        called.append(('meta', connected, read_access, write_access))
        event.set()

    derived.subscribe(meta_callback, event_type=derived.SUB_META, run=False)

    original._metadata['write_access'] = False
    original._run_subs(sub_type='meta', **original._metadata)

    event.wait(1)

    assert called == [('meta', True, True, False)]