def test_set_warnings(): GPIO_DEVEL.Reset() GPIO.setwarnings(True) assert GPIO_DEVEL.State_Access().warnings == True GPIO.setwarnings(False) assert GPIO_DEVEL.State_Access().warnings == False
def test_setdebuginfo(): GPIO_DEVEL.Reset() # Off by default assert GPIO_DEVEL.State_Access().debuginfo == False GPIO_DEVEL.setdebuginfo(True) assert GPIO_DEVEL.State_Access().debuginfo == True
def test_getmode(): GPIO_DEVEL.Reset() GPIO_DEVEL.State_Access().mode = GPIO.BOARD assert GPIO.getmode() == GPIO.BOARD GPIO_DEVEL.State_Access().mode = GPIO.BCM assert GPIO.getmode() == GPIO.BCM GPIO_DEVEL.State_Access().mode = None assert GPIO.getmode() == None GPIO_DEVEL.Reset()
def test_setup(): GPIO_DEVEL.Reset() GPIO.setmode(GPIO.BCM) with pytest.raises(ValueError) as e: GPIO.setup("foo", "bar") assert "Channel must be an integer" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup("foo", GPIO.OUT) assert "Channel must be an integer" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup(["foo", "bar"], GPIO.OUT) assert "Channel must be an integer" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup([1, "bar"], GPIO.OUT) assert "Channel must be an integer" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup(54, GPIO.OUT) assert "channel sent is invalid" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup(666, GPIO.OUT) assert "channel sent is invalid" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup(-1, GPIO.OUT) assert "channel sent is invalid" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup(23, -666) # Shoutout to RPi.GPIO magic numbers assert "invalid direction was passed" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup(18, GPIO.OUT, GPIO.PUD_UP) assert "pull_up_down parameter is not valid for outputs" in str(e.value) with pytest.raises(ValueError) as e: GPIO.setup(18, GPIO.IN, -666) assert "Invalid value for pull_up_down" in str(e.value) GPIO.setup(18, GPIO.IN, GPIO.PUD_UP) with pytest.warns(Warning) as w: GPIO.setup([16,17,18], GPIO.OUT) assert "already in use" in str(w[0].message) with pytest.raises(ValueError) as e: GPIO.setup(2, GPIO.IN, GPIO.PUD_OFF, 1) assert "initial parameter is not valid for inputs" in str(e.value) GPIO.setup([2,3,4], GPIO.OUT) # Ensure line objects for those pins were successfully created assert all([pin in GPIO_DEVEL.State_Access().lines.keys() for pin in [2,3,4]])
def test_event_detected(): GPIO_DEVEL.Reset() GPIO.setmode(GPIO.BCM) GPIO.add_event_detect(18, GPIO.FALLING, bouncetime=1) GPIO.event_detected(18) assert GPIO.event_detected(18) == False # Manufacture a false positive GPIO_DEVEL.State_Access().event_ls.append(18) assert GPIO.event_detected(18) == True GPIO_DEVEL.Reset()