2026-08-02 21:50:00 +02:00
|
|
|
from unittest.mock import MagicMock, patch
|
2026-08-02 16:29:40 +02:00
|
|
|
|
2026-07-31 16:19:14 +02:00
|
|
|
from styles.simple import SimpleStyle
|
|
|
|
|
|
|
|
|
|
|
2026-08-02 16:29:40 +02:00
|
|
|
def _make_style():
|
2026-08-02 21:50:00 +02:00
|
|
|
calls = []
|
|
|
|
|
return SimpleStyle(lambda on: calls.append(on)), calls
|
2026-08-02 16:29:40 +02:00
|
|
|
|
|
|
|
|
|
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-08-02 21:50:00 +02:00
|
|
|
with patch("styles.simple.pygame", MagicMock()):
|
|
|
|
|
style.start()
|
|
|
|
|
assert style.update(0.0, False) is True
|
2026-07-31 16:19:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_stops_on_first_press():
|
2026-08-02 16:29:40 +02:00
|
|
|
style, _ = _make_style()
|
2026-08-02 21:50:00 +02:00
|
|
|
with patch("styles.simple.pygame", MagicMock()):
|
|
|
|
|
style.start()
|
|
|
|
|
assert style.update(0.0, True) is False # press -> stop
|
2026-07-31 16:19:14 +02:00
|
|
|
|
|
|
|
|
|
2026-08-02 16:29:40 +02:00
|
|
|
def test_simple_led_solid_on():
|
2026-08-02 21:50:00 +02:00
|
|
|
style, calls = _make_style()
|
|
|
|
|
with patch("styles.simple.pygame", MagicMock()):
|
|
|
|
|
style.start()
|
|
|
|
|
style.update(0.0, False)
|
|
|
|
|
assert calls == [True, True] # start sets LED on; update keeps it on
|
2026-08-02 16:29:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_beeps_on_interval():
|
2026-08-02 21:50:00 +02:00
|
|
|
style, _ = _make_style()
|
|
|
|
|
with patch("styles.simple.pygame", MagicMock()) as pg:
|
|
|
|
|
style.start()
|
|
|
|
|
style.update(100.0, False) # first tick -> beep
|
|
|
|
|
assert pg.mixer.Sound.return_value.play.called
|
|
|
|
|
pg.mixer.Sound.return_value.play.reset_mock()
|
|
|
|
|
|
|
|
|
|
style.update(100.4, False) # before interval -> no beep
|
|
|
|
|
assert not pg.mixer.Sound.return_value.play.called
|
|
|
|
|
|
|
|
|
|
style.update(100.5, False) # at interval -> beep
|
|
|
|
|
assert pg.mixer.Sound.return_value.play.called
|
2026-08-02 16:29:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_never_plays_music():
|
2026-08-02 21:50:00 +02:00
|
|
|
style, _ = _make_style()
|
|
|
|
|
with patch("styles.simple.pygame", MagicMock()) as pg:
|
|
|
|
|
style.start()
|
|
|
|
|
style.update(0.0, False)
|
|
|
|
|
style.update(0.0, True) # press -> stop
|
|
|
|
|
assert not pg.mixer.music.play.called
|
|
|
|
|
assert not pg.mixer.music.load.called
|