summaryrefslogtreecommitdiff
path: root/tests/wipy/pin.py
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2020-03-22 21:26:08 -0500
committerDamien George <damien.p.george@gmail.com>2020-03-30 13:21:58 +1100
commit3dc324d3f1312e40d3a8ed87e7244966bb756f26 (patch)
tree94ff44f8eabba0039582c245b901173597edd11e /tests/wipy/pin.py
parent488613bca6c460340ed2995ae5cafafe22d0bfff (diff)
tests: Format all Python code with black, except tests in basics subdir.
This adds the Python files in the tests/ directory to be formatted with ./tools/codeformat.py. The basics/ subdirectory is excluded for now so we aren't changing too much at once. In a few places `# fmt: off`/`# fmt: on` was used where the code had special formatting for readability or where the test was actually testing the specific formatting.
Diffstat (limited to 'tests/wipy/pin.py')
-rw-r--r--tests/wipy/pin.py111
1 files changed, 73 insertions, 38 deletions
diff --git a/tests/wipy/pin.py b/tests/wipy/pin.py
index 22c7c6176..9ffd152e9 100644
--- a/tests/wipy/pin.py
+++ b/tests/wipy/pin.py
@@ -7,27 +7,61 @@ from machine import Pin
import os
mch = os.uname().machine
-if 'LaunchPad' in mch:
- pin_map = ['GP24', 'GP12', 'GP14', 'GP15', 'GP16', 'GP17', 'GP28', 'GP8', 'GP6', 'GP30', 'GP31', 'GP3', 'GP0', 'GP4', 'GP5']
+if "LaunchPad" in mch:
+ pin_map = [
+ "GP24",
+ "GP12",
+ "GP14",
+ "GP15",
+ "GP16",
+ "GP17",
+ "GP28",
+ "GP8",
+ "GP6",
+ "GP30",
+ "GP31",
+ "GP3",
+ "GP0",
+ "GP4",
+ "GP5",
+ ]
max_af_idx = 15
-elif 'WiPy' in mch:
- pin_map = ['GP23', 'GP24', 'GP12', 'GP13', 'GP14', 'GP9', 'GP17', 'GP28', 'GP22', 'GP8', 'GP30', 'GP31', 'GP0', 'GP4', 'GP5']
+elif "WiPy" in mch:
+ pin_map = [
+ "GP23",
+ "GP24",
+ "GP12",
+ "GP13",
+ "GP14",
+ "GP9",
+ "GP17",
+ "GP28",
+ "GP22",
+ "GP8",
+ "GP30",
+ "GP31",
+ "GP0",
+ "GP4",
+ "GP5",
+ ]
max_af_idx = 15
else:
- raise Exception('Board not supported!')
+ raise Exception("Board not supported!")
# test initial value
-p = Pin('GP12', Pin.IN)
-Pin('GP17', Pin.OUT, value=1)
+p = Pin("GP12", Pin.IN)
+Pin("GP17", Pin.OUT, value=1)
print(p() == 1)
-Pin('GP17', Pin.OUT, value=0)
+Pin("GP17", Pin.OUT, value=0)
print(p() == 0)
+
def test_noinit():
for p in pin_map:
pin = Pin(p)
pin.value()
+
def test_pin_read(pull):
# enable the pull resistor on all pins, then read the value
for p in pin_map:
@@ -35,6 +69,7 @@ def test_pin_read(pull):
for p in pin_map:
print(pin())
+
def test_pin_af():
for p in pin_map:
for af in Pin(p).alt_list():
@@ -42,6 +77,7 @@ def test_pin_af():
Pin(p, mode=Pin.ALT, alt=af[1])
Pin(p, mode=Pin.ALT_OPEN_DRAIN, alt=af[1])
+
# test un-initialized pins
test_noinit()
# test with pull-up and pull-down
@@ -65,7 +101,7 @@ pin = Pin(pin_map[0], mode=Pin.OUT, drive=pin.LOW_POWER)
pin = Pin(pin_map[0], Pin.OUT, Pin.PULL_DOWN)
pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_UP)
pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP)
-test_pin_af() # try the entire af range on all pins
+test_pin_af() # try the entire af range on all pins
# test pin init and printing
pin = Pin(pin_map[0])
@@ -81,9 +117,9 @@ print(pin)
# test value in OUT mode
pin = Pin(pin_map[0], mode=Pin.OUT)
pin.value(0)
-pin.toggle() # test toggle
+pin.toggle() # test toggle
print(pin())
-pin.toggle() # test toggle again
+pin.toggle() # test toggle again
print(pin())
# test different value settings
pin(1)
@@ -116,67 +152,66 @@ print(pin.id() == pin_map[0])
# all the next ones MUST raise
try:
- pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.IN) # incorrect drive value
+ pin = Pin(pin_map[0], mode=Pin.OUT, pull=Pin.PULL_UP, drive=pin.IN) # incorrect drive value
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin(pin_map[0], mode=Pin.LOW_POWER, pull=Pin.PULL_UP) # incorrect mode value
+ pin = Pin(pin_map[0], mode=Pin.LOW_POWER, pull=Pin.PULL_UP) # incorrect mode value
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.HIGH_POWER) # incorrect pull value
+ pin = Pin(pin_map[0], mode=Pin.IN, pull=Pin.HIGH_POWER) # incorrect pull value
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin('A0', Pin.OUT, Pin.PULL_DOWN) # incorrect pin id
+ pin = Pin("A0", Pin.OUT, Pin.PULL_DOWN) # incorrect pin id
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin(pin_map[0], Pin.IN, Pin.PULL_UP, alt=0) # af specified in GPIO mode
+ pin = Pin(pin_map[0], Pin.IN, Pin.PULL_UP, alt=0) # af specified in GPIO mode
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin(pin_map[0], Pin.OUT, Pin.PULL_UP, alt=7) # af specified in GPIO mode
+ pin = Pin(pin_map[0], Pin.OUT, Pin.PULL_UP, alt=7) # af specified in GPIO mode
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_UP, alt=0) # incorrect af
+ pin = Pin(pin_map[0], Pin.ALT, Pin.PULL_UP, alt=0) # incorrect af
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=-1) # incorrect af
+ pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=-1) # incorrect af
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=16) # incorrect af
+ pin = Pin(pin_map[0], Pin.ALT_OPEN_DRAIN, Pin.PULL_UP, alt=16) # incorrect af
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin.mode(Pin.PULL_UP) # incorrect pin mode
+ pin.mode(Pin.PULL_UP) # incorrect pin mode
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin.pull(Pin.OUT) # incorrect pull
+ pin.pull(Pin.OUT) # incorrect pull
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin.drive(Pin.IN) # incorrect drive strength
+ pin.drive(Pin.IN) # incorrect drive strength
except Exception:
- print('Exception')
+ print("Exception")
try:
- pin.id('ABC') # id cannot be set
+ pin.id("ABC") # id cannot be set
except Exception:
- print('Exception')
-
+ print("Exception")