from unittest.mock import MagicMock from styles.simple import SimpleStyle def _make_style(): sound = MagicMock() style = SimpleStyle(lambda on: None, sound) return style, sound def test_simple_keeps_ringing_when_not_pressed(): style, _ = _make_style() assert style.update(0.0, False) is True def test_simple_stops_on_first_press(): style, _ = _make_style() assert style.update(0.0, True) is False # press -> stop def test_simple_led_solid_on(): calls = [] sound = MagicMock() style = SimpleStyle(lambda on: calls.append(on), sound) style.start() assert calls == [True] 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