forked from flyte/mqtt-io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_gpio_interrupt.py
65 lines (56 loc) · 1.74 KB
/
test_gpio_interrupt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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