def test_arguments(): ptest() # Invalid open types with AssertRaises("invalid open types", TypeError): periphery.LED("abc", "out") with AssertRaises("invalid open types", TypeError): periphery.LED(100, 100)
def test_arguments(): print("Starting arguments test...") # Invalid open types with AssertRaises(TypeError): periphery.LED("abc", "out") with AssertRaises(TypeError): periphery.LED(100, 100) print("Arguments test passed.")
def test_interactive(): ptest() led = periphery.LED(led_name, False) raw_input("Press enter to continue...") # Check tostring print("LED description: {}".format(str(led))) passert("interactive success", raw_input("LED description looks ok? y/n ") == "y") # Turn LED off led.write(False) passert("interactive success", raw_input("LED is off? y/n ") == "y") # Turn LED on led.write(True) passert("interactive success", raw_input("LED is on? y/n ") == "y") # Turn LED off led.write(False) passert("interactive success", raw_input("LED is off? y/n ") == "y") # Turn LED on led.write(True) passert("interactive success", raw_input("LED is on? y/n ") == "y") led.close()
def test_interactive(): print("Starting interactive test...") led = periphery.LED(led_name, False) raw_input("Press enter to continue...") # Check tostring print("LED description: {}".format(str(led))) assert raw_input("LED description looks ok? y/n ") == "y" # Turn LED off led.write(False) assert raw_input("LED is off? y/n ") == "y" # Turn LED on led.write(True) assert raw_input("LED is on? y/n ") == "y" # Turn LED off led.write(False) assert raw_input("LED is off? y/n ") == "y" # Turn LED on led.write(True) assert raw_input("LED is on? y/n ") == "y" led.close() print("Interactive test passed.")
def test_open_close(): print("Starting open/close test...") # Open non-existent LED with AssertRaises(LookupError): periphery.LED("invalid_led_XXX", 0) # Open legitimate LED led = periphery.LED(led_name, 0) assert led.name == led_name assert led.fd > 0 assert led.max_brightness > 0 # Set brightness to 1, check brightness led.write(1) time.sleep(0.01) assert led.read() >= 1 # Set brightness to 0, check brightness led.write(0) time.sleep(0.01) assert led.read() == 0 # Set brightness to 1, check brightness led.brightness = 1 time.sleep(0.01) assert led.brightness >= 1 # Set brightness to 0, check brightness led.brightness = 0 time.sleep(0.01) assert led.brightness == 0 # Set brightness to True, check brightness led.write(True) time.sleep(0.01) assert led.read() == led.max_brightness # Set brightness to False, check brightness led.write(False) time.sleep(0.01) assert led.read() == 0 led.close() print("Open/close test passed.")
def test_open_close(): ptest() # Open non-existent LED with AssertRaises("non-existent led", LookupError): periphery.LED("invalid_led_XXX", 0) # Open legitimate LED led = periphery.LED(led_name, 0) passert("property name", led.name == led_name) passert("fd >= 0", led.fd >= 0) passert("max_brightness > 0", led.max_brightness > 0) # Set brightness to True, check brightness led.write(True) time.sleep(0.01) passert("brightness is max", led.read() == led.max_brightness) # Set brightness to False, check brightness led.write(False) time.sleep(0.01) passert("brightness is zero", led.read() == 0) # Set brightness to 1, check brightness led.write(1) time.sleep(0.01) passert("brightness is non-zero", led.read() >= 1) # Set brightness to 0, check brightness led.write(0) time.sleep(0.01) passert("brightness is zero", led.read() == 0) # Set brightness to 1, check brightness led.brightness = 1 time.sleep(0.01) passert("brightness is non-zero", led.brightness >= 1) # Set brightness to 0, check brightness led.brightness = 0 time.sleep(0.01) passert("brightness is zero", led.brightness == 0) led.close()
def test_open_close(): print("Starting open/close test...") # Open non-existent LED (export should fail with EINVAL) with AssertRaises(ValueError): periphery.LED("invalid_led_XXX", 0) # Open legitimate LED led = periphery.LED(led_name, 0) assert led.name == led_name assert led.fd > 0 assert led.max_brightness > 0 # Set brightness to 1, check brightness led.write(1) assert led.read() == 1 # Set brightness to 0, check brightness led.write(0) assert led.read() == 0 # Set brightness to 1, check brightness led.brightness = 1 assert led.brightness == 1 # Set brightness to 0, check brightness led.brightness = 0 assert led.brightness == 0 # Set brightness to True, check brightness led.write(True) assert led.read() == led.max_brightness # Set brightness to False, check brightness led.write(False) assert led.read() == 0 led.close() print("Open/close test passed.")
def test_interactive(): print("Starting interactive test...") led = periphery.LED(led_name, False) raw_input("Press enter to continue...") # Turn LED off led.write(False) assert raw_input("LED is off? y/n ") == "y" # Turn LED on led.write(True) assert raw_input("LED is on? y/n ") == "y" # Turn LED off led.write(False) assert raw_input("LED is off? y/n ") == "y" led.close() print("Interactive test passed.")