예제 #1
0
def test_input():
    with patch("LPi.GPIO.sysfs") as mock:
        mock.input.return_value = GPIO.HIGH
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.IN)
        assert GPIO.input(23) == GPIO.HIGH
        mock.input.assert_called_with(14)
예제 #2
0
def test_event_detected():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.IN)
        with patch("LPi.GPIO.event") as mock:
            mock.edge_detected.return_value = True
            assert GPIO.event_detected(23)
예제 #3
0
def test_setup_single_input_channel():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.SUNXI)
        GPIO.setup("PA01", GPIO.IN)
        mock.export.assert_called_with(1)
        mock.direction.assert_called_with(1, GPIO.IN)
        assert "PA01" in GPIO._exports
예제 #4
0
def test_wait_for_edge_completes():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(12, GPIO.IN)
        with patch("LPi.GPIO.event") as mock:
            mock.blocking_wait_for_edge.return_value = 1
            assert GPIO.wait_for_edge(12, GPIO.BOTH) == 12
            mock.blocking_wait_for_edge.assert_called_with(7, GPIO.BOTH, -1)
예제 #5
0
def test_setup_single_output_channel():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.SUNXI)
        GPIO.setup("PG07", GPIO.OUT)
        mock.export.assert_called_with(199)
        mock.direction.assert_called_with(199, GPIO.OUT)
        mock.output.assert_not_called()
        assert "PG07" in GPIO._exports
예제 #6
0
def test_setup_single_output_channel_with_initial_value():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.SUNXI)
        GPIO.setup("PG06", GPIO.OUT, GPIO.HIGH)
        mock.export.assert_called_with(198)
        mock.direction.assert_called_with(198, GPIO.OUT)
        mock.output.assert_called_with(198, GPIO.HIGH)
        assert "PG06" in GPIO._exports
예제 #7
0
def test_setup_channel_already_in_use_raises_IOError():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.SUNXI)
        mock.export.side_effect = [IOError(16, "test"), None]
        GPIO.setup("PG06", GPIO.OUT)
        mock.export.assert_called_with(198)
        mock.unexport.assert_called_with(198)
        mock.direction.assert_called_with(198, GPIO.OUT)
        mock.output.assert_not_called()
        assert "PG06" in GPIO._exports
예제 #8
0
def test_mode():
    assert GPIO.getmode() is None
    GPIO.setmode(GPIO.BCM)
    assert GPIO.getmode() == GPIO.BCM
    GPIO.cleanup()
    assert GPIO.getmode() is None
    with pytest.raises(AssertionError):
        GPIO.setmode("Sausages")
예제 #9
0
def test_setup_raises_OSError():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.SUNXI)
        mock.export.side_effect = OSError(44, "test")
        with pytest.raises(OSError) as ex:
            GPIO.setup("PG07", GPIO.OUT)
        assert str(ex.value) == "[Errno 44] test"
        mock.export.assert_called_with(199)
        mock.unexport.assert_not_called()
        mock.direction.assert_not_called()
        mock.output.assert_not_called()
        assert "PG07" not in GPIO._exports
예제 #10
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)
예제 #11
0
def test_callback_wrapper_not_none():
    called = []

    def cb(pin):
        called.append(pin)

    callback = GPIO.__wrap(cb, 17)
    callback(97)
    assert 17 in called
    assert 97 not in called
예제 #12
0
def test_wait_for_edge_not_configured_for_input():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(12, GPIO.OUT)
        with pytest.raises(RuntimeError) as ex:
            GPIO.wait_for_edge(12, GPIO.RISING)
        assert str(ex.value) == "Channel 12 is configured for output"
예제 #13
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"
예제 #14
0
def test_add_event_detect():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.IN)
        with patch("LPi.GPIO.event") as mock:
            GPIO.add_event_detect(23, GPIO.BOTH)
            mock.add_edge_detect.assert_called_with(14, GPIO.BOTH, None)
예제 #15
0
def test_event_detected_not_configured_for_input():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.OUT)
        with pytest.raises(RuntimeError) as ex:
            GPIO.event_detected(23)
        assert str(ex.value) == "Channel 23 is configured for output"
예제 #16
0
def test_add_event_callback():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.IN)
        with patch("LPi.GPIO.event") as mock:
            GPIO.add_event_callback(23, None)
            mock.add_edge_callback(14, None)
예제 #17
0
def test_remove_event_detect():
    with patch("LPi.GPIO.sysfs"):
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(23, GPIO.IN)
        with patch("LPi.GPIO.event") as mock:
            GPIO.remove_event_detect(23)
            mock.remove_edge_detect.assert_called_with(14)
예제 #18
0
def test_setup_channel_already_setup():
    with patch("LPi.GPIO.sysfs") as mock:
        GPIO.setmode(GPIO.SUNXI)
        GPIO.setup("PA01", GPIO.IN)
        mock.export.assert_called_with(1)
        mock.direction.assert_called_with(1, GPIO.IN)
        assert "PA01" in GPIO._exports
        with pytest.raises(RuntimeError) as ex:
            GPIO.setup("PA01", GPIO.OUT)
        assert str(ex.value) == "Channel PA01 is already configured"
예제 #19
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)
        ])
예제 #20
0
## Google calendar dependencies
import httplib2
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
try:
    import argparse
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
    flags = None

# Setup GPIO pin BCM GPIO04
import LPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(6, GPIO.IN)  # Next
# GPIO.setup( 17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN )    # Shutdown

mouseX, mouseY = 0, 0
mode = 'w'  # Default to weather mode.
data_refresh = 15
disp_units = "metric"
#disp_units = "imperial"
zip_code = 'SPXX0819'
lang = 'es'  #'en': English (default), 'es': Spanish

# Show degree F symbol using magic unicode char in a smaller font size.
# The variable uniTmp holds a unicode character that is either DegreeC or DegreeF.
# Yep, one unicode character is has both the letter and the degree symbol.
if disp_units == 'metric':
예제 #21
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"
예제 #22
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)
예제 #23
0
def test_setup_with_no_mode():
    with pytest.raises(RuntimeError) as ex:
        GPIO.setup(3, GPIO.IN)
    assert str(ex.value) == "Mode has not been set"
예제 #24
0
def test_warnings():
    GPIO.setwarnings(False)
    assert not GPIO._gpio_warnings
    GPIO.setwarnings(True)
    assert GPIO._gpio_warnings
예제 #25
0
def test_callback_wrapper_none():
    assert GPIO.__wrap(None, 12) is None
예제 #26
0
def setup():
    with patch("LPi.GPIO.sysfs"):
        GPIO.cleanup()
예제 #27
0
def test_wait_for_edge_not_configured():
    with pytest.raises(RuntimeError) as ex:
        GPIO.wait_for_edge(91, GPIO.RISING)
    assert str(ex.value) == "Channel 91 is not configured"