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"
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)
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) ])
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)
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"