Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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"
Пример #5
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
Пример #6
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"
Пример #7
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)
Пример #8
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"
Пример #9
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)
Пример #10
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)
Пример #11
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)
Пример #12
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
Пример #13
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
Пример #14
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)
        ])
Пример #15
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
Пример #16
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"
Пример #17
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
Пример #18
0
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':
    if lang == 'es':
Пример #19
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)
Пример #20
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"