refactor: keep style-specific config off the base class via **kwargs
The base AlarmStyle contract carried music_file, forcing SimpleStyle to accept a parameter it never uses. Move style-specific config to the subclass: the base __init__ takes only set_led (**kwargs swallows the rest); each style declares the keyword args it actually uses (BlinkStyle: music_file; SimpleStyle: none). The runner passes config as keyword args and each style keeps only what it needs, so the base contract never grows as styles are added — a future 'talk' style adds talk_file to its own signature, not to the base. README plugin contract updated.
This commit is contained in:
@@ -66,9 +66,8 @@ def test_run_alarm_uses_selected_style(mock_gpio, mock_pygame):
|
||||
wecker.run_alarm(style_name="whatever", test_mode=True)
|
||||
|
||||
get_style.assert_called_once_with("whatever")
|
||||
args = fake_style_cls.call_args.args
|
||||
assert args[0] is wecker.set_led
|
||||
assert isinstance(args[1], str) # resolved music file
|
||||
assert fake_style_cls.call_args.args[0] is wecker.set_led
|
||||
assert isinstance(fake_style_cls.call_args.kwargs["music_file"], str)
|
||||
fake.start.assert_called_once()
|
||||
fake.update.assert_called()
|
||||
|
||||
@@ -80,7 +79,7 @@ def test_run_alarm_default_music_file(mock_gpio, mock_pygame, monkeypatch):
|
||||
fake_style_cls = MagicMock(return_value=fake)
|
||||
with patch("wecker.get_style", return_value=fake_style_cls):
|
||||
wecker.run_alarm(test_mode=True)
|
||||
assert fake_style_cls.call_args.args[1] == wecker.DEFAULT_MUSIC_FILE
|
||||
assert fake_style_cls.call_args.kwargs["music_file"] == wecker.DEFAULT_MUSIC_FILE
|
||||
|
||||
|
||||
def test_run_alarm_env_music_file(mock_gpio, mock_pygame, monkeypatch):
|
||||
@@ -90,7 +89,7 @@ def test_run_alarm_env_music_file(mock_gpio, mock_pygame, monkeypatch):
|
||||
fake_style_cls = MagicMock(return_value=fake)
|
||||
with patch("wecker.get_style", return_value=fake_style_cls):
|
||||
wecker.run_alarm(test_mode=True)
|
||||
assert fake_style_cls.call_args.args[1] == "/env/track.mp3"
|
||||
assert fake_style_cls.call_args.kwargs["music_file"] == "/env/track.mp3"
|
||||
|
||||
|
||||
def test_run_alarm_music_file_arg_overrides_env(mock_gpio, mock_pygame, monkeypatch):
|
||||
@@ -100,7 +99,7 @@ def test_run_alarm_music_file_arg_overrides_env(mock_gpio, mock_pygame, monkeypa
|
||||
fake_style_cls = MagicMock(return_value=fake)
|
||||
with patch("wecker.get_style", return_value=fake_style_cls):
|
||||
wecker.run_alarm(music_file="/arg/track.mp3", test_mode=True)
|
||||
assert fake_style_cls.call_args.args[1] == "/arg/track.mp3"
|
||||
assert fake_style_cls.call_args.kwargs["music_file"] == "/arg/track.mp3"
|
||||
|
||||
|
||||
def test_run_alarm_blink_plays_music(mock_gpio, mock_pygame):
|
||||
|
||||
Reference in New Issue
Block a user