X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/04ae17d37e3ab669f57315a0c7c923f240a90f1d..refs/heads/typing-micropython:/test/src/testing/universal/digitalio.py diff --git a/test/src/testing/universal/digitalio.py b/test/src/testing/universal/digitalio.py index 78db5cb..36eff5b 100644 --- a/test/src/testing/universal/digitalio.py +++ b/test/src/testing/universal/digitalio.py @@ -1,10 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT import unittest from testing import yes_no, await_true from testing.board import led_pin, default_pin, led_hardwired, led_inverted from digitalio import * -class TestDigitalInOut(unittest.TestCase): +class TestDigitalInOut(unittest.TestCase): def test_default(self): """DigitalInOut is input with no pull when constructed""" with DigitalInOut(default_pin) as dio: @@ -22,20 +25,20 @@ class TestDigitalInOut(unittest.TestCase): def test_switch_to_input(self): """Default configuration of switch_to_input is respected""" with DigitalInOut(default_pin) as dio: - dio.switch_to_output() # starts as input anyway + dio.switch_to_output() # starts as input anyway dio.switch_to_input() self.assertEqual(dio.direction, Direction.INPUT) self.assertEqual(dio.pull, None) class TestDigitalInOutInteractive(unittest.TestCase): - def test_blink(self): """LED blinks when proper attributes set""" print() from adafruit_blinka.agnostic import sleep - if not(led_hardwired) and not(yes_no("Is LED wired to {}".format(led_pin))): - return # test trivially passed + + if not (led_hardwired) and not (yes_no("Is LED wired to {}".format(led_pin))): + return # test trivially passed with DigitalInOut(led_pin) as led: led.direction = Direction.OUTPUT # should now be OUT, PUSH_PULL, value=0, and LED should light @@ -43,9 +46,9 @@ class TestDigitalInOutInteractive(unittest.TestCase): self.assertTrue(yes_no("Is LED lit")) print("Winking LED...") for count in range(2): - led.value = not(led.value) + led.value = not (led.value) sleep(0.5) - led.value = not(led.value) + led.value = not (led.value) sleep(0.5) self.assertTrue(yes_no("Did LED wink twice")) @@ -53,7 +56,7 @@ class TestDigitalInOutInteractive(unittest.TestCase): print() """Pull-up button configured and detected""" with DigitalInOut(default_pin) as button: - #button.direction = Direction.INPUT # implied + # button.direction = Direction.INPUT # implied try: button.pull = Pull.UP except NotImplementedError as e: @@ -64,13 +67,15 @@ class TestDigitalInOutInteractive(unittest.TestCase): return # pull unsupported, test trivially passed if yes_no("Is Button wired from {} to GND".format(default_pin)): self.assertTrue(button.value == True) - self.assertTrue(await_true("button pressed", lambda: button.value == False)) + self.assertTrue( + await_true("button pressed", lambda: button.value == False) + ) def test_button_pull_down(self): print() """Pull-down button configured and detected""" with DigitalInOut(default_pin) as button: - #button.direction = Direction.INPUT # implied + # button.direction = Direction.INPUT # implied try: button.pull = Pull.DOWN except NotImplementedError as e: @@ -79,7 +84,8 @@ class TestDigitalInOutInteractive(unittest.TestCase): except Exception as e: print(e) return # pull unsupported, test trivially passed - if (yes_no("Is Button wired from {} to VCC".format(default_pin))): + if yes_no("Is Button wired from {} to VCC".format(default_pin)): self.assertTrue(button.value == False) - self.assertTrue(await_true("button pressed", lambda: button.value == True)) - + self.assertTrue( + await_true("button pressed", lambda: button.value == True) + )