Beispiel #1
0
    def test_ends_when_time_is_up(self, bus, mocker):
        timer = Timer(bus)
        changed = mocker.Mock()
        timer._bus.connect(Events.TIMER_UPDATE, changed, weak=False)

        finished = mocker.Mock()
        bus.connect(Events.TIMER_END, finished, weak=False)

        timer.start(1)
        run_loop_for(2)

        assert timer.is_running() is False
        changed.assert_called_once_with(Events.TIMER_UPDATE,
                                        payload=TimerPayload(time_left=0,
                                                             duration=1))
        finished.assert_called_once_with(Events.TIMER_END,
                                         payload=TimerPayload(time_left=0,
                                                              duration=1))
Beispiel #2
0
    def test_stops_when_timer_is_running(self, bus, mocker):
        timer = Timer(bus)
        subscriber = mocker.Mock()
        bus.connect(Events.TIMER_STOP, subscriber, weak=False)

        timer.start(60)
        result = timer.stop()

        assert result is True
        assert timer.is_running() is False
        subscriber.assert_called_once_with(Events.TIMER_STOP,
                                           payload=TimerPayload(time_left=0,
                                                                duration=0))
Beispiel #3
0
    def test_starts_when_timer_not_started_yet(self, bus, mocker, state):
        timer = Timer(bus)
        timer.state = state

        subscriber = mocker.Mock()
        bus.connect(Events.TIMER_START, subscriber, weak=False)

        result = timer.start(60)

        assert result is True
        subscriber.assert_called_once_with(Events.TIMER_START,
                                           payload=TimerPayload(time_left=60,
                                                                duration=60))
Beispiel #4
0
    graph.register_instance("tomate.bus", bus)
    scan_to_graph(["tomate.ui.widgets.countdown"], graph)
    return graph.get("tomate.ui.countdown")


def test_module(countdown, graph):
    instance = graph.get("tomate.ui.countdown")

    assert isinstance(instance, Countdown)
    assert instance is countdown


@pytest.mark.parametrize(
    "event, payload",
    [
        (Events.SESSION_READY,
         create_session_payload(duration=random.randint(1, 100))),
        (Events.SESSION_INTERRUPT,
         create_session_payload(duration=random.randint(1, 100))),
        (Events.SESSION_CHANGE,
         create_session_payload(duration=random.randint(1, 100))),
        (Events.TIMER_UPDATE,
         TimerPayload(time_left=random.randint(1, 100), duration=0)),
    ],
)
def test_updates_countdown_when_session_state_changes(event, payload, bus,
                                                      countdown):
    bus.send(event, payload=payload)

    assert payload.countdown in countdown.widget.get_text()
Beispiel #5
0
    def test_remaining_ratio(self, duration, time_left, ratio):
        payload = TimerPayload(duration=duration, time_left=time_left)

        assert payload.remaining_ratio == ratio
Beispiel #6
0
    def test_payload_markup(self, seconds, formatted):
        payload = TimerPayload(time_left=seconds, duration=0)

        assert payload.countdown == formatted
Beispiel #7
0
    def test_elapsed_percent(self, duration, time_left, percent):
        payload = TimerPayload(duration=duration, time_left=time_left)

        assert payload.elapsed_percent == percent
Beispiel #8
0
    def test_elapsed_ratio(self, duration, time_left, ratio):
        payload = TimerPayload(duration=duration, time_left=time_left)

        assert payload.elapsed_ratio == ratio