2026-08-02 16:29:40 +02:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
2026-07-31 16:19:14 +02:00
|
|
|
from styles.simple import SimpleStyle
|
|
|
|
|
|
|
|
|
|
|
2026-08-02 16:29:40 +02:00
|
|
|
def _make_style():
|
|
|
|
|
sound = MagicMock()
|
|
|
|
|
style = SimpleStyle(lambda on: None, sound)
|
|
|
|
|
return style, sound
|
|
|
|
|
|
|
|
|
|
|
2026-07-31 16:19:14 +02:00
|
|
|
def test_simple_keeps_ringing_when_not_pressed():
|
2026-08-02 16:29:40 +02:00
|
|
|
style, _ = _make_style()
|
2026-07-31 16:19:14 +02:00
|
|
|
assert style.update(0.0, False) is True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_stops_on_first_press():
|
2026-08-02 16:29:40 +02:00
|
|
|
style, _ = _make_style()
|
2026-07-31 16:19:14 +02:00
|
|
|
assert style.update(0.0, True) is False # press -> stop
|
|
|
|
|
|
|
|
|
|
|
2026-08-02 16:29:40 +02:00
|
|
|
def test_simple_led_solid_on():
|
2026-07-31 16:19:14 +02:00
|
|
|
calls = []
|
2026-08-02 16:29:40 +02:00
|
|
|
sound = MagicMock()
|
|
|
|
|
style = SimpleStyle(lambda on: calls.append(on), sound)
|
|
|
|
|
style.start()
|
2026-07-31 16:19:14 +02:00
|
|
|
assert calls == [True]
|
2026-08-02 16:29:40 +02:00
|
|
|
style.update(0.0, False)
|
|
|
|
|
assert calls[-1] is True # stays on every tick
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_beeps_on_interval():
|
|
|
|
|
style, sound = _make_style()
|
|
|
|
|
style.start()
|
|
|
|
|
style.update(100.0, False) # first tick -> beep
|
|
|
|
|
assert sound.play_beep.called
|
|
|
|
|
sound.play_beep.reset_mock()
|
|
|
|
|
style.update(100.4, False) # before interval -> no beep
|
|
|
|
|
assert not sound.play_beep.called
|
|
|
|
|
style.update(100.5, False) # at interval -> beep
|
|
|
|
|
assert sound.play_beep.called
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_never_plays_music():
|
|
|
|
|
style, sound = _make_style()
|
|
|
|
|
style.start()
|
|
|
|
|
style.update(0.0, False)
|
|
|
|
|
style.update(0.0, True) # press -> stop
|
|
|
|
|
assert not sound.play_music.called
|