Esempio n. 1
0
def test_log_display(qtbot):
    dev = Device(name='test')
    log_tool = TyphosLogDisplay.from_device(dev)
    qtbot.addWidget(log_tool)
    dev.log.error(dev.name)
    assert log_tool.logdisplay.handler in get_handlers(dev)
    dev2 = Device(name='blah')
    log_tool.add_device(dev2)
    assert log_tool.logdisplay.handler in get_handlers(dev2)
Esempio n. 2
0
def test_widget_icon(lightrow):
    assert symbol_for_device(lightrow.device) == lightrow.device._icon
    # Smoke test a device without an icon
    device = Device(name='test')
    symbol_for_device(device)
    # Smoke test a device with a malformed icon
    device._icon = 'definetly not an icon'
    lr = lightpath.ui.LightRow(device)
    lr.update_state()
Esempio n. 3
0
def test_multi_derived_basic(multi_derived_ro: Device):
    assert multi_derived_ro.cpt.signals == [
        multi_derived_ro.a,
        multi_derived_ro.b,
        multi_derived_ro.c,
    ]

    multi_derived_ro.wait_for_connection()
    assert multi_derived_ro.connected
    assert multi_derived_ro.cpt.get() == (1 + 2 + 3)
Esempio n. 4
0
def test_log_display(qtbot):
    dev = Device(name='test')
    log_tool = TyphonLogDisplay.from_device(dev)
    qtbot.addWidget(log_tool)
    dev.log.error(dev.name)
    assert dev.name in log_tool.logdisplay.text.toPlainText()
    dev2 = Device(name='blah')
    log_tool.add_device(dev2)
    dev2.log.info(dev2.name)
    assert dev2.name in log_tool.logdisplay.text.toPlainText()
Esempio n. 5
0
def test_lazy_wait_context(lazy_state, cntx):
    class LocalExcepton(Exception):
        ...

    d = Device(name='d')
    d.lazy_wait_for_connection = lazy_state

    try:
        with cntx(d):
            assert d.lazy_wait_for_connection == (not lazy_state)
            raise LocalExcepton
    except LocalExcepton:
        ...

    assert d.lazy_wait_for_connection is lazy_state
def get_components_matching(
    obj: ophyd.Device,
    predicate: callable,
) -> typing.Generator[ophyd.ophydobj.OphydObject, None, None]:
    """
    Find signals of a specific type from a given ophyd Device.

    Parameters
    ----------
    obj : ophyd.Device
        The ophyd Device.

    predicate : callable
        Callable that should return True on a match.

    Yields
    ------
    obj : ophyd.ophydobj.OphydObject
    """
    for walk in obj.walk_signals(include_lazy=True):
        try:
            included = predicate(walk.item)
        except Exception:
            logger.exception('Failed to check predicate against %s', walk)
        else:
            if included:
                yield walk.item
Esempio n. 7
0
def test_device_state():
    d = Device('test', name='test')

    d.stage()
    old, new = d.configure({})
    assert old == new
    d.unstage()
Esempio n. 8
0
def test_device_hints():
    # Default hints is 'fields' with an empty list.
    assert {'fields': []} == Device('', name='dev').hints

    # Class-provided default works.
    class Dongle(Device):
        a = Component(Signal, kind=Kind.hinted)
        b = Component(Signal)

    assert {'fields': ['dev_a']} == Dongle(name='dev').hints
    assert {'fields': ['dev_a']} == Dongle(name='dev').hints
Esempio n. 9
0
def test_multi_derived_rw_basic(multi_derived_rw: Device):
    multi_derived_rw.wait_for_connection()
    assert multi_derived_rw.connected
    assert multi_derived_rw.cpt.get() == (1 + 2 + 3)

    multi_derived_rw.cpt.set(12).wait(timeout=1)
    assert multi_derived_rw.get() == (
        12,
        4.,
        4.,
        4.,
    )

    multi_derived_rw.cpt.set(24).wait(timeout=1)
    assert multi_derived_rw.get() == (
        24,
        8.,
        8.,
        8.,
    )
Esempio n. 10
0
def test_device_state():
    d = Device('test', name='test')

    d.stage()
    old, new = d.configure({})
    assert old == new
    d.unstage()
Esempio n. 11
0
def test_subscription_status():
    # Arbitrary device
    d = Device("Tst:Prefix", name='test')
    # Mock callback
    m = Mock()

    # Full fake callback signature
    def cb(*args, done=False, **kwargs):
        # Run mock callback
        m()
        # Return finished or not
        return done

    status = SubscriptionStatus(d, cb, event_type=d.SUB_ACQ_DONE)

    # Run callbacks but do not mark as complete
    d._run_subs(sub_type=d.SUB_ACQ_DONE, done=False)
    time.sleep(0.1)  # Wait for callbacks to run.
    assert m.called
    assert not status.done and not status.success

    # Run callbacks and mark as complete
    d._run_subs(sub_type=d.SUB_ACQ_DONE, done=True)
    time.sleep(0.1)  # Wait for callbacks to run.
    assert status.done and status.success
 def stop(self, success=False):
     self.user_setpoint.set(self.user_readback.get())
     Device.stop(self, success=success)
Esempio n. 13
0
def test_multi_derived_rw_wait_for_connection(multi_derived_rw: Device):
    multi_derived_rw.cpt.wait_for_connection()
    assert multi_derived_rw.cpt.connected
    multi_derived_rw.wait_for_connection()
    assert multi_derived_rw.connected
    assert multi_derived_rw.cpt.get() == (1 + 2 + 3)