mopidy-raspberrypi-gpio/tests/test_frontend.py

41 lines
1018 B
Python
Raw Normal View History

2019-10-10 14:16:37 +02:00
import sys
2019-11-21 19:24:41 +01:00
from unittest import mock
2019-10-10 14:16:37 +02:00
import pytest
2019-11-21 19:14:34 +01:00
from mopidy_raspberry_gpio import Extension
2019-10-10 16:52:43 +02:00
from mopidy_raspberry_gpio import frontend as frontend_lib
2019-11-21 19:14:34 +01:00
from mopidy_raspberry_gpio import pinconfig
2019-10-10 14:16:37 +02:00
2019-10-10 16:52:43 +02:00
deserialize = pinconfig.PinConfig().deserialize
2019-10-10 14:16:37 +02:00
dummy_config = {
"raspberry-gpio": {
2019-10-10 16:52:43 +02:00
# Plugins expect settings to be deserialized
"bcm1": deserialize("play_pause,active_low,30")
2019-10-10 14:16:37 +02:00
}
}
def test_get_frontend_classes():
2019-11-21 19:13:31 +01:00
sys.modules["RPi"] = mock.Mock()
sys.modules["RPi.GPIO"] = mock.Mock()
2019-10-10 14:16:37 +02:00
ext = Extension()
registry = mock.Mock()
ext.setup(registry)
registry.add.assert_called_once_with(
2019-11-21 19:13:31 +01:00
"frontend", frontend_lib.RaspberryGPIOFrontend
)
2019-10-10 14:16:37 +02:00
def test_frontend_handler_dispatch():
2019-11-21 19:13:31 +01:00
sys.modules["RPi"] = mock.Mock()
sys.modules["RPi.GPIO"] = mock.Mock()
2019-10-10 14:16:37 +02:00
frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, mock.Mock())
with pytest.raises(RuntimeError):
2019-11-21 19:13:31 +01:00
frontend.dispatch_input("tomato")