118 lines
4.6 KiB
Python
118 lines
4.6 KiB
Python
"""
|
|
Tests for engine.effects.controller module.
|
|
"""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from engine.effects.controller import (
|
|
handle_effects_command,
|
|
set_effect_chain_ref,
|
|
)
|
|
|
|
|
|
class TestHandleEffectsCommand:
|
|
"""Tests for handle_effects_command function."""
|
|
|
|
def test_list_effects(self):
|
|
"""list command returns formatted effects list."""
|
|
with patch("engine.effects.controller.get_registry") as mock_registry:
|
|
mock_plugin = MagicMock()
|
|
mock_plugin.config.enabled = True
|
|
mock_plugin.config.intensity = 0.5
|
|
mock_registry.return_value.list_all.return_value = {"noise": mock_plugin}
|
|
|
|
with patch("engine.effects.controller._get_effect_chain") as mock_chain:
|
|
mock_chain.return_value.get_order.return_value = ["noise"]
|
|
|
|
result = handle_effects_command("/effects list")
|
|
|
|
assert "noise: ON" in result
|
|
assert "intensity=0.5" in result
|
|
|
|
def test_enable_effect(self):
|
|
"""enable command calls registry.enable."""
|
|
with patch("engine.effects.controller.get_registry") as mock_registry:
|
|
mock_plugin = MagicMock()
|
|
mock_registry.return_value.get.return_value = mock_plugin
|
|
mock_registry.return_value.list_all.return_value = {"noise": mock_plugin}
|
|
|
|
result = handle_effects_command("/effects noise on")
|
|
|
|
assert "Enabled: noise" in result
|
|
mock_registry.return_value.enable.assert_called_once_with("noise")
|
|
|
|
def test_disable_effect(self):
|
|
"""disable command calls registry.disable."""
|
|
with patch("engine.effects.controller.get_registry") as mock_registry:
|
|
mock_plugin = MagicMock()
|
|
mock_registry.return_value.get.return_value = mock_plugin
|
|
mock_registry.return_value.list_all.return_value = {"noise": mock_plugin}
|
|
|
|
result = handle_effects_command("/effects noise off")
|
|
|
|
assert "Disabled: noise" in result
|
|
mock_registry.return_value.disable.assert_called_once_with("noise")
|
|
|
|
def test_set_intensity(self):
|
|
"""intensity command sets plugin intensity."""
|
|
with patch("engine.effects.controller.get_registry") as mock_registry:
|
|
mock_plugin = MagicMock()
|
|
mock_plugin.config.intensity = 0.5
|
|
mock_registry.return_value.get.return_value = mock_plugin
|
|
mock_registry.return_value.list_all.return_value = {"noise": mock_plugin}
|
|
|
|
result = handle_effects_command("/effects noise intensity 0.8")
|
|
|
|
assert "intensity to 0.8" in result
|
|
assert mock_plugin.config.intensity == 0.8
|
|
|
|
def test_invalid_intensity_range(self):
|
|
"""intensity outside 0.0-1.0 returns error."""
|
|
with patch("engine.effects.controller.get_registry") as mock_registry:
|
|
mock_plugin = MagicMock()
|
|
mock_registry.return_value.get.return_value = mock_plugin
|
|
mock_registry.return_value.list_all.return_value = {"noise": mock_plugin}
|
|
|
|
result = handle_effects_command("/effects noise intensity 1.5")
|
|
|
|
assert "between 0.0 and 1.0" in result
|
|
|
|
def test_reorder_pipeline(self):
|
|
"""reorder command calls chain.reorder."""
|
|
with patch("engine.effects.controller.get_registry") as mock_registry:
|
|
mock_registry.return_value.list_all.return_value = {}
|
|
|
|
with patch("engine.effects.controller._get_effect_chain") as mock_chain:
|
|
mock_chain_instance = MagicMock()
|
|
mock_chain_instance.reorder.return_value = True
|
|
mock_chain.return_value = mock_chain_instance
|
|
|
|
result = handle_effects_command("/effects reorder noise,fade")
|
|
|
|
assert "Reordered pipeline" in result
|
|
mock_chain_instance.reorder.assert_called_once_with(["noise", "fade"])
|
|
|
|
def test_unknown_command(self):
|
|
"""unknown command returns error."""
|
|
result = handle_effects_command("/unknown")
|
|
assert "Unknown command" in result
|
|
|
|
def test_non_effects_command(self):
|
|
"""non-effects command returns error."""
|
|
result = handle_effects_command("not a command")
|
|
assert "Unknown command" in result
|
|
|
|
|
|
class TestSetEffectChainRef:
|
|
"""Tests for set_effect_chain_ref function."""
|
|
|
|
def test_sets_global_ref(self):
|
|
"""set_effect_chain_ref updates global reference."""
|
|
mock_chain = MagicMock()
|
|
set_effect_chain_ref(mock_chain)
|
|
|
|
from engine.effects.controller import _get_effect_chain
|
|
|
|
result = _get_effect_chain()
|
|
assert result == mock_chain
|