aboutsummaryrefslogtreecommitdiff
path: root/tests/pyb
diff options
context:
space:
mode:
authorDavid Lechner2020-03-22 21:26:08 -0500
committerDamien George2020-03-30 13:21:58 +1100
commit3dc324d3f1312e40d3a8ed87e7244966bb756f26 (patch)
tree94ff44f8eabba0039582c245b901173597edd11e /tests/pyb
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/pyb')
-rw-r--r--tests/pyb/accel.py4
-rw-r--r--tests/pyb/adc.py23
-rw-r--r--tests/pyb/board_pybv1x.py4
-rw-r--r--tests/pyb/can.py153
-rw-r--r--tests/pyb/can2.py11
-rw-r--r--tests/pyb/dac.py4
-rw-r--r--tests/pyb/extint.py2
-rw-r--r--tests/pyb/i2c_accel.py6
-rw-r--r--tests/pyb/i2c_error.py28
-rw-r--r--tests/pyb/irq.py4
-rw-r--r--tests/pyb/led.py6
-rw-r--r--tests/pyb/modtime.py31
-rw-r--r--tests/pyb/pin.py8
-rw-r--r--tests/pyb/pyb1.py4
-rw-r--r--tests/pyb/pyb_f405.py5
-rw-r--r--tests/pyb/pyb_f411.py4
-rw-r--r--tests/pyb/rtc.py17
-rw-r--r--tests/pyb/spi.py2
-rw-r--r--tests/pyb/timer.py2
-rw-r--r--tests/pyb/timer_callback.py5
-rw-r--r--tests/pyb/uart.py8
21 files changed, 184 insertions, 147 deletions
diff --git a/tests/pyb/accel.py b/tests/pyb/accel.py
index 9aa60c185..7a5e072be 100644
--- a/tests/pyb/accel.py
+++ b/tests/pyb/accel.py
@@ -1,7 +1,7 @@
import pyb
-if not hasattr(pyb, 'Accel'):
- print('SKIP')
+if not hasattr(pyb, "Accel"):
+ print("SKIP")
raise SystemExit
accel = pyb.Accel()
diff --git a/tests/pyb/adc.py b/tests/pyb/adc.py
index ef4206538..875d31d73 100644
--- a/tests/pyb/adc.py
+++ b/tests/pyb/adc.py
@@ -1,8 +1,8 @@
from pyb import ADC, Timer
-adct = ADC(16) # Temperature 930 -> 20C
+adct = ADC(16) # Temperature 930 -> 20C
print(str(adct)[:19])
-adcv = ADC(17) # Voltage 1500 -> 3.3V
+adcv = ADC(17) # Voltage 1500 -> 3.3V
print(adcv)
# read single sample; 2.5V-5V is pass range
@@ -13,7 +13,7 @@ assert val > 1000 and val < 2000
tim = Timer(5, freq=500)
# read into bytearray
-buf = bytearray(b'\xff' * 50)
+buf = bytearray(b"\xff" * 50)
adcv.read_timed(buf, tim)
print(len(buf))
for i in buf:
@@ -21,21 +21,22 @@ for i in buf:
# read into arrays with different element sizes
import array
-arv = array.array('h', 25 * [0x7fff])
+
+arv = array.array("h", 25 * [0x7FFF])
adcv.read_timed(arv, tim)
print(len(arv))
for i in arv:
assert i > 1000 and i < 2000
-arv = array.array('i', 30 * [-1])
+arv = array.array("i", 30 * [-1])
adcv.read_timed(arv, tim)
print(len(arv))
for i in arv:
assert i > 1000 and i < 2000
# Test read_timed_multi
-arv = bytearray(b'\xff'*50)
-art = bytearray(b'\xff'*50)
+arv = bytearray(b"\xff" * 50)
+art = bytearray(b"\xff" * 50)
ADC.read_timed_multi((adcv, adct), (arv, art), tim)
for i in arv:
assert i > 60 and i < 125
@@ -43,8 +44,8 @@ for i in arv:
for i in art:
assert i > 15 and i < 200
-arv = array.array('i', 25 * [-1])
-art = array.array('i', 25 * [-1])
+arv = array.array("i", 25 * [-1])
+art = array.array("i", 25 * [-1])
ADC.read_timed_multi((adcv, adct), (arv, art), tim)
for i in arv:
assert i > 1000 and i < 2000
@@ -52,8 +53,8 @@ for i in arv:
for i in art:
assert i > 50 and i < 2000
-arv = array.array('h', 25 * [0x7fff])
-art = array.array('h', 25 * [0x7fff])
+arv = array.array("h", 25 * [0x7FFF])
+art = array.array("h", 25 * [0x7FFF])
ADC.read_timed_multi((adcv, adct), (arv, art), tim)
for i in arv:
assert i > 1000 and i < 2000
diff --git a/tests/pyb/board_pybv1x.py b/tests/pyb/board_pybv1x.py
index f4aeeb99e..ea66270b2 100644
--- a/tests/pyb/board_pybv1x.py
+++ b/tests/pyb/board_pybv1x.py
@@ -2,8 +2,8 @@
import os, pyb
-if not 'PYBv1.' in os.uname().machine:
- print('SKIP')
+if not "PYBv1." in os.uname().machine:
+ print("SKIP")
raise SystemExit
# test creating UART by id/name
diff --git a/tests/pyb/can.py b/tests/pyb/can.py
index 71de724c7..4ea29b0f6 100644
--- a/tests/pyb/can.py
+++ b/tests/pyb/can.py
@@ -1,7 +1,7 @@
try:
from pyb import CAN
except ImportError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
from array import array
@@ -40,23 +40,23 @@ print(can.info())
# Catch all filter
can.setfilter(0, CAN.MASK16, 0, (0, 0, 0, 0))
-can.send('abcd', 123, timeout=5000)
+can.send("abcd", 123, timeout=5000)
print(can.any(0), can.info())
print(can.recv(0))
-can.send('abcd', -1, timeout=5000)
+can.send("abcd", -1, timeout=5000)
print(can.recv(0))
-can.send('abcd', 0x7FF + 1, timeout=5000)
+can.send("abcd", 0x7FF + 1, timeout=5000)
print(can.recv(0))
# Test too long message
try:
- can.send('abcdefghi', 0x7FF, timeout=5000)
+ can.send("abcdefghi", 0x7FF, timeout=5000)
except ValueError:
- print('passed')
+ print("passed")
else:
- print('failed')
+ print("failed")
# Test that recv can work without allocating memory on the heap
@@ -66,22 +66,22 @@ l2 = None
micropython.heap_lock()
-can.send('', 42)
+can.send("", 42)
l2 = can.recv(0, l)
assert l is l2
print(l, len(l[3]), buf)
-can.send('1234', 42)
+can.send("1234", 42)
l2 = can.recv(0, l)
assert l is l2
print(l, len(l[3]), buf)
-can.send('01234567', 42)
+can.send("01234567", 42)
l2 = can.recv(0, l)
assert l is l2
print(l, len(l[3]), buf)
-can.send('abc', 42)
+can.send("abc", 42)
l2 = can.recv(0, l)
assert l is l2
print(l, len(l[3]), buf)
@@ -89,65 +89,65 @@ print(l, len(l[3]), buf)
micropython.heap_unlock()
# Test that recv can work with different arrays behind the memoryview
-can.send('abc', 1)
-print(bytes(can.recv(0, [0, 0, 0, memoryview(array('B', range(8)))])[3]))
-can.send('def', 1)
-print(bytes(can.recv(0, [0, 0, 0, memoryview(array('b', range(8)))])[3]))
+can.send("abc", 1)
+print(bytes(can.recv(0, [0, 0, 0, memoryview(array("B", range(8)))])[3]))
+can.send("def", 1)
+print(bytes(can.recv(0, [0, 0, 0, memoryview(array("b", range(8)))])[3]))
# Test for non-list passed as second arg to recv
-can.send('abc', 1)
+can.send("abc", 1)
try:
can.recv(0, 1)
except TypeError:
- print('TypeError')
+ print("TypeError")
# Test for too-short-list passed as second arg to recv
-can.send('abc', 1)
+can.send("abc", 1)
try:
can.recv(0, [0, 0, 0])
except ValueError:
- print('ValueError')
+ print("ValueError")
# Test for non-memoryview passed as 4th element to recv
-can.send('abc', 1)
+can.send("abc", 1)
try:
can.recv(0, [0, 0, 0, 0])
except TypeError:
- print('TypeError')
+ print("TypeError")
# Test for read-only-memoryview passed as 4th element to recv
-can.send('abc', 1)
+can.send("abc", 1)
try:
can.recv(0, [0, 0, 0, memoryview(bytes(8))])
except ValueError:
- print('ValueError')
+ print("ValueError")
# Test for bad-typecode-memoryview passed as 4th element to recv
-can.send('abc', 1)
+can.send("abc", 1)
try:
- can.recv(0, [0, 0, 0, memoryview(array('i', range(8)))])
+ can.recv(0, [0, 0, 0, memoryview(array("i", range(8)))])
except ValueError:
- print('ValueError')
+ print("ValueError")
del can
# Testing extended IDs
-can = CAN(1, CAN.LOOPBACK, extframe = True)
+can = CAN(1, CAN.LOOPBACK, extframe=True)
# Catch all filter
can.setfilter(0, CAN.MASK32, 0, (0, 0))
print(can)
try:
- can.send('abcde', 0x7FF + 1, timeout=5000)
+ can.send("abcde", 0x7FF + 1, timeout=5000)
except ValueError:
- print('failed')
+ print("failed")
else:
r = can.recv(0)
- if r[0] == 0x7FF+1 and r[3] == b'abcde':
- print('passed')
+ if r[0] == 0x7FF + 1 and r[3] == b"abcde":
+ print("passed")
else:
- print('failed, wrong data received')
+ print("failed, wrong data received")
# Test filters
for n in [0, 8, 16, 24]:
@@ -159,7 +159,7 @@ for n in [0, 8, 16, 24]:
can.clearfilter(0)
can.setfilter(0, pyb.CAN.MASK32, 0, (filter_id, filter_mask))
- can.send('ok', id_ok, timeout=3)
+ can.send("ok", id_ok, timeout=3)
if can.any(0):
msg = can.recv(0)
print((hex(filter_id), hex(filter_mask), hex(msg[0]), msg[3]))
@@ -175,57 +175,62 @@ del can
can = CAN(1, CAN.LOOPBACK)
can.setfilter(0, CAN.LIST16, 0, (1, 2, 3, 4))
can.setfilter(1, CAN.LIST16, 1, (5, 6, 7, 8))
+
+
def cb0(bus, reason):
- print('cb0')
+ print("cb0")
if reason == 0:
- print('pending')
+ print("pending")
if reason == 1:
- print('full')
+ print("full")
if reason == 2:
- print('overflow')
+ print("overflow")
+
def cb1(bus, reason):
- print('cb1')
+ print("cb1")
if reason == 0:
- print('pending')
+ print("pending")
if reason == 1:
- print('full')
+ print("full")
if reason == 2:
- print('overflow')
+ print("overflow")
+
def cb0a(bus, reason):
- print('cb0a')
+ print("cb0a")
if reason == 0:
- print('pending')
+ print("pending")
if reason == 1:
- print('full')
+ print("full")
if reason == 2:
- print('overflow')
+ print("overflow")
+
def cb1a(bus, reason):
- print('cb1a')
+ print("cb1a")
if reason == 0:
- print('pending')
+ print("pending")
if reason == 1:
- print('full')
+ print("full")
if reason == 2:
- print('overflow')
+ print("overflow")
can.rxcallback(0, cb0)
can.rxcallback(1, cb1)
-can.send('11111111',1, timeout=5000)
-can.send('22222222',2, timeout=5000)
-can.send('33333333',3, timeout=5000)
+can.send("11111111", 1, timeout=5000)
+can.send("22222222", 2, timeout=5000)
+can.send("33333333", 3, timeout=5000)
can.rxcallback(0, cb0a)
-can.send('44444444',4, timeout=5000)
+can.send("44444444", 4, timeout=5000)
-can.send('55555555',5, timeout=5000)
-can.send('66666666',6, timeout=5000)
-can.send('77777777',7, timeout=5000)
+can.send("55555555", 5, timeout=5000)
+can.send("66666666", 6, timeout=5000)
+can.send("77777777", 7, timeout=5000)
can.rxcallback(1, cb1a)
-can.send('88888888',8, timeout=5000)
+can.send("88888888", 8, timeout=5000)
print(can.recv(0))
print(can.recv(0))
@@ -234,8 +239,8 @@ print(can.recv(1))
print(can.recv(1))
print(can.recv(1))
-can.send('11111111',1, timeout=5000)
-can.send('55555555',5, timeout=5000)
+can.send("11111111", 1, timeout=5000)
+can.send("55555555", 5, timeout=5000)
print(can.recv(0))
print(can.recv(1))
@@ -249,7 +254,7 @@ can.setfilter(0, CAN.MASK16, 0, (0, 0, 0, 0))
while can.any(0):
can.recv(0)
-can.send('abcde', 1, timeout=0)
+can.send("abcde", 1, timeout=0)
print(can.any(0))
while not can.any(0):
pass
@@ -257,15 +262,15 @@ while not can.any(0):
print(can.recv(0))
try:
- can.send('abcde', 2, timeout=0)
- can.send('abcde', 3, timeout=0)
- can.send('abcde', 4, timeout=0)
- can.send('abcde', 5, timeout=0)
+ can.send("abcde", 2, timeout=0)
+ can.send("abcde", 3, timeout=0)
+ can.send("abcde", 4, timeout=0)
+ can.send("abcde", 5, timeout=0)
except OSError as e:
- if str(e) == '16':
- print('passed')
+ if str(e) == "16":
+ print("passed")
else:
- print('failed')
+ print("failed")
pyb.delay(500)
while can.any(0):
@@ -279,22 +284,22 @@ bus1.setfilter(0, CAN.LIST16, 0, (1, 2, 3, 4))
bus1.setfilter(1, CAN.LIST16, 0, (5, 6, 7, 8), rtr=(True, True, True, True))
bus1.setfilter(2, CAN.MASK16, 0, (64, 64, 32, 32), rtr=(False, True))
-bus1.send('',1,rtr=True)
+bus1.send("", 1, rtr=True)
print(bus1.any(0))
-bus1.send('',5,rtr=True)
+bus1.send("", 5, rtr=True)
print(bus1.recv(0))
-bus1.send('',6,rtr=True)
+bus1.send("", 6, rtr=True)
print(bus1.recv(0))
-bus1.send('',7,rtr=True)
+bus1.send("", 7, rtr=True)
print(bus1.recv(0))
-bus1.send('',16,rtr=True)
+bus1.send("", 16, rtr=True)
print(bus1.any(0))
-bus1.send('',32,rtr=True)
+bus1.send("", 32, rtr=True)
print(bus1.recv(0))
# test HAL error, timeout
can = pyb.CAN(1, pyb.CAN.NORMAL)
try:
- can.send('1', 1, timeout=50)
+ can.send("1", 1, timeout=50)
except OSError as e:
print(repr(e))
diff --git a/tests/pyb/can2.py b/tests/pyb/can2.py
index 440ae4925..46237ad84 100644
--- a/tests/pyb/can2.py
+++ b/tests/pyb/can2.py
@@ -1,8 +1,9 @@
try:
from pyb import CAN
+
CAN(2)
except (ImportError, ValueError):
- print('SKIP')
+ print("SKIP")
raise SystemExit
# Testing rtr messages
@@ -14,11 +15,11 @@ bus2.setfilter(1, CAN.LIST32, 0, (3, 4), rtr=(True, False))
bus2.setfilter(2, CAN.MASK32, 0, (16, 16), rtr=(False,))
bus2.setfilter(2, CAN.MASK32, 0, (32, 32), rtr=(True,))
-bus2.send('',1,rtr=True)
+bus2.send("", 1, rtr=True)
print(bus2.recv(0))
-bus2.send('',2,rtr=True)
+bus2.send("", 2, rtr=True)
print(bus2.recv(0))
-bus2.send('',3,rtr=True)
+bus2.send("", 3, rtr=True)
print(bus2.recv(0))
-bus2.send('',4,rtr=True)
+bus2.send("", 4, rtr=True)
print(bus2.any(0))
diff --git a/tests/pyb/dac.py b/tests/pyb/dac.py
index ca68ec709..506cf272b 100644
--- a/tests/pyb/dac.py
+++ b/tests/pyb/dac.py
@@ -1,7 +1,7 @@
import pyb
-if not hasattr(pyb, 'DAC'):
- print('SKIP')
+if not hasattr(pyb, "DAC"):
+ print("SKIP")
raise SystemExit
dac = pyb.DAC(1)
diff --git a/tests/pyb/extint.py b/tests/pyb/extint.py
index 8b6bc5651..551060002 100644
--- a/tests/pyb/extint.py
+++ b/tests/pyb/extint.py
@@ -1,7 +1,7 @@
import pyb
# test basic functionality
-ext = pyb.ExtInt('X5', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l:print('line:', l))
+ext = pyb.ExtInt("X5", pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_DOWN, lambda l: print("line:", l))
ext.disable()
ext.enable()
print(ext.line())
diff --git a/tests/pyb/i2c_accel.py b/tests/pyb/i2c_accel.py
index e42cba178..8c74fa60e 100644
--- a/tests/pyb/i2c_accel.py
+++ b/tests/pyb/i2c_accel.py
@@ -3,13 +3,13 @@
import pyb
from pyb import I2C
-if not hasattr(pyb, 'Accel'):
- print('SKIP')
+if not hasattr(pyb, "Accel"):
+ print("SKIP")
raise SystemExit
accel_addr = 76
-pyb.Accel() # this will init the MMA for us
+pyb.Accel() # this will init the MMA for us
i2c = I2C(1, I2C.MASTER, baudrate=400000)
diff --git a/tests/pyb/i2c_error.py b/tests/pyb/i2c_error.py
index e0f721179..b17a26325 100644
--- a/tests/pyb/i2c_error.py
+++ b/tests/pyb/i2c_error.py
@@ -3,8 +3,8 @@
import pyb
from pyb import I2C
-if not hasattr(pyb, 'Accel'):
- print('SKIP')
+if not hasattr(pyb, "Accel"):
+ print("SKIP")
raise SystemExit
# init accelerometer
@@ -15,40 +15,40 @@ i2c = I2C(1, I2C.MASTER, dma=True)
# test polling mem_read
pyb.disable_irq()
-i2c.mem_read(1, 76, 0x0a) # should succeed
+i2c.mem_read(1, 76, 0x0A) # should succeed
pyb.enable_irq()
try:
pyb.disable_irq()
- i2c.mem_read(1, 77, 0x0a) # should fail
+ i2c.mem_read(1, 77, 0x0A) # should fail
except OSError as e:
pyb.enable_irq()
print(repr(e))
-i2c.mem_read(1, 76, 0x0a) # should succeed
+i2c.mem_read(1, 76, 0x0A) # should succeed
# test polling mem_write
pyb.disable_irq()
-i2c.mem_write(1, 76, 0x0a) # should succeed
+i2c.mem_write(1, 76, 0x0A) # should succeed
pyb.enable_irq()
try:
pyb.disable_irq()
- i2c.mem_write(1, 77, 0x0a) # should fail
+ i2c.mem_write(1, 77, 0x0A) # should fail
except OSError as e:
pyb.enable_irq()
print(repr(e))
-i2c.mem_write(1, 76, 0x0a) # should succeed
+i2c.mem_write(1, 76, 0x0A) # should succeed
# test DMA mem_read
-i2c.mem_read(1, 76, 0x0a) # should succeed
+i2c.mem_read(1, 76, 0x0A) # should succeed
try:
- i2c.mem_read(1, 77, 0x0a) # should fail
+ i2c.mem_read(1, 77, 0x0A) # should fail
except OSError as e:
print(repr(e))
-i2c.mem_read(1, 76, 0x0a) # should succeed
+i2c.mem_read(1, 76, 0x0A) # should succeed
# test DMA mem_write
-i2c.mem_write(1, 76, 0x0a) # should succeed
+i2c.mem_write(1, 76, 0x0A) # should succeed
try:
- i2c.mem_write(1, 77, 0x0a) # should fail
+ i2c.mem_write(1, 77, 0x0A) # should fail
except OSError as e:
print(repr(e))
-i2c.mem_write(1, 76, 0x0a) # should succeed
+i2c.mem_write(1, 76, 0x0A) # should succeed
diff --git a/tests/pyb/irq.py b/tests/pyb/irq.py
index 42d276568..04e70a7b7 100644
--- a/tests/pyb/irq.py
+++ b/tests/pyb/irq.py
@@ -1,10 +1,11 @@
import pyb
+
def test_irq():
# test basic disable/enable
i1 = pyb.disable_irq()
print(i1)
- pyb.enable_irq() # by default should enable IRQ
+ pyb.enable_irq() # by default should enable IRQ
# check that interrupts are enabled by waiting for ticks
pyb.delay(10)
@@ -19,4 +20,5 @@ def test_irq():
# check that interrupts are enabled by waiting for ticks
pyb.delay(10)
+
test_irq()
diff --git a/tests/pyb/led.py b/tests/pyb/led.py
index 38e9993cb..1702c189e 100644
--- a/tests/pyb/led.py
+++ b/tests/pyb/led.py
@@ -1,14 +1,14 @@
import os, pyb
machine = os.uname().machine
-if 'PYBv1.' in machine or 'PYBLITEv1.' in machine:
+if "PYBv1." in machine or "PYBLITEv1." in machine:
leds = [pyb.LED(i) for i in range(1, 5)]
pwm_leds = leds[2:]
-elif 'PYBD' in machine:
+elif "PYBD" in machine:
leds = [pyb.LED(i) for i in range(1, 4)]
pwm_leds = []
else:
- print('SKIP')
+ print("SKIP")
raise SystemExit
# test printing
diff --git a/tests/pyb/modtime.py b/tests/pyb/modtime.py
index d45440a63..396f83266 100644
--- a/tests/pyb/modtime.py
+++ b/tests/pyb/modtime.py
@@ -2,12 +2,14 @@ import time
DAYS_PER_MONTH = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
+
def is_leap(year):
return (year % 4) == 0
+
def test():
seconds = 0
- wday = 5 # Jan 1, 2000 was a Saturday
+ wday = 5 # Jan 1, 2000 was a Saturday
for year in range(2000, 2034):
print("Testing %d" % year)
yday = 1
@@ -19,32 +21,48 @@ def test():
for day in range(1, DAYS_PER_MONTH[month] + 1):
secs = time.mktime((year, month, day, 0, 0, 0, 0, 0))
if secs != seconds:
- print("mktime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds))
+ print(
+ "mktime failed for %d-%02d-%02d got %d expected %d"
+ % (year, month, day, secs, seconds)
+ )
tuple = time.localtime(seconds)
secs = time.mktime(tuple)
if secs != seconds:
- print("localtime failed for %d-%02d-%02d got %d expected %d" % (year, month, day, secs, seconds))
+ print(
+ "localtime failed for %d-%02d-%02d got %d expected %d"
+ % (year, month, day, secs, seconds)
+ )
return
seconds += 86400
if yday != tuple[7]:
- print("locatime for %d-%02d-%02d got yday %d, expecting %d" % (year, month, day, tuple[7], yday))
+ print(
+ "locatime for %d-%02d-%02d got yday %d, expecting %d"
+ % (year, month, day, tuple[7], yday)
+ )
return
if wday != tuple[6]:
- print("locatime for %d-%02d-%02d got wday %d, expecting %d" % (year, month, day, tuple[6], wday))
+ print(
+ "locatime for %d-%02d-%02d got wday %d, expecting %d"
+ % (year, month, day, tuple[6], wday)
+ )
return
yday += 1
wday = (wday + 1) % 7
+
def spot_test(seconds, expected_time):
actual_time = time.localtime(seconds)
for i in range(len(actual_time)):
if actual_time[i] != expected_time[i]:
- print("time.localtime(", seconds, ") returned", actual_time, "expecting", expected_time)
+ print(
+ "time.localtime(", seconds, ") returned", actual_time, "expecting", expected_time
+ )
return
print("time.localtime(", seconds, ") returned", actual_time, "(pass)")
test()
+# fmt: off
spot_test( 0, (2000, 1, 1, 0, 0, 0, 5, 1))
spot_test( 1, (2000, 1, 1, 0, 0, 1, 5, 1))
spot_test( 59, (2000, 1, 1, 0, 0, 59, 5, 1))
@@ -57,3 +75,4 @@ spot_test( -940984933, (1970, 3, 7, 23, 17, 47, 5, 66))
spot_test(-1072915199, (1966, 1, 1, 0, 0, 1, 5, 1))
spot_test(-1072915200, (1966, 1, 1, 0, 0, 0, 5, 1))
spot_test(-1072915201, (1965, 12, 31, 23, 59, 59, 4, 365))
+# fmt: on
diff --git a/tests/pyb/pin.py b/tests/pyb/pin.py
index ea42cc206..3d2bef97e 100644
--- a/tests/pyb/pin.py
+++ b/tests/pyb/pin.py
@@ -1,14 +1,14 @@
from pyb import Pin
-p = Pin('X8', Pin.IN)
+p = Pin("X8", Pin.IN)
print(p)
print(p.name())
print(p.pin())
print(p.port())
-p = Pin('X8', Pin.IN, Pin.PULL_UP)
-p = Pin('X8', Pin.IN, pull=Pin.PULL_UP)
-p = Pin('X8', mode=Pin.IN, pull=Pin.PULL_UP)
+p = Pin("X8", Pin.IN, Pin.PULL_UP)
+p = Pin("X8", Pin.IN, pull=Pin.PULL_UP)
+p = Pin("X8", mode=Pin.IN, pull=Pin.PULL_UP)
print(p)
print(p.value())
diff --git a/tests/pyb/pyb1.py b/tests/pyb/pyb1.py
index 443722ca8..e9626ecf4 100644
--- a/tests/pyb/pyb1.py
+++ b/tests/pyb/pyb1.py
@@ -10,7 +10,7 @@ pyb.delay(1)
start = pyb.millis()
pyb.delay(17)
-print((pyb.millis() - start) // 5) # should print 3
+print((pyb.millis() - start) // 5) # should print 3
# test udelay
@@ -20,7 +20,7 @@ pyb.udelay(1)
start = pyb.millis()
pyb.udelay(17000)
-print((pyb.millis() - start) // 5) # should print 3
+print((pyb.millis() - start) // 5) # should print 3
# other
diff --git a/tests/pyb/pyb_f405.py b/tests/pyb/pyb_f405.py
index f49dd1bc7..243381056 100644
--- a/tests/pyb/pyb_f405.py
+++ b/tests/pyb/pyb_f405.py
@@ -2,8 +2,8 @@
import os, pyb
-if not 'STM32F405' in os.uname().machine:
- print('SKIP')
+if not "STM32F405" in os.uname().machine:
+ print("SKIP")
raise SystemExit
print(pyb.freq())
@@ -15,4 +15,3 @@ try:
i2c.recv(1, 1)
except OSError as e:
print(repr(e))
-
diff --git a/tests/pyb/pyb_f411.py b/tests/pyb/pyb_f411.py
index 50de30282..58d5fa2d4 100644
--- a/tests/pyb/pyb_f411.py
+++ b/tests/pyb/pyb_f411.py
@@ -2,8 +2,8 @@
import os, pyb
-if not 'STM32F411' in os.uname().machine:
- print('SKIP')
+if not "STM32F411" in os.uname().machine:
+ print("SKIP")
raise SystemExit
print(pyb.freq())
diff --git a/tests/pyb/rtc.py b/tests/pyb/rtc.py
index 844526b4b..41b52f260 100644
--- a/tests/pyb/rtc.py
+++ b/tests/pyb/rtc.py
@@ -10,10 +10,12 @@ rtc.datetime((2014, 1, 1, 1, 0, 0, 0, 0))
pyb.delay(1002)
print(rtc.datetime()[:7])
+
def set_and_print(datetime):
rtc.datetime(datetime)
print(rtc.datetime()[:7])
+
# make sure that setting works correctly
set_and_print((2000, 1, 1, 1, 0, 0, 0, 0))
set_and_print((2000, 1, 31, 1, 0, 0, 0, 0))
@@ -34,10 +36,12 @@ set_and_print((2099, 12, 31, 7, 23, 59, 59, 0))
# save existing calibration value:
cal_tmp = rtc.calibration()
+
def set_and_print_calib(cal):
rtc.calibration(cal)
print(rtc.calibration())
+
set_and_print_calib(512)
set_and_print_calib(511)
set_and_print_calib(345)
@@ -56,12 +60,13 @@ def set_and_print_wakeup(ms):
try:
rtc.wakeup(ms)
wucksel = stm.mem32[stm.RTC + stm.RTC_CR] & 7
- wut = stm.mem32[stm.RTC + stm.RTC_WUTR] & 0xffff
+ wut = stm.mem32[stm.RTC + stm.RTC_WUTR] & 0xFFFF
except ValueError:
wucksel = -1
wut = -1
print((wucksel, wut))
+
set_and_print_wakeup(0)
set_and_print_wakeup(1)
set_and_print_wakeup(4000)
@@ -72,8 +77,8 @@ set_and_print_wakeup(16000)
set_and_print_wakeup(16001)
set_and_print_wakeup(32000)
set_and_print_wakeup(32001)
-set_and_print_wakeup(0x10000*1000)
-set_and_print_wakeup(0x10001*1000)
-set_and_print_wakeup(0x1ffff*1000)
-set_and_print_wakeup(0x20000*1000)
-set_and_print_wakeup(0x20001*1000) # exception
+set_and_print_wakeup(0x10000 * 1000)
+set_and_print_wakeup(0x10001 * 1000)
+set_and_print_wakeup(0x1FFFF * 1000)
+set_and_print_wakeup(0x20000 * 1000)
+set_and_print_wakeup(0x20001 * 1000) # exception
diff --git a/tests/pyb/spi.py b/tests/pyb/spi.py
index 577737420..73d39e724 100644
--- a/tests/pyb/spi.py
+++ b/tests/pyb/spi.py
@@ -14,7 +14,7 @@ print(spi)
spi = SPI(1, SPI.MASTER)
spi = SPI(1, SPI.MASTER, baudrate=500000)
spi = SPI(1, SPI.MASTER, 500000, polarity=1, phase=0, bits=8, firstbit=SPI.MSB, ti=False, crc=None)
-print(str(spi)[:28], str(spi)[49:]) # don't print baudrate/prescaler
+print(str(spi)[:28], str(spi)[49:]) # don't print baudrate/prescaler
spi.init(SPI.SLAVE, phase=1)
print(spi)
diff --git a/tests/pyb/timer.py b/tests/pyb/timer.py
index 0e24ff4ad..251a06c08 100644
--- a/tests/pyb/timer.py
+++ b/tests/pyb/timer.py
@@ -16,4 +16,4 @@ print(tim.period())
tim = Timer(2, freq=100)
print(tim.freq())
tim.freq(0.001)
-print('{:.3f}'.format(tim.freq()))
+print("{:.3f}".format(tim.freq()))
diff --git a/tests/pyb/timer_callback.py b/tests/pyb/timer_callback.py
index 864dd479e..51242fba4 100644
--- a/tests/pyb/timer_callback.py
+++ b/tests/pyb/timer_callback.py
@@ -8,19 +8,24 @@ def cb1(t):
print("cb1")
t.callback(None)
+
# callback function that disables the timer when called
def cb2(t):
print("cb2")
t.deinit()
+
# callback where cb4 closes over cb3.y
def cb3(x):
y = x
+
def cb4(t):
print("cb4", y)
t.callback(None)
+
return cb4
+
# create a timer with a callback, using callback(None) to stop
tim = Timer(1, freq=100, callback=cb1)
pyb.delay(5)
diff --git a/tests/pyb/uart.py b/tests/pyb/uart.py
index 9dcb1f75c..53b0ea6ad 100644
--- a/tests/pyb/uart.py
+++ b/tests/pyb/uart.py
@@ -17,8 +17,8 @@ uart.init(2400)
print(uart)
print(uart.any())
-print(uart.write('123'))
-print(uart.write(b'abcd'))
+print(uart.write("123"))
+print(uart.write(b"abcd"))
print(uart.writechar(1))
# make sure this method exists
@@ -26,8 +26,8 @@ uart.sendbreak()
# non-blocking mode
uart = UART(1, 9600, timeout=0)
-print(uart.write(b'1'))
-print(uart.write(b'abcd'))
+print(uart.write(b"1"))
+print(uart.write(b"abcd"))
print(uart.writechar(1))
print(uart.read(100))