Skip to content
Snippets Groups Projects
Select Git revision
  • 773c246232c1f3d7fc67d7ddf5b1cb172ece8fa1
  • master default protected
  • docs-release-checklist-037
  • release
  • release-v0.37.0
  • staging
  • reprovide-sweep
  • copilot/fix-859994d3-9d4e-4a8e-bea3-58b58c75a399
  • feat/boxo-retrieval-diagnostics
  • dependabot/github_actions/codecov/codecov-action-5.5.0
  • config-api-for-path
  • fix/panic-and-zombie-daemons
  • chore-golangci-v2
  • config-reprovider-test
  • release-v036
  • release-v0.36.0
  • telemetry-plugin
  • fix-editor-env-handling
  • fix-flush-files-rm
  • unixfs-percent-encoding-poc
  • fix/systemd-path
  • v0.37.0
  • v0.37.0-rc1
  • v0.36.0
  • v0.36.0-rc2
  • v0.36.0-rc1
  • v0.35.0
  • v0.35.0-rc2
  • v0.35.0-rc1
  • v0.34.1
  • v0.34.0
  • v0.34.0-rc2
  • v0.34.0-rc1
  • v0.33.2
  • v0.33.1
  • v0.33.0
  • v0.33.0-rc3
  • v0.33.0-rc2
  • v0.33.0-rc1
  • v0.32.1
  • v0.32.0
41 results

routing.go

Blame
  • test_gpio_interrupt.py 1.74 KiB
    import mock
    import pytest
    
    from pi_mqtt_gpio import server
    from pi_mqtt_gpio.server import GPIO_INTERRUPT_LOOKUP
    from pi_mqtt_gpio.modules.stdio import GPIO
    
    
    @pytest.fixture
    def fix_interrupt():
        GPIO_INTERRUPT_LOOKUP.clear()
        yield fix_interrupt
    
    
    @mock.patch("pi_mqtt_gpio.modules.stdio.GPIO")
    def test_server_gpio_configure_gpio_module(mock_std_gpio):
        """
        check stdio configure module
        """
        gpio_config = {"name": "dev", "module": "stdio", "cleanup": False}
        server.configure_gpio_module(gpio_config)
        mock_std_gpio.assert_called()
    
    
    @mock.patch("pi_mqtt_gpio.modules.stdio.GPIO")
    def test_server_gpio_initialise_digital_input(mock_std_gpio):
        """
        check stdio input
        """
        in_conf = {
            "name": "button",
            "module": "dev",
            "pin": 21,
            "on_payload": "ON",
            "off_payload": "OFF",
            "pullup": False,
            "pulldown": True,
            "interrupt": "none",
            "bouncetime": 100,
        }
        server.initialise_digital_input(in_conf, mock_std_gpio)
        mock_std_gpio.setup_pin.assert_called()
        mock_std_gpio.setup_interrupt.assert_not_called()
    
    
    @mock.patch("pi_mqtt_gpio.modules.stdio.GPIO")
    def test_server_gpio_initialise_digital_input_interrupt(mock_std_gpio, fix_interrupt):
        """	
        check stdio input with interrupt
        """
        in_conf = {
            "name": "button",
            "module": "dev",
            "pin": 21,
            "on_payload": "ON",
            "off_payload": "OFF",
            "pullup": False,
            "pulldown": True,
            "interrupt": "rising",
            "bouncetime": 100,
        }
        server.initialise_digital_input(in_conf, mock_std_gpio)
        mock_std_gpio.setup_pin.assert_called()
        mock_std_gpio.setup_interrupt.assert_called()
        assert GPIO_INTERRUPT_LOOKUP["dev"][21] == in_conf