def test_UI_GIVEN_invalid_broker_WHEN_status_broker_timer_callback_is_called_THEN_nothing_happens(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.status_consumer = None
    window.status_broker_edit.setText("invalid")

    window.status_broker_timer_changed(DummyInterface)
    assert window.status_consumer is None
def test_UI_GIVEN_command_producer_WHEN_checking_connection_status_THEN_command_led_is_turned_on(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.command_producer = Mock()
    window.status_consumer = None
    window.command_producer.connected = True

    window._check_connection_status()
    assert window.command_broker_led.is_on()
def test_UI_GIVEN_no_status_consumer_and_no_command_producer_WHEN_checking_status_connection_THEN_both_leds_are_turned_off(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.status_consumer = None
    window.command_producer = None

    window._check_connection_status()

    assert window.status_broker_led.is_off()
    assert window.command_broker_led.is_off()
def test_UI_GIVEN_valid_broker_WHEN_status_broker_timer_callback_is_called_THEN_consumer_is_created(
        qtbot, instrument):
    window = FileWriterCtrl(instrument)
    qtbot.addWidget(window)
    window.command_broker_change_timer.stop()
    window.status_broker_change_timer.stop()

    window.status_consumer = 1  # anything that's not None
    window.status_broker_edit.setText("valid:9092/topic1")

    window.status_broker_timer_changed(DummyInterface)
    assert isinstance(window.status_consumer, DummyInterface)