def test_frontend_gpio_event(): sys.modules["RPi"] = mock.Mock() sys.modules["RPi.GPIO"] = mock.Mock() frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, dummy_mopidy_core()) frontend.gpio_event(3) stop_mopidy_core()
def test_frontend_handler_dispatch_volume_up(): sys.modules["RPi"] = mock.Mock() sys.modules["RPi.GPIO"] = mock.Mock() frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, dummy_mopidy_core()) frontend.dispatch_input("volume_up") stop_mopidy_core()
def test_frontend_handler_dispatch_invalid_event(): sys.modules["RPi"] = mock.Mock() sys.modules["RPi.GPIO"] = mock.Mock() frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, dummy_mopidy_core()) with pytest.raises(RuntimeError): frontend.dispatch_input("tomato") stop_mopidy_core()
def test_frontend_handler_dispatch_volume_up(): sys.modules["RPi"] = mock.Mock() sys.modules["RPi.GPIO"] = mock.Mock() frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, dummy_mopidy_core()) ext = Extension() schema = ext.get_config_schema() settings = schema["bcm1"].deserialize("volume_up,active_low,30") frontend.dispatch_input(settings) stop_mopidy_core()
def test_frontend_rot_encoder_event(patched_input): patched_input.return_value = False frontend = frontend_lib.RaspberryGPIOFrontend(dummy_config, dummy_mopidy_core()) # Check that transition (False, True) -> (False, False) triggers volume_up encoder = frontend.rot_encoders["vol"] encoder.state = (False, True) dispatch_input = mock.Mock() frontend.dispatch_input = dispatch_input frontend.gpio_event(4) assert dispatch_input.call_args[0][0] == "volume_up" assert encoder.state == (False, False) # Check that we do not submit an event for the invalid transition # (False, False) -> (False, False) dispatch_input.reset_mock() frontend.gpio_event(4) dispatch_input.assert_not_called() stop_mopidy_core()