Beispiel #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)
Beispiel #2
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()
Beispiel #3
0
def test_device_state():
    d = Device('test', name='test')

    d.stage()
    old, new = d.configure({})
    assert old == new
    d.unstage()
Beispiel #4
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
Beispiel #5
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()
Beispiel #6
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
Beispiel #7
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