Пример #1
0
def test_input_not_configured_for_output():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.IN)
        with pytest.raises(RuntimeError) as ex:
            GPIO.output(23, GPIO.LOW)
        assert str(ex.value) == "Channel 23 is configured for input"
Пример #2
0
def test_input_and_output():
    with patch("LPi.GPIO.sysfs") as mock:
        mock.input.return_value = GPIO.HIGH
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.OUT)
        GPIO.output(23, not GPIO.input(23))
        mock.input.assert_called_with(14)
        mock.output.assert_called_with(14, GPIO.LOW)
Пример #3
0
def test_multiple_output():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup([23, 13, 3], GPIO.OUT)
        GPIO.output([23, 13, 3], GPIO.LOW)
        mock.output.assert_has_calls([
            call(14, GPIO.LOW),
            call(0, GPIO.LOW),
            call(12, GPIO.LOW)
        ])
Пример #4
0
def test_output():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.OUT)
        GPIO.output(23, GPIO.LOW)
        mock.output.assert_called_with(14, GPIO.LOW)
Пример #5
0
def test_output_not_configured():
    with pytest.raises(RuntimeError) as ex:
        GPIO.output(12, GPIO.LOW)
    assert str(ex.value) == "Channel 12 is not configured"