mopidy-raspberrypi-gpio/tests/test_frontend.py

42 lines
970 B
Python
Raw Normal View History

2019-10-10 14:16:37 +02:00
import sys
import mock
import pytest
2019-10-10 16:52:43 +02:00
from mopidy_raspberry_gpio import Extension, pinconfig
from mopidy_raspberry_gpio import frontend as frontend_lib
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():
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi.GPIO'] = mock.Mock()
ext = Extension()
registry = mock.Mock()
ext.setup(registry)
registry.add.assert_called_once_with(
'frontend', frontend_lib.RaspberryGPIOFrontend)
def test_frontend_handler_dispatch():
sys.modules['RPi'] = mock.Mock()
sys.modules['RPi.GPIO'] = mock.Mock()
frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, mock.Mock())
with pytest.raises(RuntimeError):
frontend.dispatch_input('tomato')