aboutsummaryrefslogtreecommitdiff
path: root/tests/extmod
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/extmod
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/extmod')
-rw-r--r--tests/extmod/btree1.py2
-rw-r--r--tests/extmod/framebuf1.py26
-rw-r--r--tests/extmod/framebuf16.py26
-rw-r--r--tests/extmod/framebuf2.py4
-rw-r--r--tests/extmod/framebuf4.py38
-rw-r--r--tests/extmod/framebuf8.py6
-rw-r--r--tests/extmod/framebuf_subclass.py9
-rw-r--r--tests/extmod/machine_pinbase.py2
-rw-r--r--tests/extmod/machine_pulse.py2
-rw-r--r--tests/extmod/machine_signal.py1
-rw-r--r--tests/extmod/machine_timer.py5
-rw-r--r--tests/extmod/time_ms_us.py1
-rw-r--r--tests/extmod/ubinascii_a2b_base64.py42
-rw-r--r--tests/extmod/ubinascii_b2a_base64.py24
-rw-r--r--tests/extmod/ubinascii_crc32.py12
-rw-r--r--tests/extmod/ubinascii_hexlify.py8
-rw-r--r--tests/extmod/ubinascii_micropython.py4
-rw-r--r--tests/extmod/ubinascii_unhexlify.py16
-rw-r--r--tests/extmod/ucryptolib_aes128_cbc.py1
-rw-r--r--tests/extmod/ucryptolib_aes128_ctr.py6
-rw-r--r--tests/extmod/ucryptolib_aes128_ecb.py1
-rw-r--r--tests/extmod/ucryptolib_aes128_ecb_enc.py1
-rw-r--r--tests/extmod/ucryptolib_aes256_cbc.py1
-rw-r--r--tests/extmod/ucryptolib_aes256_ecb.py1
-rw-r--r--tests/extmod/uctypes_32bit_intbig.py12
-rw-r--r--tests/extmod/uctypes_array_assign_le.py7
-rw-r--r--tests/extmod/uctypes_array_assign_native_le.py5
-rw-r--r--tests/extmod/uctypes_array_assign_native_le_intbig.py5
-rw-r--r--tests/extmod/uctypes_byteat.py6
-rw-r--r--tests/extmod/uctypes_error.py24
-rw-r--r--tests/extmod/uctypes_le.py19
-rw-r--r--tests/extmod/uctypes_le_float.py8
-rw-r--r--tests/extmod/uctypes_native_float.py4
-rw-r--r--tests/extmod/uctypes_native_le.py20
-rw-r--r--tests/extmod/uctypes_print.py4
-rw-r--r--tests/extmod/uctypes_ptr_le.py3
-rw-r--r--tests/extmod/uctypes_ptr_native_le.py3
-rw-r--r--tests/extmod/uctypes_sizeof.py11
-rw-r--r--tests/extmod/uctypes_sizeof_float.py4
-rw-r--r--tests/extmod/uctypes_sizeof_native.py5
-rw-r--r--tests/extmod/uctypes_sizeof_od.py29
-rw-r--r--tests/extmod/uhashlib_md5.py4
-rw-r--r--tests/extmod/uhashlib_sha1.py4
-rw-r--r--tests/extmod/uhashlib_sha256.py14
-rw-r--r--tests/extmod/uheapq1.py4
-rw-r--r--tests/extmod/ujson_dump.py8
-rw-r--r--tests/extmod/ujson_dump_iobase.py13
-rw-r--r--tests/extmod/ujson_dumps.py10
-rw-r--r--tests/extmod/ujson_dumps_extra.py2
-rw-r--r--tests/extmod/ujson_dumps_float.py2
-rw-r--r--tests/extmod/ujson_load.py4
-rw-r--r--tests/extmod/ujson_loads.py44
-rw-r--r--tests/extmod/ujson_loads_bytes.py4
-rw-r--r--tests/extmod/ujson_loads_float.py16
-rw-r--r--tests/extmod/urandom_basic.py2
-rw-r--r--tests/extmod/urandom_extra.py20
-rw-r--r--tests/extmod/urandom_extra_float.py6
-rw-r--r--tests/extmod/ure1.py61
-rw-r--r--tests/extmod/ure_debug.py3
-rw-r--r--tests/extmod/ure_error.py20
-rw-r--r--tests/extmod/ure_group.py12
-rw-r--r--tests/extmod/ure_groups.py12
-rw-r--r--tests/extmod/ure_namedclass.py12
-rw-r--r--tests/extmod/ure_span.py13
-rw-r--r--tests/extmod/ure_split_notimpl.py4
-rw-r--r--tests/extmod/ure_sub.py37
-rw-r--r--tests/extmod/ure_sub_unmatched.py6
-rw-r--r--tests/extmod/uselect_poll_basic.py1
-rw-r--r--tests/extmod/uselect_poll_udp.py4
-rw-r--r--tests/extmod/usocket_udp_nonblock.py4
-rw-r--r--tests/extmod/ussl_basic.py20
-rw-r--r--tests/extmod/ussl_keycert.py6
-rw-r--r--tests/extmod/utimeq1.py14
-rw-r--r--tests/extmod/uzlib_decompio.py6
-rw-r--r--tests/extmod/uzlib_decompio_gz.py26
-rw-r--r--tests/extmod/uzlib_decompress.py37
-rw-r--r--tests/extmod/vfs_basic.py127
-rw-r--r--tests/extmod/vfs_blockdev.py20
-rw-r--r--tests/extmod/vfs_fat_fileio1.py26
-rw-r--r--tests/extmod/vfs_fat_fileio2.py12
-rw-r--r--tests/extmod/vfs_fat_finaliser.py23
-rw-r--r--tests/extmod/vfs_fat_more.py73
-rw-r--r--tests/extmod/vfs_fat_oldproto.py5
-rw-r--r--tests/extmod/vfs_fat_ramdisk.py10
-rw-r--r--tests/extmod/vfs_fat_ramdisklarge.py14
-rw-r--r--tests/extmod/vfs_lfs.py58
-rw-r--r--tests/extmod/vfs_lfs_corrupt.py54
-rw-r--r--tests/extmod/vfs_lfs_error.py66
-rw-r--r--tests/extmod/vfs_lfs_file.py52
-rw-r--r--tests/extmod/vfs_lfs_mount.py25
-rw-r--r--tests/extmod/vfs_userfs.py29
-rw-r--r--tests/extmod/websocket_basic.py16
92 files changed, 802 insertions, 671 deletions
diff --git a/tests/extmod/btree1.py b/tests/extmod/btree1.py
index 59638ef0a..4890d92b4 100644
--- a/tests/extmod/btree1.py
+++ b/tests/extmod/btree1.py
@@ -6,7 +6,7 @@ except ImportError:
print("SKIP")
raise SystemExit
-#f = open("_test.db", "w+b")
+# f = open("_test.db", "w+b")
f = uio.BytesIO()
db = btree.open(f, pagesize=512)
diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py
index 2c1366522..c8e013226 100644
--- a/tests/extmod/framebuf1.py
+++ b/tests/extmod/framebuf1.py
@@ -8,9 +8,11 @@ w = 5
h = 16
size = w * h // 8
buf = bytearray(size)
-maps = {framebuf.MONO_VLSB : 'MONO_VLSB',
- framebuf.MONO_HLSB : 'MONO_HLSB',
- framebuf.MONO_HMSB : 'MONO_HMSB'}
+maps = {
+ framebuf.MONO_VLSB: "MONO_VLSB",
+ framebuf.MONO_HLSB: "MONO_HLSB",
+ framebuf.MONO_HMSB: "MONO_HMSB",
+}
for mapping in maps.keys():
for x in range(size):
@@ -43,33 +45,33 @@ for mapping in maps.keys():
# hline
fbuf.fill(0)
fbuf.hline(0, 1, w, 1)
- print('hline', buf)
+ print("hline", buf)
# vline
fbuf.fill(0)
fbuf.vline(1, 0, h, 1)
- print('vline', buf)
+ print("vline", buf)
# rect
fbuf.fill(0)
fbuf.rect(1, 1, 3, 3, 1)
- print('rect', buf)
+ print("rect", buf)
- #fill rect
+ # fill rect
fbuf.fill(0)
- fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
+ fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
fbuf.fill_rect(1, 1, 3, 3, 1)
- print('fill_rect', buf)
+ print("fill_rect", buf)
# line
fbuf.fill(0)
fbuf.line(1, 1, 3, 3, 1)
- print('line', buf)
+ print("line", buf)
# line steep negative gradient
fbuf.fill(0)
fbuf.line(3, 3, 2, 1, 1)
- print('line', buf)
+ print("line", buf)
# scroll
fbuf.fill(0)
@@ -89,7 +91,7 @@ for mapping in maps.keys():
fbuf.fill(0)
fbuf.text("hello", 0, 0, 1)
print(buf)
- fbuf.text("hello", 0, 0, 0) # clear
+ fbuf.text("hello", 0, 0, 0) # clear
print(buf)
# char out of font range set to chr(127)
diff --git a/tests/extmod/framebuf16.py b/tests/extmod/framebuf16.py
index fe81f7f93..e658f1345 100644
--- a/tests/extmod/framebuf16.py
+++ b/tests/extmod/framebuf16.py
@@ -4,28 +4,30 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def printbuf():
print("--8<--")
for y in range(h):
- print(buf[y * w * 2:(y + 1) * w * 2])
+ print(buf[y * w * 2 : (y + 1) * w * 2])
print("-->8--")
+
w = 4
h = 5
buf = bytearray(w * h * 2)
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.RGB565)
# fill
-fbuf.fill(0xffff)
+fbuf.fill(0xFFFF)
printbuf()
fbuf.fill(0x0000)
printbuf()
# put pixel
-fbuf.pixel(0, 0, 0xeeee)
-fbuf.pixel(3, 0, 0xee00)
-fbuf.pixel(0, 4, 0x00ee)
-fbuf.pixel(3, 4, 0x0ee0)
+fbuf.pixel(0, 0, 0xEEEE)
+fbuf.pixel(3, 0, 0xEE00)
+fbuf.pixel(0, 4, 0x00EE)
+fbuf.pixel(3, 4, 0x0EE0)
printbuf()
# get pixel
@@ -33,7 +35,7 @@ print(fbuf.pixel(0, 4), fbuf.pixel(1, 1))
# scroll
fbuf.fill(0x0000)
-fbuf.pixel(2, 2, 0xffff)
+fbuf.pixel(2, 2, 0xFFFF)
printbuf()
fbuf.scroll(0, 1)
printbuf()
@@ -48,11 +50,11 @@ buf2 = bytearray(w2 * h2 * 2)
fbuf2 = framebuf.FrameBuffer(buf2, w2, h2, framebuf.RGB565)
fbuf2.fill(0x0000)
-fbuf2.pixel(0, 0, 0x0ee0)
-fbuf2.pixel(0, 2, 0xee00)
-fbuf2.pixel(1, 0, 0x00ee)
-fbuf2.pixel(1, 2, 0xe00e)
-fbuf.fill(0xffff)
+fbuf2.pixel(0, 0, 0x0EE0)
+fbuf2.pixel(0, 2, 0xEE00)
+fbuf2.pixel(1, 0, 0x00EE)
+fbuf2.pixel(1, 2, 0xE00E)
+fbuf.fill(0xFFFF)
fbuf.blit(fbuf2, 3, 3, 0x0000)
fbuf.blit(fbuf2, -1, -1, 0x0000)
fbuf.blit(fbuf2, 16, 16, 0x0000)
diff --git a/tests/extmod/framebuf2.py b/tests/extmod/framebuf2.py
index a313170eb..097057fe9 100644
--- a/tests/extmod/framebuf2.py
+++ b/tests/extmod/framebuf2.py
@@ -4,14 +4,16 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def printbuf():
print("--8<--")
for y in range(h):
for x in range(w):
- print('%u' % ((buf[(x + y * w) // 4] >> ((x & 3) << 1)) & 3), end='')
+ print("%u" % ((buf[(x + y * w) // 4] >> ((x & 3) << 1)) & 3), end="")
print()
print("-->8--")
+
w = 8
h = 5
buf = bytearray(w * h // 4)
diff --git a/tests/extmod/framebuf4.py b/tests/extmod/framebuf4.py
index 8358fa55b..56593ee15 100644
--- a/tests/extmod/framebuf4.py
+++ b/tests/extmod/framebuf4.py
@@ -4,50 +4,52 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def printbuf():
print("--8<--")
for y in range(h):
- print(buf[y * w // 2:(y + 1) * w // 2])
+ print(buf[y * w // 2 : (y + 1) * w // 2])
print("-->8--")
+
w = 16
h = 8
buf = bytearray(w * h // 2)
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB)
# fill
-fbuf.fill(0x0f)
+fbuf.fill(0x0F)
printbuf()
-fbuf.fill(0xa0)
+fbuf.fill(0xA0)
printbuf()
# put pixel
fbuf.pixel(0, 0, 0x01)
printbuf()
-fbuf.pixel(w-1, 0, 0x02)
+fbuf.pixel(w - 1, 0, 0x02)
printbuf()
-fbuf.pixel(w-1, h-1, 0x03)
+fbuf.pixel(w - 1, h - 1, 0x03)
printbuf()
-fbuf.pixel(0, h-1, 0x04)
+fbuf.pixel(0, h - 1, 0x04)
printbuf()
# get pixel
-print(fbuf.pixel(0, 0), fbuf.pixel(w-1, 0), fbuf.pixel(w-1, h-1), fbuf.pixel(0, h-1))
-print(fbuf.pixel(1, 0), fbuf.pixel(w-2, 0), fbuf.pixel(w-2, h-1), fbuf.pixel(1, h-1))
+print(fbuf.pixel(0, 0), fbuf.pixel(w - 1, 0), fbuf.pixel(w - 1, h - 1), fbuf.pixel(0, h - 1))
+print(fbuf.pixel(1, 0), fbuf.pixel(w - 2, 0), fbuf.pixel(w - 2, h - 1), fbuf.pixel(1, h - 1))
# fill rect
-fbuf.fill_rect(0, 0, w, h, 0x0f)
+fbuf.fill_rect(0, 0, w, h, 0x0F)
printbuf()
-fbuf.fill_rect(0, 0, w, h, 0xf0)
-fbuf.fill_rect(1, 0, w//2+1, 1, 0xf1)
+fbuf.fill_rect(0, 0, w, h, 0xF0)
+fbuf.fill_rect(1, 0, w // 2 + 1, 1, 0xF1)
printbuf()
-fbuf.fill_rect(1, 0, w//2+1, 1, 0x10)
-fbuf.fill_rect(1, 0, w//2, 1, 0xf1)
+fbuf.fill_rect(1, 0, w // 2 + 1, 1, 0x10)
+fbuf.fill_rect(1, 0, w // 2, 1, 0xF1)
printbuf()
-fbuf.fill_rect(1, 0, w//2, 1, 0x10)
-fbuf.fill_rect(0, h-4, w//2+1, 4, 0xaf)
+fbuf.fill_rect(1, 0, w // 2, 1, 0x10)
+fbuf.fill_rect(0, h - 4, w // 2 + 1, 4, 0xAF)
printbuf()
-fbuf.fill_rect(0, h-4, w//2+1, 4, 0xb0)
-fbuf.fill_rect(0, h-4, w//2, 4, 0xaf)
+fbuf.fill_rect(0, h - 4, w // 2 + 1, 4, 0xB0)
+fbuf.fill_rect(0, h - 4, w // 2, 4, 0xAF)
printbuf()
-fbuf.fill_rect(0, h-4, w//2, 4, 0xb0)
+fbuf.fill_rect(0, h - 4, w // 2, 4, 0xB0)
diff --git a/tests/extmod/framebuf8.py b/tests/extmod/framebuf8.py
index b6899aae9..a3ca6fcd4 100644
--- a/tests/extmod/framebuf8.py
+++ b/tests/extmod/framebuf8.py
@@ -4,14 +4,16 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def printbuf():
print("--8<--")
for y in range(h):
for x in range(w):
- print('%02x' % buf[(x + y * w)], end='')
+ print("%02x" % buf[(x + y * w)], end="")
print()
print("-->8--")
+
w = 8
h = 5
buf = bytearray(w * h)
@@ -25,7 +27,7 @@ printbuf()
fbuf.pixel(0, 0, 0x11)
fbuf.pixel(w - 1, 0, 0x22)
fbuf.pixel(0, h - 1, 0x33)
-fbuf.pixel(w - 1, h - 1, 0xff)
+fbuf.pixel(w - 1, h - 1, 0xFF)
printbuf()
# get pixel
diff --git a/tests/extmod/framebuf_subclass.py b/tests/extmod/framebuf_subclass.py
index f44a306a3..aad5d2a1e 100644
--- a/tests/extmod/framebuf_subclass.py
+++ b/tests/extmod/framebuf_subclass.py
@@ -3,9 +3,10 @@
try:
import framebuf
except ImportError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
+
class FB(framebuf.FrameBuffer):
def __init__(self, n):
self.n = n
@@ -14,6 +15,7 @@ class FB(framebuf.FrameBuffer):
def foo(self):
self.hline(0, 2, self.n, 0x0304)
+
fb = FB(n=3)
fb.pixel(0, 0, 0x0102)
fb.foo()
@@ -31,12 +33,13 @@ print(bytes(fb2))
class NotAFrameBuf:
pass
+
try:
fb.blit(NotAFrameBuf(), 0, 0)
except TypeError:
- print('TypeError')
+ print("TypeError")
try:
fb.blit(None, 0, 0)
except TypeError:
- print('TypeError')
+ print("TypeError")
diff --git a/tests/extmod/machine_pinbase.py b/tests/extmod/machine_pinbase.py
index 45aa4d8b5..8bddd4bb7 100644
--- a/tests/extmod/machine_pinbase.py
+++ b/tests/extmod/machine_pinbase.py
@@ -10,7 +10,6 @@ except:
class MyPin(machine.PinBase):
-
def __init__(self):
print("__init__")
self.v = False
@@ -21,6 +20,7 @@ class MyPin(machine.PinBase):
self.v = not self.v
return int(self.v)
+
p = MyPin()
print(p.value())
diff --git a/tests/extmod/machine_pulse.py b/tests/extmod/machine_pulse.py
index 458fe09a1..65d15fb35 100644
--- a/tests/extmod/machine_pulse.py
+++ b/tests/extmod/machine_pulse.py
@@ -11,7 +11,6 @@ except:
class ConstPin(machine.PinBase):
-
def __init__(self, value):
self.v = value
@@ -23,7 +22,6 @@ class ConstPin(machine.PinBase):
class TogglePin(machine.PinBase):
-
def __init__(self):
self.v = 0
diff --git a/tests/extmod/machine_signal.py b/tests/extmod/machine_signal.py
index dcc0de1a5..1ffdb5643 100644
--- a/tests/extmod/machine_signal.py
+++ b/tests/extmod/machine_signal.py
@@ -11,6 +11,7 @@ except:
print("SKIP")
raise SystemExit
+
class Pin(machine.PinBase):
def __init__(self):
self.v = 0
diff --git a/tests/extmod/machine_timer.py b/tests/extmod/machine_timer.py
index b7e6a280f..c9a47c402 100644
--- a/tests/extmod/machine_timer.py
+++ b/tests/extmod/machine_timer.py
@@ -2,6 +2,7 @@
try:
import utime, umachine as machine
+
machine.Timer
except:
print("SKIP")
@@ -27,11 +28,11 @@ t2.deinit()
t.deinit()
# create one-shot timer with callback and wait for it to print (should be just once)
-t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t:print('one-shot'))
+t = machine.Timer(period=1, mode=machine.Timer.ONE_SHOT, callback=lambda t: print("one-shot"))
utime.sleep_ms(5)
t.deinit()
# create periodic timer with callback and wait for it to print
-t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t:print('periodic'))
+t = machine.Timer(period=4, mode=machine.Timer.PERIODIC, callback=lambda t: print("periodic"))
utime.sleep_ms(14)
t.deinit()
diff --git a/tests/extmod/time_ms_us.py b/tests/extmod/time_ms_us.py
index 7c915d067..ac2ed8be2 100644
--- a/tests/extmod/time_ms_us.py
+++ b/tests/extmod/time_ms_us.py
@@ -1,5 +1,6 @@
try:
import utime
+
utime.sleep_ms, utime.sleep_us, utime.ticks_diff, utime.ticks_ms, utime.ticks_us, utime.ticks_cpu
except (ImportError, AttributeError):
print("SKIP")
diff --git a/tests/extmod/ubinascii_a2b_base64.py b/tests/extmod/ubinascii_a2b_base64.py
index 05a3169f3..2630965e6 100644
--- a/tests/extmod/ubinascii_a2b_base64.py
+++ b/tests/extmod/ubinascii_a2b_base64.py
@@ -7,40 +7,40 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(binascii.a2b_base64(b''))
-print(binascii.a2b_base64(b'Zg=='))
-print(binascii.a2b_base64(b'Zm8='))
-print(binascii.a2b_base64(b'Zm9v'))
-print(binascii.a2b_base64(b'Zm9vYg=='))
-print(binascii.a2b_base64(b'Zm9vYmE='))
-print(binascii.a2b_base64(b'Zm9vYmFy'))
+print(binascii.a2b_base64(b""))
+print(binascii.a2b_base64(b"Zg=="))
+print(binascii.a2b_base64(b"Zm8="))
+print(binascii.a2b_base64(b"Zm9v"))
+print(binascii.a2b_base64(b"Zm9vYg=="))
+print(binascii.a2b_base64(b"Zm9vYmE="))
+print(binascii.a2b_base64(b"Zm9vYmFy"))
-print(binascii.a2b_base64(b'AAECAwQFBgc='))
-print(binascii.a2b_base64(b'CAkKCwwNDg8='))
-print(binascii.a2b_base64(b'f4D/'))
-print(binascii.a2b_base64(b'f4D+')) # convert '+'
-print(binascii.a2b_base64(b'MTIzNEFCQ0RhYmNk'))
+print(binascii.a2b_base64(b"AAECAwQFBgc="))
+print(binascii.a2b_base64(b"CAkKCwwNDg8="))
+print(binascii.a2b_base64(b"f4D/"))
+print(binascii.a2b_base64(b"f4D+")) # convert '+'
+print(binascii.a2b_base64(b"MTIzNEFCQ0RhYmNk"))
# Ignore invalid characters and pad sequences
-print(binascii.a2b_base64(b'Zm9v\n'))
-print(binascii.a2b_base64(b'Zm\x009v\n'))
-print(binascii.a2b_base64(b'Zm9v=='))
-print(binascii.a2b_base64(b'Zm9v==='))
-print(binascii.a2b_base64(b'Zm9v===YmFy'))
+print(binascii.a2b_base64(b"Zm9v\n"))
+print(binascii.a2b_base64(b"Zm\x009v\n"))
+print(binascii.a2b_base64(b"Zm9v=="))
+print(binascii.a2b_base64(b"Zm9v==="))
+print(binascii.a2b_base64(b"Zm9v===YmFy"))
try:
- print(binascii.a2b_base64(b'abc'))
+ print(binascii.a2b_base64(b"abc"))
except ValueError:
print("ValueError")
try:
- print(binascii.a2b_base64(b'abcde='))
+ print(binascii.a2b_base64(b"abcde="))
except ValueError:
print("ValueError")
try:
- print(binascii.a2b_base64(b'ab*d'))
+ print(binascii.a2b_base64(b"ab*d"))
except ValueError:
print("ValueError")
try:
- print(binascii.a2b_base64(b'ab=cdef='))
+ print(binascii.a2b_base64(b"ab=cdef="))
except ValueError:
print("ValueError")
diff --git a/tests/extmod/ubinascii_b2a_base64.py b/tests/extmod/ubinascii_b2a_base64.py
index f4bb69fe0..9c100f972 100644
--- a/tests/extmod/ubinascii_b2a_base64.py
+++ b/tests/extmod/ubinascii_b2a_base64.py
@@ -7,16 +7,16 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(binascii.b2a_base64(b''))
-print(binascii.b2a_base64(b'f'))
-print(binascii.b2a_base64(b'fo'))
-print(binascii.b2a_base64(b'foo'))
-print(binascii.b2a_base64(b'foob'))
-print(binascii.b2a_base64(b'fooba'))
-print(binascii.b2a_base64(b'foobar'))
+print(binascii.b2a_base64(b""))
+print(binascii.b2a_base64(b"f"))
+print(binascii.b2a_base64(b"fo"))
+print(binascii.b2a_base64(b"foo"))
+print(binascii.b2a_base64(b"foob"))
+print(binascii.b2a_base64(b"fooba"))
+print(binascii.b2a_base64(b"foobar"))
-print(binascii.b2a_base64(b'\x00\x01\x02\x03\x04\x05\x06\x07'))
-print(binascii.b2a_base64(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'))
-print(binascii.b2a_base64(b'\x7f\x80\xff'))
-print(binascii.b2a_base64(b'1234ABCDabcd'))
-print(binascii.b2a_base64(b'\x00\x00>')) # convert into '+'
+print(binascii.b2a_base64(b"\x00\x01\x02\x03\x04\x05\x06\x07"))
+print(binascii.b2a_base64(b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"))
+print(binascii.b2a_base64(b"\x7f\x80\xff"))
+print(binascii.b2a_base64(b"1234ABCDabcd"))
+print(binascii.b2a_base64(b"\x00\x00>")) # convert into '+'
diff --git a/tests/extmod/ubinascii_crc32.py b/tests/extmod/ubinascii_crc32.py
index 89664a9b3..8f5f4d9ba 100644
--- a/tests/extmod/ubinascii_crc32.py
+++ b/tests/extmod/ubinascii_crc32.py
@@ -13,12 +13,12 @@ except AttributeError:
print("SKIP")
raise SystemExit
-print(hex(binascii.crc32(b'The quick brown fox jumps over the lazy dog')))
-print(hex(binascii.crc32(b'\x00' * 32)))
-print(hex(binascii.crc32(b'\xff' * 32)))
+print(hex(binascii.crc32(b"The quick brown fox jumps over the lazy dog")))
+print(hex(binascii.crc32(b"\x00" * 32)))
+print(hex(binascii.crc32(b"\xff" * 32)))
print(hex(binascii.crc32(bytes(range(32)))))
-print(hex(binascii.crc32(b' over the lazy dog', binascii.crc32(b'The quick brown fox jumps'))))
-print(hex(binascii.crc32(b'\x00' * 16, binascii.crc32(b'\x00' * 16))))
-print(hex(binascii.crc32(b'\xff' * 16, binascii.crc32(b'\xff' * 16))))
+print(hex(binascii.crc32(b" over the lazy dog", binascii.crc32(b"The quick brown fox jumps"))))
+print(hex(binascii.crc32(b"\x00" * 16, binascii.crc32(b"\x00" * 16))))
+print(hex(binascii.crc32(b"\xff" * 16, binascii.crc32(b"\xff" * 16))))
print(hex(binascii.crc32(bytes(range(16, 32)), binascii.crc32(bytes(range(16))))))
diff --git a/tests/extmod/ubinascii_hexlify.py b/tests/extmod/ubinascii_hexlify.py
index bc9928747..2329f53ed 100644
--- a/tests/extmod/ubinascii_hexlify.py
+++ b/tests/extmod/ubinascii_hexlify.py
@@ -7,7 +7,7 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(binascii.hexlify(b'\x00\x01\x02\x03\x04\x05\x06\x07'))
-print(binascii.hexlify(b'\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f'))
-print(binascii.hexlify(b'\x7f\x80\xff'))
-print(binascii.hexlify(b'1234ABCDabcd'))
+print(binascii.hexlify(b"\x00\x01\x02\x03\x04\x05\x06\x07"))
+print(binascii.hexlify(b"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"))
+print(binascii.hexlify(b"\x7f\x80\xff"))
+print(binascii.hexlify(b"1234ABCDabcd"))
diff --git a/tests/extmod/ubinascii_micropython.py b/tests/extmod/ubinascii_micropython.py
index 77084ec9e..94e8daa55 100644
--- a/tests/extmod/ubinascii_micropython.py
+++ b/tests/extmod/ubinascii_micropython.py
@@ -8,8 +8,8 @@ except ImportError:
raise SystemExit
# two arguments supported in uPy but not CPython
-a = binascii.hexlify(b'123', ':')
+a = binascii.hexlify(b"123", ":")
print(a)
# zero length buffer
-print(binascii.hexlify(b'', b':'))
+print(binascii.hexlify(b"", b":"))
diff --git a/tests/extmod/ubinascii_unhexlify.py b/tests/extmod/ubinascii_unhexlify.py
index 865abfe3a..413eaf1b6 100644
--- a/tests/extmod/ubinascii_unhexlify.py
+++ b/tests/extmod/ubinascii_unhexlify.py
@@ -7,17 +7,17 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(binascii.unhexlify(b'0001020304050607'))
-print(binascii.unhexlify(b'08090a0b0c0d0e0f'))
-print(binascii.unhexlify(b'7f80ff'))
-print(binascii.unhexlify(b'313233344142434461626364'))
+print(binascii.unhexlify(b"0001020304050607"))
+print(binascii.unhexlify(b"08090a0b0c0d0e0f"))
+print(binascii.unhexlify(b"7f80ff"))
+print(binascii.unhexlify(b"313233344142434461626364"))
try:
- a = binascii.unhexlify(b'0') # odd buffer length
+ a = binascii.unhexlify(b"0") # odd buffer length
except ValueError:
- print('ValueError')
+ print("ValueError")
try:
- a = binascii.unhexlify(b'gg') # digit not hex
+ a = binascii.unhexlify(b"gg") # digit not hex
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/extmod/ucryptolib_aes128_cbc.py b/tests/extmod/ucryptolib_aes128_cbc.py
index 4c5ea6acb..d861d2c6b 100644
--- a/tests/extmod/ucryptolib_aes128_cbc.py
+++ b/tests/extmod/ucryptolib_aes128_cbc.py
@@ -1,5 +1,6 @@
try:
from Crypto.Cipher import AES
+
aes = AES.new
except ImportError:
try:
diff --git a/tests/extmod/ucryptolib_aes128_ctr.py b/tests/extmod/ucryptolib_aes128_ctr.py
index 5a16b4529..538d9606e 100644
--- a/tests/extmod/ucryptolib_aes128_ctr.py
+++ b/tests/extmod/ucryptolib_aes128_ctr.py
@@ -10,7 +10,7 @@ def _new(k, ctr_initial):
try:
- _new(b'x' * 16, b'x' * 16)
+ _new(b"x" * 16, b"x" * 16)
except ValueError as e:
# is CTR support disabled?
if e.args[0] == "mode":
@@ -19,9 +19,9 @@ except ValueError as e:
raise e
crypto = _new(b"1234" * 4, b"5678" * 4)
-enc = crypto.encrypt(b'a')
+enc = crypto.encrypt(b"a")
print(enc)
-enc += crypto.encrypt(b'b' * 1000)
+enc += crypto.encrypt(b"b" * 1000)
print(enc)
crypto = _new(b"1234" * 4, b"5678" * 4)
diff --git a/tests/extmod/ucryptolib_aes128_ecb.py b/tests/extmod/ucryptolib_aes128_ecb.py
index 89451b282..5c0e17998 100644
--- a/tests/extmod/ucryptolib_aes128_ecb.py
+++ b/tests/extmod/ucryptolib_aes128_ecb.py
@@ -1,5 +1,6 @@
try:
from Crypto.Cipher import AES
+
aes = AES.new
except ImportError:
try:
diff --git a/tests/extmod/ucryptolib_aes128_ecb_enc.py b/tests/extmod/ucryptolib_aes128_ecb_enc.py
index 55b676d36..1d4484b0b 100644
--- a/tests/extmod/ucryptolib_aes128_ecb_enc.py
+++ b/tests/extmod/ucryptolib_aes128_ecb_enc.py
@@ -3,6 +3,7 @@
# is optional).
try:
from Crypto.Cipher import AES
+
aes = AES.new
except ImportError:
try:
diff --git a/tests/extmod/ucryptolib_aes256_cbc.py b/tests/extmod/ucryptolib_aes256_cbc.py
index a907f26e2..c01846f19 100644
--- a/tests/extmod/ucryptolib_aes256_cbc.py
+++ b/tests/extmod/ucryptolib_aes256_cbc.py
@@ -1,5 +1,6 @@
try:
from Crypto.Cipher import AES
+
aes = AES.new
except ImportError:
try:
diff --git a/tests/extmod/ucryptolib_aes256_ecb.py b/tests/extmod/ucryptolib_aes256_ecb.py
index 326383a45..0760063c1 100644
--- a/tests/extmod/ucryptolib_aes256_ecb.py
+++ b/tests/extmod/ucryptolib_aes256_ecb.py
@@ -1,5 +1,6 @@
try:
from Crypto.Cipher import AES
+
aes = AES.new
except ImportError:
try:
diff --git a/tests/extmod/uctypes_32bit_intbig.py b/tests/extmod/uctypes_32bit_intbig.py
index 6b4d3d76c..eed36e877 100644
--- a/tests/extmod/uctypes_32bit_intbig.py
+++ b/tests/extmod/uctypes_32bit_intbig.py
@@ -10,16 +10,16 @@ buf = b"12345678abcd"
struct = uctypes.struct(
uctypes.addressof(buf),
{"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4},
- uctypes.LITTLE_ENDIAN
+ uctypes.LITTLE_ENDIAN,
)
-struct.f32 = 0x7fffffff
+struct.f32 = 0x7FFFFFFF
print(buf)
struct.f32 = 0x80000000
print(buf)
-struct.f32 = 0xff010203
+struct.f32 = 0xFF010203
print(buf)
struct.f64 = 0x80000000
@@ -34,16 +34,16 @@ buf = b"12345678abcd"
struct = uctypes.struct(
uctypes.addressof(buf),
{"f32": uctypes.UINT32 | 0, "f64": uctypes.UINT64 | 4},
- uctypes.BIG_ENDIAN
+ uctypes.BIG_ENDIAN,
)
-struct.f32 = 0x7fffffff
+struct.f32 = 0x7FFFFFFF
print(buf)
struct.f32 = 0x80000000
print(buf)
-struct.f32 = 0xff010203
+struct.f32 = 0xFF010203
print(buf)
struct.f64 = 0x80000000
diff --git a/tests/extmod/uctypes_array_assign_le.py b/tests/extmod/uctypes_array_assign_le.py
index 6afa7e0a2..d822faf7e 100644
--- a/tests/extmod/uctypes_array_assign_le.py
+++ b/tests/extmod/uctypes_array_assign_le.py
@@ -10,19 +10,17 @@ desc = {
# arr2 is array at offset 0, size 2, of structures defined recursively
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
-
# aligned
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
# unaligned
"arr6": (uctypes.ARRAY | 1, uctypes.UINT32 | 1),
-
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
- "arr8": (uctypes.ARRAY | 1, 1, {"l": uctypes.UINT32 | 0})
+ "arr8": (uctypes.ARRAY | 1, 1, {"l": uctypes.UINT32 | 0}),
}
data = bytearray(5)
-S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
+S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
# assign byte
S.arr[0] = 0x11
@@ -55,4 +53,3 @@ assert hex(S.arr6[0]) == "0xaabbccdd"
print(S.arr6[0] == S.arr8[0].l)
assert S.arr6[0] == S.arr8[0].l
-
diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py
index a538bf9ad..d4c27fc4b 100644
--- a/tests/extmod/uctypes_array_assign_native_le.py
+++ b/tests/extmod/uctypes_array_assign_native_le.py
@@ -1,4 +1,5 @@
import sys
+
try:
import uctypes
except ImportError:
@@ -15,16 +16,14 @@ desc = {
# arr2 is array at offset 0, size 2, of structures defined recursively
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
-
# aligned
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
-
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
- "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
+ "arr12": (uctypes.ARRAY | 0, uctypes.UINT64 | 1),
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
}
diff --git a/tests/extmod/uctypes_array_assign_native_le_intbig.py b/tests/extmod/uctypes_array_assign_native_le_intbig.py
index 84dfba0e2..f33c63b4e 100644
--- a/tests/extmod/uctypes_array_assign_native_le_intbig.py
+++ b/tests/extmod/uctypes_array_assign_native_le_intbig.py
@@ -1,4 +1,5 @@
import sys
+
try:
import uctypes
except ImportError:
@@ -15,16 +16,14 @@ desc = {
# arr2 is array at offset 0, size 2, of structures defined recursively
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
-
# aligned
"arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
"arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
-
"arr8": (uctypes.ARRAY | 0, uctypes.INT8 | 1),
"arr9": (uctypes.ARRAY | 0, uctypes.INT16 | 1),
"arr10": (uctypes.ARRAY | 0, uctypes.INT32 | 1),
"arr11": (uctypes.ARRAY | 0, uctypes.INT64 | 1),
- "arr12": (uctypes.ARRAY | 0, uctypes.UINT64| 1),
+ "arr12": (uctypes.ARRAY | 0, uctypes.UINT64 | 1),
"arr13": (uctypes.ARRAY | 1, 1, {"l": {}}),
}
diff --git a/tests/extmod/uctypes_byteat.py b/tests/extmod/uctypes_byteat.py
index ab2535db8..0619d31dc 100644
--- a/tests/extmod/uctypes_byteat.py
+++ b/tests/extmod/uctypes_byteat.py
@@ -4,7 +4,7 @@ except ImportError:
print("SKIP")
raise SystemExit
-data = bytearray(b'01234567')
+data = bytearray(b"01234567")
-print(uctypes.bytes_at(uctypes.addressof(data), 4))
-print(uctypes.bytearray_at(uctypes.addressof(data), 4))
+print(uctypes.bytes_at(uctypes.addressof(data), 4))
+print(uctypes.bytearray_at(uctypes.addressof(data), 4))
diff --git a/tests/extmod/uctypes_error.py b/tests/extmod/uctypes_error.py
index 68106ac78..d42956261 100644
--- a/tests/extmod/uctypes_error.py
+++ b/tests/extmod/uctypes_error.py
@@ -9,35 +9,35 @@ except ImportError:
data = bytearray(b"01234567")
# del subscr not supported
-S = uctypes.struct(uctypes.addressof(data), {})
+S = uctypes.struct(uctypes.addressof(data), {})
try:
del S[0]
except TypeError:
- print('TypeError')
+ print("TypeError")
# list is an invalid descriptor
-S = uctypes.struct(uctypes.addressof(data), [])
+S = uctypes.struct(uctypes.addressof(data), [])
try:
- S.x
+ S.x
except TypeError:
- print('TypeError')
+ print("TypeError")
# can't access attribute with invalid descriptor
-S = uctypes.struct(uctypes.addressof(data), {'x':[]})
+S = uctypes.struct(uctypes.addressof(data), {"x": []})
try:
- S.x
+ S.x
except TypeError:
- print('TypeError')
+ print("TypeError")
# can't assign to aggregate
-S = uctypes.struct(uctypes.addressof(data), {'x':(uctypes.ARRAY | 0, uctypes.INT8 | 2)})
+S = uctypes.struct(uctypes.addressof(data), {"x": (uctypes.ARRAY | 0, uctypes.INT8 | 2)})
try:
- S.x = 1
+ S.x = 1
except TypeError:
- print('TypeError')
+ print("TypeError")
# unsupported unary op
try:
hash(S)
except TypeError:
- print('TypeError')
+ print("TypeError")
diff --git a/tests/extmod/uctypes_le.py b/tests/extmod/uctypes_le.py
index 7df5ac090..23f2af982 100644
--- a/tests/extmod/uctypes_le.py
+++ b/tests/extmod/uctypes_le.py
@@ -6,20 +6,15 @@ except ImportError:
desc = {
"s0": uctypes.UINT16 | 0,
- "sub": (0, {
- "b0": uctypes.UINT8 | 0,
- "b1": uctypes.UINT8 | 1,
- }),
+ "sub": (0, {"b0": uctypes.UINT8 | 0, "b1": uctypes.UINT8 | 1,}),
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"bitf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
"bitf1": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
-
- "bf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- "bf1": uctypes.BFUINT16 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- "bf2": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "bf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "bf1": uctypes.BFUINT16 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "bf2": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
"bf3": uctypes.BFUINT16 | 0 | 12 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
-
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
}
@@ -28,10 +23,10 @@ data = bytearray(b"01")
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
-#print(S)
+# print(S)
print(hex(S.s0))
assert hex(S.s0) == "0x3130"
-#print(S.sub.b0)
+# print(S.sub.b0)
print(S.sub.b0, S.sub.b1)
assert S.sub.b0, S.sub.b1 == (0x30, 0x31)
@@ -73,7 +68,7 @@ assert bytes(data) == b"2Q"
desc2 = {
"bf8": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- "bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN
+ "bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
}
data2 = bytearray(b"0123")
diff --git a/tests/extmod/uctypes_le_float.py b/tests/extmod/uctypes_le_float.py
index 84ff2b84c..89e9a9e0a 100644
--- a/tests/extmod/uctypes_le_float.py
+++ b/tests/extmod/uctypes_le_float.py
@@ -7,7 +7,7 @@ except ImportError:
desc = {
"f32": uctypes.FLOAT32 | 0,
"f64": uctypes.FLOAT64 | 0,
- "uf64": uctypes.FLOAT64 | 2, # unaligned
+ "uf64": uctypes.FLOAT64 | 2, # unaligned
}
data = bytearray(10)
@@ -15,10 +15,10 @@ data = bytearray(10)
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
S.f32 = 12.34
-print('%.4f' % S.f32)
+print("%.4f" % S.f32)
S.f64 = 12.34
-print('%.4f' % S.f64)
+print("%.4f" % S.f64)
S.uf64 = 12.34
-print('%.4f' % S.uf64)
+print("%.4f" % S.uf64)
diff --git a/tests/extmod/uctypes_native_float.py b/tests/extmod/uctypes_native_float.py
index acef47036..e7d3ddabd 100644
--- a/tests/extmod/uctypes_native_float.py
+++ b/tests/extmod/uctypes_native_float.py
@@ -14,7 +14,7 @@ data = bytearray(8)
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
S.f32 = 12.34
-print('%.4f' % S.f32)
+print("%.4f" % S.f32)
S.f64 = 12.34
-print('%.4f' % S.f64)
+print("%.4f" % S.f64)
diff --git a/tests/extmod/uctypes_native_le.py b/tests/extmod/uctypes_native_le.py
index 8bba03b38..c161539c6 100644
--- a/tests/extmod/uctypes_native_le.py
+++ b/tests/extmod/uctypes_native_le.py
@@ -2,6 +2,7 @@
# Codepaths for packed vs native structures are different. This test only works
# on little-endian machine (no matter if 32 or 64 bit).
import sys
+
try:
import uctypes
except ImportError:
@@ -15,20 +16,15 @@ if sys.byteorder != "little":
desc = {
"s0": uctypes.UINT16 | 0,
- "sub": (0, {
- "b0": uctypes.UINT8 | 0,
- "b1": uctypes.UINT8 | 1,
- }),
+ "sub": (0, {"b0": uctypes.UINT8 | 0, "b1": uctypes.UINT8 | 1,}),
"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"bitf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
"bitf1": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 8 << uctypes.BF_LEN,
-
- "bf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- "bf1": uctypes.BFUINT16 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- "bf2": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "bf0": uctypes.BFUINT16 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "bf1": uctypes.BFUINT16 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "bf2": uctypes.BFUINT16 | 0 | 8 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
"bf3": uctypes.BFUINT16 | 0 | 12 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
-
"ptr": (uctypes.PTR | 0, uctypes.UINT8),
"ptr2": (uctypes.PTR | 0, {"b": uctypes.UINT8 | 0}),
}
@@ -37,10 +33,10 @@ data = bytearray(b"01")
S = uctypes.struct(uctypes.addressof(data), desc, uctypes.NATIVE)
-#print(S)
+# print(S)
print(hex(S.s0))
assert hex(S.s0) == "0x3130"
-#print(S.sub.b0)
+# print(S.sub.b0)
print(S.sub.b0, S.sub.b1)
assert S.sub.b0, S.sub.b1 == (0x30, 0x31)
@@ -81,7 +77,7 @@ assert bytes(data) == b"2Q"
desc2 = {
"bf8": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- "bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN
+ "bf32": uctypes.BFUINT32 | 0 | 20 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
}
data2 = bytearray(b"0123")
diff --git a/tests/extmod/uctypes_print.py b/tests/extmod/uctypes_print.py
index c310238e5..6e0018abc 100644
--- a/tests/extmod/uctypes_print.py
+++ b/tests/extmod/uctypes_print.py
@@ -16,10 +16,10 @@ desc2 = [(uctypes.ARRAY | 0, uctypes.UINT8 | 1)]
S2 = uctypes.struct(0, desc2)
print(S2)
-desc3 = ((uctypes.ARRAY | 0, uctypes.UINT8 | 1))
+desc3 = (uctypes.ARRAY | 0, uctypes.UINT8 | 1)
S3 = uctypes.struct(0, desc3)
print(S3)
-desc4 = ((uctypes.PTR | 0, uctypes.UINT8 | 1))
+desc4 = (uctypes.PTR | 0, uctypes.UINT8 | 1)
S4 = uctypes.struct(0, desc4)
print(S4)
diff --git a/tests/extmod/uctypes_ptr_le.py b/tests/extmod/uctypes_ptr_le.py
index fc625f422..5d8094ee4 100644
--- a/tests/extmod/uctypes_ptr_le.py
+++ b/tests/extmod/uctypes_ptr_le.py
@@ -1,4 +1,5 @@
import sys
+
try:
import uctypes
except ImportError:
@@ -32,6 +33,6 @@ assert S.ptr[1] == ord("1")
print(hex(S.ptr16[0]))
assert hex(S.ptr16[0]) == "0x3130"
print(S.ptr2[0].b, S.ptr2[1].b)
-print (S.ptr2[0].b, S.ptr2[1].b)
+print(S.ptr2[0].b, S.ptr2[1].b)
print(hex(S.ptr16[0]))
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
diff --git a/tests/extmod/uctypes_ptr_native_le.py b/tests/extmod/uctypes_ptr_native_le.py
index 24508b1cb..8ca4d2c55 100644
--- a/tests/extmod/uctypes_ptr_native_le.py
+++ b/tests/extmod/uctypes_ptr_native_le.py
@@ -1,4 +1,5 @@
import sys
+
try:
import uctypes
except ImportError:
@@ -30,6 +31,6 @@ assert S.ptr[1] == ord("1")
print(hex(S.ptr16[0]))
assert hex(S.ptr16[0]) == "0x3130"
print(S.ptr2[0].b, S.ptr2[1].b)
-print (S.ptr2[0].b, S.ptr2[1].b)
+print(S.ptr2[0].b, S.ptr2[1].b)
print(hex(S.ptr16[0]))
assert (S.ptr2[0].b, S.ptr2[1].b) == (48, 49)
diff --git a/tests/extmod/uctypes_sizeof.py b/tests/extmod/uctypes_sizeof.py
index e42e06c92..6e52232e3 100644
--- a/tests/extmod/uctypes_sizeof.py
+++ b/tests/extmod/uctypes_sizeof.py
@@ -11,10 +11,13 @@ desc = {
"arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
"arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
"arr4": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0, "w": uctypes.UINT16 | 1}),
- "sub": (0, {
- 'b1': uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- 'b2': uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- }),
+ "sub": (
+ 0,
+ {
+ "b1": uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "b2": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ },
+ ),
}
data = bytearray(b"01234567")
diff --git a/tests/extmod/uctypes_sizeof_float.py b/tests/extmod/uctypes_sizeof_float.py
index 1ba8871bd..351632d76 100644
--- a/tests/extmod/uctypes_sizeof_float.py
+++ b/tests/extmod/uctypes_sizeof_float.py
@@ -4,5 +4,5 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(uctypes.sizeof({'f':uctypes.FLOAT32}))
-print(uctypes.sizeof({'f':uctypes.FLOAT64}))
+print(uctypes.sizeof({"f": uctypes.FLOAT32}))
+print(uctypes.sizeof({"f": uctypes.FLOAT64}))
diff --git a/tests/extmod/uctypes_sizeof_native.py b/tests/extmod/uctypes_sizeof_native.py
index 32c740e77..352c191e0 100644
--- a/tests/extmod/uctypes_sizeof_native.py
+++ b/tests/extmod/uctypes_sizeof_native.py
@@ -28,10 +28,7 @@ S5 = {
"b": uctypes.UINT32 | 4,
"c": uctypes.UINT8 | 8,
"d": uctypes.UINT32 | 0,
- "sub": (4, {
- "b0": uctypes.UINT8 | 0,
- "b1": uctypes.UINT8 | 1,
- }),
+ "sub": (4, {"b0": uctypes.UINT8 | 0, "b1": uctypes.UINT8 | 1,}),
}
assert uctypes.sizeof(S5) == 12
diff --git a/tests/extmod/uctypes_sizeof_od.py b/tests/extmod/uctypes_sizeof_od.py
index 192ee9152..2f070095b 100644
--- a/tests/extmod/uctypes_sizeof_od.py
+++ b/tests/extmod/uctypes_sizeof_od.py
@@ -5,18 +5,23 @@ except ImportError:
print("SKIP")
raise SystemExit
-desc = OrderedDict({
- # arr is array at offset 0, of UINT8 elements, array size is 2
- "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
- # arr2 is array at offset 0, size 2, of structures defined recursively
- "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
- "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
- "arr4": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0, "w": uctypes.UINT16 | 1}),
- "sub": (0, {
- 'b1': uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- 'b2': uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
- }),
-})
+desc = OrderedDict(
+ {
+ # arr is array at offset 0, of UINT8 elements, array size is 2
+ "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
+ # arr2 is array at offset 0, size 2, of structures defined recursively
+ "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
+ "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
+ "arr4": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0, "w": uctypes.UINT16 | 1}),
+ "sub": (
+ 0,
+ {
+ "b1": uctypes.BFUINT8 | 0 | 4 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ "b2": uctypes.BFUINT8 | 0 | 0 << uctypes.BF_POS | 4 << uctypes.BF_LEN,
+ },
+ ),
+ }
+)
data = bytearray(b"01234567")
diff --git a/tests/extmod/uhashlib_md5.py b/tests/extmod/uhashlib_md5.py
index 10b6d054e..07d5f3169 100644
--- a/tests/extmod/uhashlib_md5.py
+++ b/tests/extmod/uhashlib_md5.py
@@ -16,6 +16,6 @@ except AttributeError:
print("SKIP")
raise SystemExit
-md5 = hashlib.md5(b'hello')
-md5.update(b'world')
+md5 = hashlib.md5(b"hello")
+md5.update(b"world")
print(md5.digest())
diff --git a/tests/extmod/uhashlib_sha1.py b/tests/extmod/uhashlib_sha1.py
index 4f7066899..a57312131 100644
--- a/tests/extmod/uhashlib_sha1.py
+++ b/tests/extmod/uhashlib_sha1.py
@@ -16,6 +16,6 @@ except AttributeError:
print("SKIP")
raise SystemExit
-sha1 = hashlib.sha1(b'hello')
-sha1.update(b'world')
+sha1 = hashlib.sha1(b"hello")
+sha1.update(b"world")
print(sha1.digest())
diff --git a/tests/extmod/uhashlib_sha256.py b/tests/extmod/uhashlib_sha256.py
index 676d47979..2e6df7df1 100644
--- a/tests/extmod/uhashlib_sha256.py
+++ b/tests/extmod/uhashlib_sha256.py
@@ -27,12 +27,12 @@ print(hashlib.sha256(b"\xff" * 64).digest())
print(hashlib.sha256(b"\xff" * 56).digest())
# TODO: running .digest() several times in row is not supported()
-#h = hashlib.sha256(b'123')
-#print(h.digest())
-#print(h.digest())
+# h = hashlib.sha256(b'123')
+# print(h.digest())
+# print(h.digest())
# TODO: partial digests are not supported
-#h = hashlib.sha256(b'123')
-#print(h.digest())
-#h.update(b'456')
-#print(h.digest())
+# h = hashlib.sha256(b'123')
+# print(h.digest())
+# h.update(b'456')
+# print(h.digest())
diff --git a/tests/extmod/uheapq1.py b/tests/extmod/uheapq1.py
index 7c1fe4e1e..a470bb6f7 100644
--- a/tests/extmod/uheapq1.py
+++ b/tests/extmod/uheapq1.py
@@ -17,11 +17,13 @@ try:
except TypeError:
print("TypeError")
+
def pop_and_print(h):
l = []
while h:
l.append(str(heapq.heappop(h)))
- print(' '.join(l))
+ print(" ".join(l))
+
h = []
heapq.heappush(h, 3)
diff --git a/tests/extmod/ujson_dump.py b/tests/extmod/ujson_dump.py
index b1cb4a9cb..feda8a47d 100644
--- a/tests/extmod/ujson_dump.py
+++ b/tests/extmod/ujson_dump.py
@@ -20,11 +20,11 @@ print(s.getvalue())
# dump to a small-int not allowed
try:
json.dump(123, 1)
-except (AttributeError, OSError): # CPython and uPy have different errors
- print('Exception')
+except (AttributeError, OSError): # CPython and uPy have different errors
+ print("Exception")
# dump to an object not allowed
try:
json.dump(123, {})
-except (AttributeError, OSError): # CPython and uPy have different errors
- print('Exception')
+except (AttributeError, OSError): # CPython and uPy have different errors
+ print("Exception")
diff --git a/tests/extmod/ujson_dump_iobase.py b/tests/extmod/ujson_dump_iobase.py
index 51d507cd1..7ecf23afb 100644
--- a/tests/extmod/ujson_dump_iobase.py
+++ b/tests/extmod/ujson_dump_iobase.py
@@ -7,27 +7,28 @@ except ImportError:
try:
import io, json
except ImportError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
-if not hasattr(io, 'IOBase'):
- print('SKIP')
+if not hasattr(io, "IOBase"):
+ print("SKIP")
raise SystemExit
# a user stream that only has the write method
class S(io.IOBase):
def __init__(self):
- self.buf = ''
+ self.buf = ""
+
def write(self, buf):
if type(buf) == bytearray:
# uPy passes a bytearray, CPython passes a str
- buf = str(buf, 'ascii')
+ buf = str(buf, "ascii")
self.buf += buf
return len(buf)
# dump to the user stream
s = S()
-json.dump([123, {}], s)
+json.dump([123, {}], s)
print(s.buf)
diff --git a/tests/extmod/ujson_dumps.py b/tests/extmod/ujson_dumps.py
index c33126cec..251b26875 100644
--- a/tests/extmod/ujson_dumps.py
+++ b/tests/extmod/ujson_dumps.py
@@ -11,8 +11,8 @@ print(json.dumps(False))
print(json.dumps(True))
print(json.dumps(None))
print(json.dumps(1))
-print(json.dumps('abc'))
-print(json.dumps('\x00\x01\x7e'))
+print(json.dumps("abc"))
+print(json.dumps("\x00\x01\x7e"))
print(json.dumps([]))
print(json.dumps([1]))
print(json.dumps([1, 2]))
@@ -22,10 +22,10 @@ print(json.dumps((1,)))
print(json.dumps((1, 2)))
print(json.dumps((1, (2, 3))))
print(json.dumps({}))
-print(json.dumps({"a":1}))
-print(json.dumps({"a":(2,[3,None])}))
+print(json.dumps({"a": 1}))
+print(json.dumps({"a": (2, [3, None])}))
print(json.dumps('"quoted"'))
-print(json.dumps('space\n\r\tspace'))
+print(json.dumps("space\n\r\tspace"))
print(json.dumps({None: -1}))
print(json.dumps({False: 0}))
print(json.dumps({True: 1}))
diff --git a/tests/extmod/ujson_dumps_extra.py b/tests/extmod/ujson_dumps_extra.py
index 21a388c32..f2aa7f249 100644
--- a/tests/extmod/ujson_dumps_extra.py
+++ b/tests/extmod/ujson_dumps_extra.py
@@ -6,4 +6,4 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(ujson.dumps(b'1234'))
+print(ujson.dumps(b"1234"))
diff --git a/tests/extmod/ujson_dumps_float.py b/tests/extmod/ujson_dumps_float.py
index 40adb1e26..25681d0c2 100644
--- a/tests/extmod/ujson_dumps_float.py
+++ b/tests/extmod/ujson_dumps_float.py
@@ -8,4 +8,4 @@ except ImportError:
raise SystemExit
print(json.dumps(1.2))
-print(json.dumps({1.5: 'hi'}))
+print(json.dumps({1.5: "hi"}))
diff --git a/tests/extmod/ujson_load.py b/tests/extmod/ujson_load.py
index 9725ab2dd..7cec9246b 100644
--- a/tests/extmod/ujson_load.py
+++ b/tests/extmod/ujson_load.py
@@ -9,7 +9,7 @@ except:
print("SKIP")
raise SystemExit
-print(json.load(StringIO('null')))
+print(json.load(StringIO("null")))
print(json.load(StringIO('"abc\\u0064e"')))
-print(json.load(StringIO('[false, true, 1, -2]')))
+print(json.load(StringIO("[false, true, 1, -2]")))
print(json.load(StringIO('{"a":true}')))
diff --git a/tests/extmod/ujson_loads.py b/tests/extmod/ujson_loads.py
index adba3c068..2de9cdcbc 100644
--- a/tests/extmod/ujson_loads.py
+++ b/tests/extmod/ujson_loads.py
@@ -7,23 +7,25 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def my_print(o):
if isinstance(o, dict):
- print('sorted dict', sorted(o.items()))
+ print("sorted dict", sorted(o.items()))
else:
print(o)
-my_print(json.loads('null'))
-my_print(json.loads('false'))
-my_print(json.loads('true'))
-my_print(json.loads('1'))
-my_print(json.loads('-2'))
+
+my_print(json.loads("null"))
+my_print(json.loads("false"))
+my_print(json.loads("true"))
+my_print(json.loads("1"))
+my_print(json.loads("-2"))
my_print(json.loads('"abc\\u0064e"'))
-my_print(json.loads('[]'))
-my_print(json.loads('[null]'))
-my_print(json.loads('[null,false,true]'))
-my_print(json.loads(' [ null , false , true ] '))
-my_print(json.loads('{}'))
+my_print(json.loads("[]"))
+my_print(json.loads("[null]"))
+my_print(json.loads("[null,false,true]"))
+my_print(json.loads(" [ null , false , true ] "))
+my_print(json.loads("{}"))
my_print(json.loads('{"a":true}'))
my_print(json.loads('{"a":null, "b":false, "c":true}'))
my_print(json.loads('{"a":[], "b":[1], "c":{"3":4}}'))
@@ -39,36 +41,36 @@ my_print(json.loads('{\n\t"a":[]\r\n, "b":[1], "c":{"3":4} \n\r\t\r\r\r\n}')
# loading nothing should raise exception
try:
- json.loads('')
+ json.loads("")
except ValueError:
- print('ValueError')
+ print("ValueError")
# string which is not closed
try:
my_print(json.loads('"abc'))
except ValueError:
- print('ValueError')
+ print("ValueError")
# unaccompanied closing brace
try:
- my_print(json.loads(']'))
+ my_print(json.loads("]"))
except ValueError:
- print('ValueError')
+ print("ValueError")
# unspecified object type
try:
- my_print(json.loads('a'))
+ my_print(json.loads("a"))
except ValueError:
- print('ValueError')
+ print("ValueError")
# bad property name
try:
my_print(json.loads('{{}:"abc"}'))
except ValueError:
- print('ValueError')
+ print("ValueError")
# unexpected characters after white space
try:
- my_print(json.loads('[null] a'))
+ my_print(json.loads("[null] a"))
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/extmod/ujson_loads_bytes.py b/tests/extmod/ujson_loads_bytes.py
index 507e4ca88..3ee87bbcd 100644
--- a/tests/extmod/ujson_loads_bytes.py
+++ b/tests/extmod/ujson_loads_bytes.py
@@ -9,5 +9,5 @@ except ImportError:
print("SKIP")
raise SystemExit
-print(json.loads(b'[1,2]'))
-print(json.loads(bytearray(b'[null]')))
+print(json.loads(b"[1,2]"))
+print(json.loads(bytearray(b"[null]")))
diff --git a/tests/extmod/ujson_loads_float.py b/tests/extmod/ujson_loads_float.py
index 086853a2d..842718f37 100644
--- a/tests/extmod/ujson_loads_float.py
+++ b/tests/extmod/ujson_loads_float.py
@@ -7,12 +7,14 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def my_print(o):
- print('%.3f' % o)
+ print("%.3f" % o)
+
-my_print(json.loads('1.2'))
-my_print(json.loads('1e2'))
-my_print(json.loads('-2.3'))
-my_print(json.loads('-2e3'))
-my_print(json.loads('-2e+3'))
-my_print(json.loads('-2e-3'))
+my_print(json.loads("1.2"))
+my_print(json.loads("1e2"))
+my_print(json.loads("-2.3"))
+my_print(json.loads("-2e3"))
+my_print(json.loads("-2e+3"))
+my_print(json.loads("-2e-3"))
diff --git a/tests/extmod/urandom_basic.py b/tests/extmod/urandom_basic.py
index 57e6b26cb..180197398 100644
--- a/tests/extmod/urandom_basic.py
+++ b/tests/extmod/urandom_basic.py
@@ -26,4 +26,4 @@ print(random.getrandbits(16) == r)
try:
random.getrandbits(0)
except ValueError:
- print('ValueError')
+ print("ValueError")
diff --git a/tests/extmod/urandom_extra.py b/tests/extmod/urandom_extra.py
index 0cfd9280b..78e17379d 100644
--- a/tests/extmod/urandom_extra.py
+++ b/tests/extmod/urandom_extra.py
@@ -10,10 +10,10 @@ except ImportError:
try:
random.randint
except AttributeError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
-print('randrange')
+print("randrange")
for i in range(50):
assert 0 <= random.randrange(4) < 4
assert 2 <= random.randrange(2, 6) < 6
@@ -25,27 +25,27 @@ for i in range(50):
try:
random.randrange(0)
except ValueError:
- print('ValueError')
+ print("ValueError")
# empty range
try:
random.randrange(2, 1)
except ValueError:
- print('ValueError')
+ print("ValueError")
# zero step
try:
random.randrange(2, 1, 0)
except ValueError:
- print('ValueError')
+ print("ValueError")
# empty range
try:
random.randrange(2, 1, 1)
except ValueError:
- print('ValueError')
+ print("ValueError")
-print('randint')
+print("randint")
for i in range(50):
assert 0 <= random.randint(0, 4) <= 4
assert 2 <= random.randint(2, 6) <= 6
@@ -55,9 +55,9 @@ for i in range(50):
try:
random.randint(2, 1)
except ValueError:
- print('ValueError')
+ print("ValueError")
-print('choice')
+print("choice")
lst = [1, 2, 5, 6]
for i in range(50):
assert random.choice(lst) in lst
@@ -66,4 +66,4 @@ for i in range(50):
try:
random.choice([])
except IndexError:
- print('IndexError')
+ print("IndexError")
diff --git a/tests/extmod/urandom_extra_float.py b/tests/extmod/urandom_extra_float.py
index f665fd18a..65918da13 100644
--- a/tests/extmod/urandom_extra_float.py
+++ b/tests/extmod/urandom_extra_float.py
@@ -10,14 +10,14 @@ except ImportError:
try:
random.randint
except AttributeError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
-print('random')
+print("random")
for i in range(50):
assert 0 <= random.random() < 1
-print('uniform')
+print("uniform")
for i in range(50):
assert 0 <= random.uniform(0, 4) <= 4
assert 2 <= random.uniform(2, 6) <= 6
diff --git a/tests/extmod/ure1.py b/tests/extmod/ure1.py
index ae9ff3470..9e1be5fc7 100644
--- a/tests/extmod/ure1.py
+++ b/tests/extmod/ure1.py
@@ -70,11 +70,16 @@ print(m.group(0))
m = re.search("w.r", "hello world")
print(m.group(0))
-m = re.match('a+?', 'ab'); print(m.group(0))
-m = re.match('a*?', 'ab'); print(m.group(0))
-m = re.match('^ab$', 'ab'); print(m.group(0))
-m = re.match('a|b', 'b'); print(m.group(0))
-m = re.match('a|b|c', 'c'); print(m.group(0))
+m = re.match("a+?", "ab")
+print(m.group(0))
+m = re.match("a*?", "ab")
+print(m.group(0))
+m = re.match("^ab$", "ab")
+print(m.group(0))
+m = re.match("a|b", "b")
+print(m.group(0))
+m = re.match("a|b|c", "c")
+print(m.group(0))
# Case where anchors fail to match
r = re.compile("^b|b$")
@@ -87,24 +92,36 @@ except:
print("Caught invalid regex")
# bytes objects
-m = re.match(rb'a+?', b'ab'); print(m.group(0))
+m = re.match(rb"a+?", b"ab")
+print(m.group(0))
print("===")
# escaping
-m = re.match(r'a\.c', 'a.c'); print(m.group(0) if m else '')
-m = re.match(r'a\.b', 'abc'); print(m is None)
-m = re.match(r'a\.b', 'a\\bc'); print(m is None)
-m = re.match(r'[a\-z]', 'abc'); print(m.group(0))
-m = re.match(r'[.\]]*', '.].]a'); print(m.group(0))
-m = re.match(r'[.\]+]*', '.]+.]a'); print(m.group(0))
-m = re.match(r'[a-f0-9x\-yz]*', 'abxcd1-23'); print(m.group(0))
-m = re.match(r'[a\\b]*', 'a\\aa\\bb\\bbab'); print(m.group(0))
-m = re.search(r'[a\-z]', '-'); print(m.group(0))
-m = re.search(r'[a\-z]', 'f'); print(m is None)
-m = re.search(r'[a\]z]', 'a'); print(m.group(0))
-print(re.compile(r'[-a]').split('foo-bar'))
-print(re.compile(r'[a-]').split('foo-bar'))
-print(re.compile(r'[ax\-]').split('foo-bar'))
-print(re.compile(r'[a\-x]').split('foo-bar'))
-print(re.compile(r'[\-ax]').split('foo-bar'))
+m = re.match(r"a\.c", "a.c")
+print(m.group(0) if m else "")
+m = re.match(r"a\.b", "abc")
+print(m is None)
+m = re.match(r"a\.b", "a\\bc")
+print(m is None)
+m = re.match(r"[a\-z]", "abc")
+print(m.group(0))
+m = re.match(r"[.\]]*", ".].]a")
+print(m.group(0))
+m = re.match(r"[.\]+]*", ".]+.]a")
+print(m.group(0))
+m = re.match(r"[a-f0-9x\-yz]*", "abxcd1-23")
+print(m.group(0))
+m = re.match(r"[a\\b]*", "a\\aa\\bb\\bbab")
+print(m.group(0))
+m = re.search(r"[a\-z]", "-")
+print(m.group(0))
+m = re.search(r"[a\-z]", "f")
+print(m is None)
+m = re.search(r"[a\]z]", "a")
+print(m.group(0))
+print(re.compile(r"[-a]").split("foo-bar"))
+print(re.compile(r"[a-]").split("foo-bar"))
+print(re.compile(r"[ax\-]").split("foo-bar"))
+print(re.compile(r"[a\-x]").split("foo-bar"))
+print(re.compile(r"[\-ax]").split("foo-bar"))
print("===")
diff --git a/tests/extmod/ure_debug.py b/tests/extmod/ure_debug.py
index 621fc8d50..7a07ede2d 100644
--- a/tests/extmod/ure_debug.py
+++ b/tests/extmod/ure_debug.py
@@ -1,9 +1,10 @@
# test printing debugging info when compiling
try:
import ure
+
ure.DEBUG
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
-ure.compile('^a|b[0-9]\w$', ure.DEBUG)
+ure.compile("^a|b[0-9]\w$", ure.DEBUG)
diff --git a/tests/extmod/ure_error.py b/tests/extmod/ure_error.py
index 02d48d2a8..52a96b7c0 100644
--- a/tests/extmod/ure_error.py
+++ b/tests/extmod/ure_error.py
@@ -9,18 +9,20 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def test_re(r):
try:
re.compile(r)
print("OK")
- except: # uPy and CPy use different errors, so just ignore the type
+ except: # uPy and CPy use different errors, so just ignore the type
print("Error")
-test_re(r'?')
-test_re(r'*')
-test_re(r'+')
-test_re(r')')
-test_re(r'[')
-test_re(r'([')
-test_re(r'([)')
-test_re(r'[a\]')
+
+test_re(r"?")
+test_re(r"*")
+test_re(r"+")
+test_re(r")")
+test_re(r"[")
+test_re(r"([")
+test_re(r"([)")
+test_re(r"[a\]")
diff --git a/tests/extmod/ure_group.py b/tests/extmod/ure_group.py
index 4e39468c5..41425dd62 100644
--- a/tests/extmod/ure_group.py
+++ b/tests/extmod/ure_group.py
@@ -9,8 +9,9 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def print_groups(match):
- print('----')
+ print("----")
try:
i = 0
while True:
@@ -19,14 +20,15 @@ def print_groups(match):
except IndexError:
pass
-m = re.match(r'(([0-9]*)([a-z]*)[0-9]*)','1234hello567')
+
+m = re.match(r"(([0-9]*)([a-z]*)[0-9]*)", "1234hello567")
print_groups(m)
-m = re.match(r'([0-9]*)(([a-z]*)([0-9]*))','1234hello567')
+m = re.match(r"([0-9]*)(([a-z]*)([0-9]*))", "1234hello567")
print_groups(m)
# optional group that matches
-print_groups(re.match(r'(a)?b(c)', 'abc'))
+print_groups(re.match(r"(a)?b(c)", "abc"))
# optional group that doesn't match
-print_groups(re.match(r'(a)?b(c)', 'bc'))
+print_groups(re.match(r"(a)?b(c)", "bc"))
diff --git a/tests/extmod/ure_groups.py b/tests/extmod/ure_groups.py
index 4fac896d7..7da072a92 100644
--- a/tests/extmod/ure_groups.py
+++ b/tests/extmod/ure_groups.py
@@ -13,21 +13,21 @@ try:
m = re.match(".", "a")
m.groups
except AttributeError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
-m = re.match(r'(([0-9]*)([a-z]*)[0-9]*)','1234hello567')
+m = re.match(r"(([0-9]*)([a-z]*)[0-9]*)", "1234hello567")
print(m.groups())
-m = re.match(r'([0-9]*)(([a-z]*)([0-9]*))','1234hello567')
+m = re.match(r"([0-9]*)(([a-z]*)([0-9]*))", "1234hello567")
print(m.groups())
# optional group that matches
-print(re.match(r'(a)?b(c)', 'abc').groups())
+print(re.match(r"(a)?b(c)", "abc").groups())
# optional group that doesn't match
-print(re.match(r'(a)?b(c)', 'bc').groups())
+print(re.match(r"(a)?b(c)", "bc").groups())
# only a single match
-print(re.match(r'abc', 'abc').groups())
+print(re.match(r"abc", "abc").groups())
diff --git a/tests/extmod/ure_namedclass.py b/tests/extmod/ure_namedclass.py
index 215d09613..00d58ad98 100644
--- a/tests/extmod/ure_namedclass.py
+++ b/tests/extmod/ure_namedclass.py
@@ -9,8 +9,9 @@ except ImportError:
print("SKIP")
raise SystemExit
+
def print_groups(match):
- print('----')
+ print("----")
try:
i = 0
while True:
@@ -19,14 +20,15 @@ def print_groups(match):
except IndexError:
pass
-m = re.match(r'\w+','1234hello567 abc')
+
+m = re.match(r"\w+", "1234hello567 abc")
print_groups(m)
-m = re.match(r'(\w+)\s+(\w+)','ABC \t1234hello567 abc')
+m = re.match(r"(\w+)\s+(\w+)", "ABC \t1234hello567 abc")
print_groups(m)
-m = re.match(r'(\S+)\s+(\D+)','ABC \thello abc567 abc')
+m = re.match(r"(\S+)\s+(\D+)", "ABC \thello abc567 abc")
print_groups(m)
-m = re.match(r'(([0-9]*)([a-z]*)\d*)','1234hello567')
+m = re.match(r"(([0-9]*)([a-z]*)\d*)", "1234hello567")
print_groups(m)
diff --git a/tests/extmod/ure_span.py b/tests/extmod/ure_span.py
index 50f44399c..03a3fef9f 100644
--- a/tests/extmod/ure_span.py
+++ b/tests/extmod/ure_span.py
@@ -13,12 +13,12 @@ try:
m = re.match(".", "a")
m.span
except AttributeError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
def print_spans(match):
- print('----')
+ print("----")
try:
i = 0
while True:
@@ -27,14 +27,15 @@ def print_spans(match):
except IndexError:
pass
-m = re.match(r'(([0-9]*)([a-z]*)[0-9]*)','1234hello567')
+
+m = re.match(r"(([0-9]*)([a-z]*)[0-9]*)", "1234hello567")
print_spans(m)
-m = re.match(r'([0-9]*)(([a-z]*)([0-9]*))','1234hello567')
+m = re.match(r"([0-9]*)(([a-z]*)([0-9]*))", "1234hello567")
print_spans(m)
# optional span that matches
-print_spans(re.match(r'(a)?b(c)', 'abc'))
+print_spans(re.match(r"(a)?b(c)", "abc"))
# optional span that doesn't match
-print_spans(re.match(r'(a)?b(c)', 'bc'))
+print_spans(re.match(r"(a)?b(c)", "bc"))
diff --git a/tests/extmod/ure_split_notimpl.py b/tests/extmod/ure_split_notimpl.py
index da6e9652d..51bad791e 100644
--- a/tests/extmod/ure_split_notimpl.py
+++ b/tests/extmod/ure_split_notimpl.py
@@ -4,8 +4,8 @@ except ImportError:
print("SKIP")
raise SystemExit
-r = re.compile('( )')
+r = re.compile("( )")
try:
s = r.split("a b c foobar")
except NotImplementedError:
- print('NotImplementedError')
+ print("NotImplementedError")
diff --git a/tests/extmod/ure_sub.py b/tests/extmod/ure_sub.py
index 4aeb8650a..6bb332077 100644
--- a/tests/extmod/ure_sub.py
+++ b/tests/extmod/ure_sub.py
@@ -4,58 +4,59 @@ except ImportError:
try:
import re
except ImportError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
try:
re.sub
except AttributeError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
def multiply(m):
return str(int(m.group(0)) * 2)
+
print(re.sub("\d+", multiply, "10 20 30 40 50"))
print(re.sub("\d+", lambda m: str(int(m.group(0)) // 2), "10 20 30 40 50"))
+
def A():
return "A"
-print(re.sub('a', A(), 'aBCBABCDabcda.'))
+
+
+print(re.sub("a", A(), "aBCBABCDabcda."))
print(
re.sub(
- r'def\s+([a-zA-Z_][a-zA-Z_0-9]*)\s*\(\s*\):',
- 'static PyObject*\npy_\\1(void){\n return;\n}\n',
- '\n\ndef myfunc():\n\ndef myfunc1():\n\ndef myfunc2():'
+ r"def\s+([a-zA-Z_][a-zA-Z_0-9]*)\s*\(\s*\):",
+ "static PyObject*\npy_\\1(void){\n return;\n}\n",
+ "\n\ndef myfunc():\n\ndef myfunc1():\n\ndef myfunc2():",
)
-)
+)
print(
- re.compile(
- '(calzino) (blu|bianco|verde) e (scarpa) (blu|bianco|verde)'
- ).sub(
- r'\g<1> colore \2 con \g<3> colore \4? ...',
- 'calzino blu e scarpa verde'
+ re.compile("(calzino) (blu|bianco|verde) e (scarpa) (blu|bianco|verde)").sub(
+ r"\g<1> colore \2 con \g<3> colore \4? ...", "calzino blu e scarpa verde"
)
)
# no matches at all
-print(re.sub('a', 'b', 'c'))
+print(re.sub("a", "b", "c"))
# with maximum substitution count specified
-print(re.sub('a', 'b', '1a2a3a', 2))
+print(re.sub("a", "b", "1a2a3a", 2))
# invalid group
try:
- re.sub('(a)', 'b\\2', 'a')
+ re.sub("(a)", "b\\2", "a")
except:
- print('invalid group')
+ print("invalid group")
# invalid group with very large number (to test overflow in uPy)
try:
- re.sub('(a)', 'b\\199999999999999999999999999999999999999', 'a')
+ re.sub("(a)", "b\\199999999999999999999999999999999999999", "a")
except:
- print('invalid group')
+ print("invalid group")
diff --git a/tests/extmod/ure_sub_unmatched.py b/tests/extmod/ure_sub_unmatched.py
index 4795b3196..d6312bfc2 100644
--- a/tests/extmod/ure_sub_unmatched.py
+++ b/tests/extmod/ure_sub_unmatched.py
@@ -6,14 +6,14 @@ except ImportError:
try:
import re
except ImportError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
try:
re.sub
except AttributeError:
- print('SKIP')
+ print("SKIP")
raise SystemExit
# first group matches, second optional group doesn't so is replaced with a blank
-print(re.sub(r'(a)(b)?', r'\2-\1', '1a2'))
+print(re.sub(r"(a)(b)?", r"\2-\1", "1a2"))
diff --git a/tests/extmod/uselect_poll_basic.py b/tests/extmod/uselect_poll_basic.py
index 82a7195c0..07328365b 100644
--- a/tests/extmod/uselect_poll_basic.py
+++ b/tests/extmod/uselect_poll_basic.py
@@ -3,6 +3,7 @@ try:
except ImportError:
try:
import socket, select, errno
+
select.poll # Raises AttributeError for CPython implementations without poll()
except (ImportError, AttributeError):
print("SKIP")
diff --git a/tests/extmod/uselect_poll_udp.py b/tests/extmod/uselect_poll_udp.py
index e7d7dfe34..f6be262ee 100644
--- a/tests/extmod/uselect_poll_udp.py
+++ b/tests/extmod/uselect_poll_udp.py
@@ -8,10 +8,10 @@ except ImportError:
except ImportError:
print("SKIP")
raise SystemExit
-
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-s.bind(socket.getaddrinfo('127.0.0.1', 8000)[0][-1])
+s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0][-1])
poll = select.poll()
# UDP socket should not be readable
diff --git a/tests/extmod/usocket_udp_nonblock.py b/tests/extmod/usocket_udp_nonblock.py
index 63197584d..7dc0e562a 100644
--- a/tests/extmod/usocket_udp_nonblock.py
+++ b/tests/extmod/usocket_udp_nonblock.py
@@ -11,10 +11,10 @@ except ImportError:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-s.bind(socket.getaddrinfo('127.0.0.1', 8000)[0][-1])
+s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0][-1])
s.settimeout(0)
try:
s.recv(1)
except OSError as er:
- print('EAGAIN:', er.args[0] == errno.EAGAIN)
+ print("EAGAIN:", er.args[0] == errno.EAGAIN)
diff --git a/tests/extmod/ussl_basic.py b/tests/extmod/ussl_basic.py
index a040fc20c..b4e21c7dc 100644
--- a/tests/extmod/ussl_basic.py
+++ b/tests/extmod/ussl_basic.py
@@ -11,7 +11,7 @@ except ImportError:
try:
ss = ssl.wrap_socket(io.BytesIO())
except OSError as er:
- print('wrap_socket:', repr(er))
+ print("wrap_socket:", repr(er))
# create in server mode (can use this object for further tests)
socket = io.BytesIO()
@@ -22,25 +22,25 @@ print(repr(ss)[:12])
# setblocking() propagates call to the underlying stream object, and
# io.BytesIO doesn't have setblocking() (in CPython too).
-#try:
+# try:
# ss.setblocking(False)
-#except NotImplementedError:
+# except NotImplementedError:
# print('setblocking: NotImplementedError')
-#ss.setblocking(True)
+# ss.setblocking(True)
# write
-print(ss.write(b'aaaa'))
+print(ss.write(b"aaaa"))
# read (underlying socket has no data)
print(ss.read(8))
# read (underlying socket has data, but it's bad data)
-socket.write(b'aaaaaaaaaaaaaaaa')
+socket.write(b"aaaaaaaaaaaaaaaa")
socket.seek(0)
try:
ss.read(8)
except OSError as er:
- print('read:', repr(er))
+ print("read:", repr(er))
# close
ss.close()
@@ -51,10 +51,10 @@ ss.close()
try:
ss.read(10)
except OSError as er:
- print('read:', repr(er))
+ print("read:", repr(er))
# write on closed socket
try:
- ss.write(b'aaaa')
+ ss.write(b"aaaa")
except OSError as er:
- print('write:', repr(er))
+ print("write:", repr(er))
diff --git a/tests/extmod/ussl_keycert.py b/tests/extmod/ussl_keycert.py
index 9b3eae602..87a40a1e5 100644
--- a/tests/extmod/ussl_keycert.py
+++ b/tests/extmod/ussl_keycert.py
@@ -7,11 +7,11 @@ except ImportError:
print("SKIP")
raise SystemExit
-key = b'0\x82\x019\x02\x01\x00\x02A\x00\xf9\xe0}\xbd\xd7\x9cI\x18\x06\xc3\xcb\xb5\xec@r\xfbD\x18\x80\xaaWoZ{\xcc\xa3\xeb!"\x0fY\x9e]-\xee\xe4\t!BY\x9f{7\xf3\xf2\x8f}}\r|.\xa8<\ta\xb2\xd7W\xb3\xc9\x19A\xc39\x02\x03\x01\x00\x01\x02@\x07:\x9fh\xa6\x9c6\xe1#\x10\xf7\x0b\xc4Q\xf9\x01\x9b\xee\xb9\x8a4\r\\\xa8\xc8:\xd5\xca\x97\x99\xaa\x16\x04)\xa8\xf9\x13\xdeq\x0ev`\xa7\x83\xc5\x8b`\xdb\xef \x9d\x93\xe8g\x84\x96\xfaV\\\xf4R\xda\xd0\xa1\x02!\x00\xfeR\xbf\n\x91Su\x87L\x98{\xeb%\xed\xfb\x06u)@\xfe\x1b\xde\xa0\xc6@\xab\xc5\xedg\x8e\x10[\x02!\x00\xfb\x86=\x85\xa4\'\xde\x85\xb5L\xe0)\x99\xfaL\x8c3A\x02\xa8<\xdew\xad\x00\xe3\x1d\x05\xd8\xb4N\xfb\x02 \x08\xb0M\x04\x90hx\x88q\xcew\xd5U\xcbf\x9b\x16\xdf\x9c\xef\xd1\x85\xee\x9a7Ug\x02\xb0Z\x03\'\x02 9\xa0D\xe2$|\xf9\xefz]5\x92rs\xb5+\xfd\xe6,\x1c\xadmn\xcf\xd5?3|\x0em)\x17\x02 5Z\xcc/\xa5?\n\x04%\x9b{N\x9dX\xddI\xbe\xd2\xb0\xa0\x03BQ\x02\x82\xc2\xe0u)\xbd\xb8\xaf'
+key = b"0\x82\x019\x02\x01\x00\x02A\x00\xf9\xe0}\xbd\xd7\x9cI\x18\x06\xc3\xcb\xb5\xec@r\xfbD\x18\x80\xaaWoZ{\xcc\xa3\xeb!\"\x0fY\x9e]-\xee\xe4\t!BY\x9f{7\xf3\xf2\x8f}}\r|.\xa8<\ta\xb2\xd7W\xb3\xc9\x19A\xc39\x02\x03\x01\x00\x01\x02@\x07:\x9fh\xa6\x9c6\xe1#\x10\xf7\x0b\xc4Q\xf9\x01\x9b\xee\xb9\x8a4\r\\\xa8\xc8:\xd5\xca\x97\x99\xaa\x16\x04)\xa8\xf9\x13\xdeq\x0ev`\xa7\x83\xc5\x8b`\xdb\xef \x9d\x93\xe8g\x84\x96\xfaV\\\xf4R\xda\xd0\xa1\x02!\x00\xfeR\xbf\n\x91Su\x87L\x98{\xeb%\xed\xfb\x06u)@\xfe\x1b\xde\xa0\xc6@\xab\xc5\xedg\x8e\x10[\x02!\x00\xfb\x86=\x85\xa4'\xde\x85\xb5L\xe0)\x99\xfaL\x8c3A\x02\xa8<\xdew\xad\x00\xe3\x1d\x05\xd8\xb4N\xfb\x02 \x08\xb0M\x04\x90hx\x88q\xcew\xd5U\xcbf\x9b\x16\xdf\x9c\xef\xd1\x85\xee\x9a7Ug\x02\xb0Z\x03'\x02 9\xa0D\xe2$|\xf9\xefz]5\x92rs\xb5+\xfd\xe6,\x1c\xadmn\xcf\xd5?3|\x0em)\x17\x02 5Z\xcc/\xa5?\n\x04%\x9b{N\x9dX\xddI\xbe\xd2\xb0\xa0\x03BQ\x02\x82\xc2\xe0u)\xbd\xb8\xaf"
# Invalid key
try:
- ssl.wrap_socket(io.BytesIO(), key=b'!')
+ ssl.wrap_socket(io.BytesIO(), key=b"!")
except ValueError as er:
print(repr(er))
@@ -23,6 +23,6 @@ except TypeError as er:
# Valid key, invalid cert
try:
- ssl.wrap_socket(io.BytesIO(), key=key, cert=b'!')
+ ssl.wrap_socket(io.BytesIO(), key=key, cert=b"!")
except ValueError as er:
print(repr(er))
diff --git a/tests/extmod/utimeq1.py b/tests/extmod/utimeq1.py
index dc7f3b660..234d7a31d 100644
--- a/tests/extmod/utimeq1.py
+++ b/tests/extmod/utimeq1.py
@@ -13,12 +13,17 @@ MAX = ticks_add(0, -1)
MODULO_HALF = MAX // 2 + 1
if DEBUG:
+
def dprint(*v):
print(*v)
+
+
else:
+
def dprint(*v):
pass
+
# Try not to crash on invalid data
h = utimeq(10)
try:
@@ -69,22 +74,25 @@ try:
except IndexError:
pass
+
def pop_all(h):
l = []
while h:
item = [0, 0, 0]
h.pop(item)
- #print("!", item)
+ # print("!", item)
l.append(tuple(item))
dprint(l)
return l
+
def add(h, v):
h.push(v, 0, 0)
dprint("-----")
- #h.dump()
+ # h.dump()
dprint("-----")
+
h = utimeq(10)
add(h, 0)
add(h, MAX)
@@ -98,6 +106,7 @@ for i in range(len(l) - 1):
diff = ticks_diff(l[i + 1][0], l[i][0])
assert diff > 0
+
def edge_case(edge, offset):
h = utimeq(10)
add(h, ticks_add(0, offset))
@@ -108,6 +117,7 @@ def edge_case(edge, offset):
dprint(diff, diff > 0)
return diff
+
dprint("===")
diff = edge_case(MODULO_HALF - 1, 0)
assert diff == MODULO_HALF - 1
diff --git a/tests/extmod/uzlib_decompio.py b/tests/extmod/uzlib_decompio.py
index 112a82597..6a0aae8bc 100644
--- a/tests/extmod/uzlib_decompio.py
+++ b/tests/extmod/uzlib_decompio.py
@@ -7,7 +7,7 @@ except ImportError:
# Raw DEFLATE bitstream
-buf = io.BytesIO(b'\xcbH\xcd\xc9\xc9\x07\x00')
+buf = io.BytesIO(b"\xcbH\xcd\xc9\xc9\x07\x00")
inp = zlib.DecompIO(buf, -8)
print(buf.seek(0, 1))
print(inp.read(1))
@@ -21,12 +21,12 @@ print(buf.seek(0, 1))
# zlib bitstream
-inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'))
+inp = zlib.DecompIO(io.BytesIO(b"x\x9c30\xa0=\x00\x00\xb3q\x12\xc1"))
print(inp.read(10))
print(inp.read())
# zlib bitstream, wrong checksum
-inp = zlib.DecompIO(io.BytesIO(b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc0'))
+inp = zlib.DecompIO(io.BytesIO(b"x\x9c30\xa0=\x00\x00\xb3q\x12\xc0"))
try:
print(inp.read())
except OSError as e:
diff --git a/tests/extmod/uzlib_decompio_gz.py b/tests/extmod/uzlib_decompio_gz.py
index 02087f763..1bc8ba885 100644
--- a/tests/extmod/uzlib_decompio_gz.py
+++ b/tests/extmod/uzlib_decompio_gz.py
@@ -7,7 +7,9 @@ except ImportError:
# gzip bitstream
-buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
+buf = io.BytesIO(
+ b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
+)
inp = zlib.DecompIO(buf, 16 + 8)
print(buf.seek(0, 1))
print(inp.read(1))
@@ -20,24 +22,32 @@ print(inp.read())
print(buf.seek(0, 1))
# Check FHCRC field
-buf = io.BytesIO(b'\x1f\x8b\x08\x02\x99\x0c\xe5W\x00\x03\x00\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
+buf = io.BytesIO(
+ b"\x1f\x8b\x08\x02\x99\x0c\xe5W\x00\x03\x00\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
+)
inp = zlib.DecompIO(buf, 16 + 8)
print(inp.read())
# Check FEXTRA field
-buf = io.BytesIO(b'\x1f\x8b\x08\x04\x99\x0c\xe5W\x00\x03\x01\x00X\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
+buf = io.BytesIO(
+ b"\x1f\x8b\x08\x04\x99\x0c\xe5W\x00\x03\x01\x00X\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
+)
inp = zlib.DecompIO(buf, 16 + 8)
print(inp.read())
# broken header
-buf = io.BytesIO(b'\x1f\x8c\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00')
+buf = io.BytesIO(
+ b"\x1f\x8c\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
+)
try:
inp = zlib.DecompIO(buf, 16 + 8)
except ValueError:
print("ValueError")
# broken crc32
-buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa7\x106\x05\x00\x00\x00')
+buf = io.BytesIO(
+ b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa7\x106\x05\x00\x00\x00"
+)
inp = zlib.DecompIO(buf, 16 + 8)
try:
inp.read(6)
@@ -45,6 +55,6 @@ except OSError as e:
print(repr(e))
# broken uncompressed size - not checked so far
-#buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x06\x00\x00\x00')
-#inp = zlib.DecompIO(buf, 16 + 8)
-#inp.read(6)
+# buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x06\x00\x00\x00')
+# inp = zlib.DecompIO(buf, 16 + 8)
+# inp.read(6)
diff --git a/tests/extmod/uzlib_decompress.py b/tests/extmod/uzlib_decompress.py
index dd6e4876f..8d4a9640b 100644
--- a/tests/extmod/uzlib_decompress.py
+++ b/tests/extmod/uzlib_decompress.py
@@ -9,15 +9,24 @@ except ImportError:
PATTERNS = [
# Packed results produced by CPy's zlib.compress()
- (b'0', b'x\x9c3\x00\x00\x001\x001'),
- (b'a', b'x\x9cK\x04\x00\x00b\x00b'),
- (b'0' * 100, b'x\x9c30\xa0=\x00\x00\xb3q\x12\xc1'),
- (bytes(range(64)), b'x\x9cc`dbfaec\xe7\xe0\xe4\xe2\xe6\xe1\xe5\xe3\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91\x95\x93WPTRVQUS\xd7\xd0\xd4\xd2\xd6\xd1\xd5\xd370426153\xb7\xb0\xb4\xb2\xb6\xb1\xb5\xb3\x07\x00\xaa\xe0\x07\xe1'),
- (b'hello', b'x\x01\x01\x05\x00\xfa\xffhello\x06,\x02\x15'), # compression level 0
+ (b"0", b"x\x9c3\x00\x00\x001\x001"),
+ (b"a", b"x\x9cK\x04\x00\x00b\x00b"),
+ (b"0" * 100, b"x\x9c30\xa0=\x00\x00\xb3q\x12\xc1"),
+ (
+ bytes(range(64)),
+ b"x\x9cc`dbfaec\xe7\xe0\xe4\xe2\xe6\xe1\xe5\xe3\x17\x10\x14\x12\x16\x11\x15\x13\x97\x90\x94\x92\x96\x91\x95\x93WPTRVQUS\xd7\xd0\xd4\xd2\xd6\xd1\xd5\xd370426153\xb7\xb0\xb4\xb2\xb6\xb1\xb5\xb3\x07\x00\xaa\xe0\x07\xe1",
+ ),
+ (b"hello", b"x\x01\x01\x05\x00\xfa\xffhello\x06,\x02\x15"), # compression level 0
# adaptive/dynamic huffman tree
- (b'13371813150|13764518736|12345678901', b'x\x9c\x05\xc1\x81\x01\x000\x04\x04\xb1\x95\\\x1f\xcfn\x86o\x82d\x06Qq\xc8\x9d\xc5X}<e\xb5g\x83\x0f\x89X\x07\xab'),
+ (
+ b"13371813150|13764518736|12345678901",
+ b"x\x9c\x05\xc1\x81\x01\x000\x04\x04\xb1\x95\\\x1f\xcfn\x86o\x82d\x06Qq\xc8\x9d\xc5X}<e\xb5g\x83\x0f\x89X\x07\xab",
+ ),
# dynamic Huffman tree with "case 17" (repeat code for 3-10 times)
- (b'>I}\x00\x951D>I}\x00\x951D>I}\x00\x951D>I}\x00\x951D', b'x\x9c\x05\xc11\x01\x00\x00\x00\x010\x95\x14py\x84\x12C_\x9bR\x8cV\x8a\xd1J1Z)F\x1fw`\x089'),
+ (
+ b">I}\x00\x951D>I}\x00\x951D>I}\x00\x951D>I}\x00\x951D",
+ b"x\x9c\x05\xc11\x01\x00\x00\x00\x010\x95\x14py\x84\x12C_\x9bR\x8cV\x8a\xd1J1Z)F\x1fw`\x089",
+ ),
]
for unpacked, packed in PATTERNS:
@@ -26,26 +35,26 @@ for unpacked, packed in PATTERNS:
# Raw DEFLATE bitstream
-v = b'\xcbH\xcd\xc9\xc9\x07\x00'
+v = b"\xcbH\xcd\xc9\xc9\x07\x00"
exp = b"hello"
out = zlib.decompress(v, -15)
-assert(out == exp)
+assert out == exp
print(exp)
# Even when you ask CPython zlib.compress to produce Raw DEFLATE stream,
# it returns it with adler2 and oriignal size appended, as if it was a
# zlib stream. Make sure there're no random issues decompressing such.
-v = b'\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00'
+v = b"\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
out = zlib.decompress(v, -15)
-assert(out == exp)
+assert out == exp
# this should error
try:
- zlib.decompress(b'abc')
+ zlib.decompress(b"abc")
except Exception:
print("Exception")
# invalid block type
try:
- zlib.decompress(b'\x07', -15) # final-block, block-type=3 (invalid)
+ zlib.decompress(b"\x07", -15) # final-block, block-type=3 (invalid)
except Exception as er:
- print('Exception')
+ print("Exception")
diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py
index fbcc92bad..c8e203b3d 100644
--- a/tests/extmod/vfs_basic.py
+++ b/tests/extmod/vfs_basic.py
@@ -2,6 +2,7 @@
try:
import uos
+
uos.mount
except (ImportError, AttributeError):
print("SKIP")
@@ -11,55 +12,67 @@ except (ImportError, AttributeError):
class Filesystem:
def __init__(self, id):
self.id = id
+
def mount(self, readonly, mkfs):
- print(self.id, 'mount', readonly, mkfs)
+ print(self.id, "mount", readonly, mkfs)
+
def umount(self):
- print(self.id, 'umount')
+ print(self.id, "umount")
+
def ilistdir(self, dir):
- print(self.id, 'ilistdir', dir)
- return iter([('a%d' % self.id, 0, 0)])
+ print(self.id, "ilistdir", dir)
+ return iter([("a%d" % self.id, 0, 0)])
+
def chdir(self, dir):
- print(self.id, 'chdir', dir)
+ print(self.id, "chdir", dir)
+
def getcwd(self):
- print(self.id, 'getcwd')
- return 'dir%d' % self.id
+ print(self.id, "getcwd")
+ return "dir%d" % self.id
+
def mkdir(self, path):
- print(self.id, 'mkdir', path)
+ print(self.id, "mkdir", path)
+
def remove(self, path):
- print(self.id, 'remove', path)
+ print(self.id, "remove", path)
+
def rename(self, old_path, new_path):
- print(self.id, 'rename', old_path, new_path)
+ print(self.id, "rename", old_path, new_path)
+
def rmdir(self, path):
- print(self.id, 'rmdir', path)
+ print(self.id, "rmdir", path)
+
def stat(self, path):
- print(self.id, 'stat', path)
+ print(self.id, "stat", path)
return (self.id,)
+
def statvfs(self, path):
- print(self.id, 'statvfs', path)
+ print(self.id, "statvfs", path)
return (self.id,)
+
def open(self, file, mode):
- print(self.id, 'open', file, mode)
+ print(self.id, "open", file, mode)
# first we umount any existing mount points the target may have
try:
- uos.umount('/')
+ uos.umount("/")
except OSError:
pass
-for path in uos.listdir('/'):
- uos.umount('/' + path)
+for path in uos.listdir("/"):
+ uos.umount("/" + path)
# stat root dir
-print(uos.stat('/'))
+print(uos.stat("/"))
# statvfs root dir; verify that f_namemax has a sensible size
-print(uos.statvfs('/')[9] >= 32)
+print(uos.statvfs("/")[9] >= 32)
# getcwd when in root dir
print(uos.getcwd())
# basic mounting and listdir
-uos.mount(Filesystem(1), '/test_mnt')
+uos.mount(Filesystem(1), "/test_mnt")
print(uos.listdir())
# ilistdir
@@ -68,80 +81,80 @@ print(next(i))
try:
next(i)
except StopIteration:
- print('StopIteration')
+ print("StopIteration")
try:
next(i)
except StopIteration:
- print('StopIteration')
+ print("StopIteration")
# referencing the mount point in different ways
-print(uos.listdir('test_mnt'))
-print(uos.listdir('/test_mnt'))
+print(uos.listdir("test_mnt"))
+print(uos.listdir("/test_mnt"))
# mounting another filesystem
-uos.mount(Filesystem(2), '/test_mnt2', readonly=True)
+uos.mount(Filesystem(2), "/test_mnt2", readonly=True)
print(uos.listdir())
-print(uos.listdir('/test_mnt2'))
+print(uos.listdir("/test_mnt2"))
# mounting over an existing mount point
try:
- uos.mount(Filesystem(3), '/test_mnt2')
+ uos.mount(Filesystem(3), "/test_mnt2")
except OSError:
- print('OSError')
+ print("OSError")
# mkdir of a mount point
try:
- uos.mkdir('/test_mnt')
+ uos.mkdir("/test_mnt")
except OSError:
- print('OSError')
+ print("OSError")
# rename across a filesystem
try:
- uos.rename('/test_mnt/a', '/test_mnt2/b')
+ uos.rename("/test_mnt/a", "/test_mnt2/b")
except OSError:
- print('OSError')
+ print("OSError")
# delegating to mounted filesystem
-uos.chdir('test_mnt')
+uos.chdir("test_mnt")
print(uos.listdir())
print(uos.getcwd())
-uos.mkdir('test_dir')
-uos.remove('test_file')
-uos.rename('test_file', 'test_file2')
-uos.rmdir('test_dir')
-print(uos.stat('test_file'))
-print(uos.statvfs('/test_mnt'))
-open('test_file')
-open('test_file', 'wb')
+uos.mkdir("test_dir")
+uos.remove("test_file")
+uos.rename("test_file", "test_file2")
+uos.rmdir("test_dir")
+print(uos.stat("test_file"))
+print(uos.statvfs("/test_mnt"))
+open("test_file")
+open("test_file", "wb")
# umount
-uos.umount('/test_mnt')
-uos.umount('/test_mnt2')
+uos.umount("/test_mnt")
+uos.umount("/test_mnt2")
# umount a non-existent mount point
try:
- uos.umount('/test_mnt')
+ uos.umount("/test_mnt")
except OSError:
- print('OSError')
+ print("OSError")
# root dir
-uos.mount(Filesystem(3), '/')
-print(uos.stat('/'))
-print(uos.statvfs('/'))
+uos.mount(Filesystem(3), "/")
+print(uos.stat("/"))
+print(uos.statvfs("/"))
print(uos.listdir())
-open('test')
+open("test")
-uos.mount(Filesystem(4), '/mnt')
+uos.mount(Filesystem(4), "/mnt")
print(uos.listdir())
-print(uos.listdir('/mnt'))
-uos.chdir('/mnt')
+print(uos.listdir("/mnt"))
+uos.chdir("/mnt")
print(uos.listdir())
# chdir to a subdir within root-mounted vfs, and then listdir
-uos.chdir('/subdir')
+uos.chdir("/subdir")
print(uos.listdir())
-uos.chdir('/')
+uos.chdir("/")
-uos.umount('/')
-print(uos.listdir('/'))
-uos.umount('/mnt')
+uos.umount("/")
+print(uos.listdir("/"))
+uos.umount("/mnt")
diff --git a/tests/extmod/vfs_blockdev.py b/tests/extmod/vfs_blockdev.py
index d82b10610..e24169ba9 100644
--- a/tests/extmod/vfs_blockdev.py
+++ b/tests/extmod/vfs_blockdev.py
@@ -2,12 +2,14 @@
try:
import uos
+
uos.VfsFat
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
+
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 512
@@ -28,15 +30,16 @@ class RAMBlockDevice:
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
- if op == 4: # block count
+ if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
- if op == 5: # block size
+ if op == 5: # block size
return self.ERASE_BLOCK_SIZE
- if op == 6: # erase block
+ if op == 6: # erase block
return 0
+
def test(bdev, vfs_class):
- print('test', vfs_class)
+ print("test", vfs_class)
# mkfs
vfs_class.mkfs(bdev)
@@ -45,21 +48,22 @@ def test(bdev, vfs_class):
vfs = vfs_class(bdev)
# statvfs
- print(vfs.statvfs('/'))
+ print(vfs.statvfs("/"))
# open, write close
- f = vfs.open('test', 'w')
+ f = vfs.open("test", "w")
for i in range(10):
- f.write('some data')
+ f.write("some data")
f.close()
# ilistdir
print(list(vfs.ilistdir()))
# read
- with vfs.open('test', 'r') as f:
+ with vfs.open("test", "r") as f:
print(f.read())
+
try:
bdev = RAMBlockDevice(50)
except MemoryError:
diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py
index 7fe040d53..e42911093 100644
--- a/tests/extmod/vfs_fat_fileio1.py
+++ b/tests/extmod/vfs_fat_fileio1.py
@@ -20,17 +20,17 @@ class RAMFS:
self.data = bytearray(blocks * self.SEC_SIZE)
def readblocks(self, n, buf):
- #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
+ # print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
for i in range(len(buf)):
buf[i] = self.data[n * self.SEC_SIZE + i]
def writeblocks(self, n, buf):
- #print("writeblocks(%s, %x)" % (n, id(buf)))
+ # print("writeblocks(%s, %x)" % (n, id(buf)))
for i in range(len(buf)):
self.data[n * self.SEC_SIZE + i] = buf[i]
def ioctl(self, op, arg):
- #print("ioctl(%d, %r)" % (op, arg))
+ # print("ioctl(%d, %r)" % (op, arg))
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
return len(self.data) // self.SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
@@ -45,8 +45,8 @@ except MemoryError:
uos.VfsFat.mkfs(bdev)
vfs = uos.VfsFat(bdev)
-uos.mount(vfs, '/ramdisk')
-uos.chdir('/ramdisk')
+uos.mount(vfs, "/ramdisk")
+uos.chdir("/ramdisk")
# file IO
f = open("foo_file.txt", "w")
@@ -54,7 +54,7 @@ print(str(f)[:17], str(f)[-1:])
f.write("hello!")
f.flush()
f.close()
-f.close() # allowed
+f.close() # allowed
try:
f.write("world!")
except OSError as e:
@@ -82,21 +82,21 @@ with open("foo_file.txt") as f2:
print(f2.read())
print(f2.tell())
- f2.seek(0, 0) # SEEK_SET
+ f2.seek(0, 0) # SEEK_SET
print(f2.read(1))
- f2.seek(0, 1) # SEEK_CUR
+ f2.seek(0, 1) # SEEK_CUR
print(f2.read(1))
- f2.seek(2, 1) # SEEK_CUR
+ f2.seek(2, 1) # SEEK_CUR
print(f2.read(1))
- f2.seek(-2, 2) # SEEK_END
+ f2.seek(-2, 2) # SEEK_END
print(f2.read(1))
# using constructor of FileIO type to open a file
# no longer working with new VFS sub-system
-#FileIO = type(f)
-#with FileIO("/ramdisk/foo_file.txt") as f:
+# FileIO = type(f)
+# with FileIO("/ramdisk/foo_file.txt") as f:
# print(f.read())
# dirs
@@ -105,7 +105,7 @@ vfs.mkdir("foo_dir")
try:
vfs.rmdir("foo_file.txt")
except OSError as e:
- print(e.args[0] == 20) # uerrno.ENOTDIR
+ print(e.args[0] == 20) # uerrno.ENOTDIR
vfs.remove("foo_file.txt")
print(list(vfs.ilistdir()))
diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py
index 6721f9b93..a9cea2bed 100644
--- a/tests/extmod/vfs_fat_fileio2.py
+++ b/tests/extmod/vfs_fat_fileio2.py
@@ -20,17 +20,17 @@ class RAMFS:
self.data = bytearray(blocks * self.SEC_SIZE)
def readblocks(self, n, buf):
- #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
+ # print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
for i in range(len(buf)):
buf[i] = self.data[n * self.SEC_SIZE + i]
def writeblocks(self, n, buf):
- #print("writeblocks(%s, %x)" % (n, id(buf)))
+ # print("writeblocks(%s, %x)" % (n, id(buf)))
for i in range(len(buf)):
self.data[n * self.SEC_SIZE + i] = buf[i]
def ioctl(self, op, arg):
- #print("ioctl(%d, %r)" % (op, arg))
+ # print("ioctl(%d, %r)" % (op, arg))
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
return len(self.data) // self.SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
@@ -45,8 +45,8 @@ except MemoryError:
uos.VfsFat.mkfs(bdev)
vfs = uos.VfsFat(bdev)
-uos.mount(vfs, '/ramdisk')
-uos.chdir('/ramdisk')
+uos.mount(vfs, "/ramdisk")
+uos.chdir("/ramdisk")
try:
vfs.mkdir("foo_dir")
@@ -111,4 +111,4 @@ try:
f = open("large_file.txt", "wb")
f.write(bytearray(bsize * free))
except OSError as e:
- print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC
+ print("ENOSPC:", e.args[0] == 28) # uerrno.ENOSPC
diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py
index c7254c5f0..e30f42f84 100644
--- a/tests/extmod/vfs_fat_finaliser.py
+++ b/tests/extmod/vfs_fat_finaliser.py
@@ -2,6 +2,7 @@
try:
import uerrno, uos
+
uos.VfsFat
except (ImportError, AttributeError):
print("SKIP")
@@ -22,9 +23,9 @@ class RAMBlockDevice:
self.data[n * self.sec_size + i] = buf[i]
def ioctl(self, op, arg):
- if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
+ if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
return len(self.data) // self.sec_size
- if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
+ if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
return self.sec_size
@@ -44,23 +45,25 @@ vfs = uos.VfsFat(bdev)
# finaliser is a different path to normal allocation. It would be better to
# test this in the core tests but there are no core objects that use finaliser.
import micropython
+
micropython.heap_lock()
try:
- vfs.open('x', 'r')
+ vfs.open("x", "r")
except MemoryError:
- print('MemoryError')
+ print("MemoryError")
micropython.heap_unlock()
# Here we test that the finaliser is actually called during a garbage collection.
import gc
+
N = 4
for i in range(N):
- n = 'x%d' % i
- f = vfs.open(n, 'w')
+ n = "x%d" % i
+ f = vfs.open(n, "w")
f.write(n)
- f = None # release f without closing
- [0, 1, 2, 3] # use up Python stack so f is really gone
-gc.collect() # should finalise all N files by closing them
+ f = None # release f without closing
+ [0, 1, 2, 3] # use up Python stack so f is really gone
+gc.collect() # should finalise all N files by closing them
for i in range(N):
- with vfs.open('x%d' % i, 'r') as f:
+ with vfs.open("x%d" % i, "r") as f:
print(f.read())
diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py
index 9505fd328..d8449829d 100644
--- a/tests/extmod/vfs_fat_more.py
+++ b/tests/extmod/vfs_fat_more.py
@@ -19,17 +19,17 @@ class RAMFS:
self.data = bytearray(blocks * self.SEC_SIZE)
def readblocks(self, n, buf):
- #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
+ # print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
for i in range(len(buf)):
buf[i] = self.data[n * self.SEC_SIZE + i]
def writeblocks(self, n, buf):
- #print("writeblocks(%s, %x)" % (n, id(buf)))
+ # print("writeblocks(%s, %x)" % (n, id(buf)))
for i in range(len(buf)):
self.data[n * self.SEC_SIZE + i] = buf[i]
def ioctl(self, op, arg):
- #print("ioctl(%d, %r)" % (op, arg))
+ # print("ioctl(%d, %r)" % (op, arg))
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
return len(self.data) // self.SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
@@ -45,75 +45,76 @@ except MemoryError:
# first we umount any existing mount points the target may have
try:
- uos.umount('/')
+ uos.umount("/")
except OSError:
pass
-for path in uos.listdir('/'):
- uos.umount('/' + path)
+for path in uos.listdir("/"):
+ uos.umount("/" + path)
uos.VfsFat.mkfs(bdev)
-uos.mount(bdev, '/')
+uos.mount(bdev, "/")
print(uos.getcwd())
-f = open('test.txt', 'w')
-f.write('hello')
+f = open("test.txt", "w")
+f.write("hello")
f.close()
print(uos.listdir())
-print(uos.listdir('/'))
-print(uos.stat('')[:-3])
-print(uos.stat('/')[:-3])
-print(uos.stat('test.txt')[:-3])
-print(uos.stat('/test.txt')[:-3])
+print(uos.listdir("/"))
+print(uos.stat("")[:-3])
+print(uos.stat("/")[:-3])
+print(uos.stat("test.txt")[:-3])
+print(uos.stat("/test.txt")[:-3])
-f = open('/test.txt')
+f = open("/test.txt")
print(f.read())
f.close()
-uos.rename('test.txt', 'test2.txt')
+uos.rename("test.txt", "test2.txt")
print(uos.listdir())
-uos.rename('test2.txt', '/test3.txt')
+uos.rename("test2.txt", "/test3.txt")
print(uos.listdir())
-uos.rename('/test3.txt', 'test4.txt')
+uos.rename("/test3.txt", "test4.txt")
print(uos.listdir())
-uos.rename('/test4.txt', '/test5.txt')
+uos.rename("/test4.txt", "/test5.txt")
print(uos.listdir())
-uos.mkdir('dir')
+uos.mkdir("dir")
print(uos.listdir())
-uos.mkdir('/dir2')
+uos.mkdir("/dir2")
print(uos.listdir())
-uos.mkdir('dir/subdir')
-print(uos.listdir('dir'))
-for exist in ('', '/', 'dir', '/dir', 'dir/subdir'):
+uos.mkdir("dir/subdir")
+print(uos.listdir("dir"))
+for exist in ("", "/", "dir", "/dir", "dir/subdir"):
try:
uos.mkdir(exist)
except OSError as er:
- print('mkdir OSError', er.args[0] == 17) # EEXIST
+ print("mkdir OSError", er.args[0] == 17) # EEXIST
-uos.chdir('/')
-print(uos.stat('test5.txt')[:-3])
+uos.chdir("/")
+print(uos.stat("test5.txt")[:-3])
uos.VfsFat.mkfs(bdev2)
-uos.mount(bdev2, '/sys')
+uos.mount(bdev2, "/sys")
print(uos.listdir())
-print(uos.listdir('sys'))
-print(uos.listdir('/sys'))
+print(uos.listdir("sys"))
+print(uos.listdir("/sys"))
-uos.rmdir('dir2')
-uos.remove('test5.txt')
+uos.rmdir("dir2")
+uos.remove("test5.txt")
print(uos.listdir())
-uos.umount('/')
+uos.umount("/")
print(uos.getcwd())
print(uos.listdir())
-print(uos.listdir('sys'))
+print(uos.listdir("sys"))
# test importing a file from a mounted FS
import sys
+
sys.path.clear()
-sys.path.append('/sys')
-with open('sys/test_module.py', 'w') as f:
+sys.path.append("/sys")
+with open("sys/test_module.py", "w") as f:
f.write('print("test_module!")')
import test_module
diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py
index 3caaa368d..93d00f9ce 100644
--- a/tests/extmod/vfs_fat_oldproto.py
+++ b/tests/extmod/vfs_fat_oldproto.py
@@ -11,6 +11,7 @@ except AttributeError:
print("SKIP")
raise SystemExit
+
class RAMFS_OLD:
SEC_SIZE = 512
@@ -19,12 +20,12 @@ class RAMFS_OLD:
self.data = bytearray(blocks * self.SEC_SIZE)
def readblocks(self, n, buf):
- #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
+ # print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
for i in range(len(buf)):
buf[i] = self.data[n * self.SEC_SIZE + i]
def writeblocks(self, n, buf):
- #print("writeblocks(%s, %x)" % (n, id(buf)))
+ # print("writeblocks(%s, %x)" % (n, id(buf)))
for i in range(len(buf)):
self.data[n * self.SEC_SIZE + i] = buf[i]
diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py
index 11b2df7f4..5f758bf89 100644
--- a/tests/extmod/vfs_fat_ramdisk.py
+++ b/tests/extmod/vfs_fat_ramdisk.py
@@ -20,17 +20,17 @@ class RAMFS:
self.data = bytearray(blocks * self.SEC_SIZE)
def readblocks(self, n, buf):
- #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
+ # print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
for i in range(len(buf)):
buf[i] = self.data[n * self.SEC_SIZE + i]
def writeblocks(self, n, buf):
- #print("writeblocks(%s, %x)" % (n, id(buf)))
+ # print("writeblocks(%s, %x)" % (n, id(buf)))
for i in range(len(buf)):
self.data[n * self.SEC_SIZE + i] = buf[i]
def ioctl(self, op, arg):
- #print("ioctl(%d, %r)" % (op, arg))
+ # print("ioctl(%d, %r)" % (op, arg))
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
return len(self.data) // self.SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
@@ -64,7 +64,7 @@ with vfs.open("foo_file.txt", "w") as f:
print(list(vfs.ilistdir()))
print("stat root:", vfs.stat("/"))
-print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs
+print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs
print(b"FOO_FILETXT" in bdev.data)
print(b"hello!" in bdev.data)
@@ -94,4 +94,4 @@ print(list(vfs.ilistdir(b"")))
try:
vfs.ilistdir(b"no_exist")
except OSError as e:
- print('ENOENT:', e.args[0] == uerrno.ENOENT)
+ print("ENOENT:", e.args[0] == uerrno.ENOENT)
diff --git a/tests/extmod/vfs_fat_ramdisklarge.py b/tests/extmod/vfs_fat_ramdisklarge.py
index 4ac52b257..69d4a8cbb 100644
--- a/tests/extmod/vfs_fat_ramdisklarge.py
+++ b/tests/extmod/vfs_fat_ramdisklarge.py
@@ -22,23 +22,23 @@ class RAMBDevSparse:
self.data = {}
def readblocks(self, n, buf):
- #print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
+ # print("readblocks(%s, %x(%d))" % (n, id(buf), len(buf)))
assert len(buf) == self.SEC_SIZE
if n not in self.data:
self.data[n] = bytearray(self.SEC_SIZE)
buf[:] = self.data[n]
def writeblocks(self, n, buf):
- #print("writeblocks(%s, %x)" % (n, id(buf)))
+ # print("writeblocks(%s, %x)" % (n, id(buf)))
mv = memoryview(buf)
for off in range(0, len(buf), self.SEC_SIZE):
s = n + off // self.SEC_SIZE
if s not in self.data:
self.data[s] = bytearray(self.SEC_SIZE)
- self.data[s][:] = mv[off:off + self.SEC_SIZE]
+ self.data[s][:] = mv[off : off + self.SEC_SIZE]
def ioctl(self, op, arg):
- #print("ioctl(%d, %r)" % (op, arg))
+ # print("ioctl(%d, %r)" % (op, arg))
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
return self.blocks
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
@@ -57,13 +57,13 @@ uos.mount(vfs, "/ramdisk")
print("statvfs:", vfs.statvfs("/ramdisk"))
-f = open('/ramdisk/test.txt', 'w')
-f.write('test file')
+f = open("/ramdisk/test.txt", "w")
+f.write("test file")
f.close()
print("statvfs:", vfs.statvfs("/ramdisk"))
-f = open('/ramdisk/test.txt')
+f = open("/ramdisk/test.txt")
print(f.read())
f.close()
diff --git a/tests/extmod/vfs_lfs.py b/tests/extmod/vfs_lfs.py
index 46c770b43..c3656fe68 100644
--- a/tests/extmod/vfs_lfs.py
+++ b/tests/extmod/vfs_lfs.py
@@ -2,12 +2,14 @@
try:
import uos
+
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
+
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
@@ -25,15 +27,16 @@ class RAMBlockDevice:
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
- if op == 4: # block count
+ if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
- if op == 5: # block size
+ if op == 5: # block size
return self.ERASE_BLOCK_SIZE
- if op == 6: # erase block
+ if op == 6: # erase block
return 0
+
def test(bdev, vfs_class):
- print('test', vfs_class)
+ print("test", vfs_class)
# mkfs
vfs_class.mkfs(bdev)
@@ -42,65 +45,66 @@ def test(bdev, vfs_class):
vfs = vfs_class(bdev)
# statvfs
- print(vfs.statvfs('/'))
+ print(vfs.statvfs("/"))
# open, write close
- f = vfs.open('test', 'w')
- f.write('littlefs')
+ f = vfs.open("test", "w")
+ f.write("littlefs")
f.close()
# statvfs after creating a file
- print(vfs.statvfs('/'))
+ print(vfs.statvfs("/"))
# ilistdir
print(list(vfs.ilistdir()))
- print(list(vfs.ilistdir('/')))
- print(list(vfs.ilistdir(b'/')))
+ print(list(vfs.ilistdir("/")))
+ print(list(vfs.ilistdir(b"/")))
# mkdir, rmdir
- vfs.mkdir('testdir')
+ vfs.mkdir("testdir")
print(list(vfs.ilistdir()))
- print(list(vfs.ilistdir('testdir')))
- vfs.rmdir('testdir')
+ print(list(vfs.ilistdir("testdir")))
+ vfs.rmdir("testdir")
print(list(vfs.ilistdir()))
- vfs.mkdir('testdir')
+ vfs.mkdir("testdir")
# stat a file
- print(vfs.stat('test'))
+ print(vfs.stat("test"))
# stat a dir (size seems to vary on LFS2 so don't print that)
- print(vfs.stat('testdir')[:6])
+ print(vfs.stat("testdir")[:6])
# read
- with vfs.open('test', 'r') as f:
+ with vfs.open("test", "r") as f:
print(f.read())
# create large file
- with vfs.open('testbig', 'w') as f:
- data = 'large012' * 32 * 16
- print('data length:', len(data))
+ with vfs.open("testbig", "w") as f:
+ data = "large012" * 32 * 16
+ print("data length:", len(data))
for i in range(4):
- print('write', i)
+ print("write", i)
f.write(data)
# stat after creating large file
- print(vfs.statvfs('/'))
+ print(vfs.statvfs("/"))
# rename
- vfs.rename('testbig', 'testbig2')
+ vfs.rename("testbig", "testbig2")
print(list(vfs.ilistdir()))
# remove
- vfs.remove('testbig2')
+ vfs.remove("testbig2")
print(list(vfs.ilistdir()))
# getcwd, chdir
print(vfs.getcwd())
- vfs.chdir('/testdir')
+ vfs.chdir("/testdir")
print(vfs.getcwd())
- vfs.chdir('/')
+ vfs.chdir("/")
print(vfs.getcwd())
- vfs.rmdir('testdir')
+ vfs.rmdir("testdir")
+
bdev = RAMBlockDevice(30)
test(bdev, uos.VfsLfs1)
diff --git a/tests/extmod/vfs_lfs_corrupt.py b/tests/extmod/vfs_lfs_corrupt.py
index 90c3e8216..330458709 100644
--- a/tests/extmod/vfs_lfs_corrupt.py
+++ b/tests/extmod/vfs_lfs_corrupt.py
@@ -2,12 +2,14 @@
try:
import uos
+
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
+
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
@@ -28,79 +30,83 @@ class RAMBlockDevice:
return self.ret
def ioctl(self, op, arg):
- if op == 4: # block count
+ if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
- if op == 5: # block size
+ if op == 5: # block size
return self.ERASE_BLOCK_SIZE
- if op == 6: # erase block
+ if op == 6: # erase block
return 0
+
def corrupt(bdev, block):
addr = block * bdev.ERASE_BLOCK_SIZE
for i in range(bdev.ERASE_BLOCK_SIZE):
- bdev.data[addr + i] = i & 0xff
+ bdev.data[addr + i] = i & 0xFF
+
def create_vfs(bdev, vfs_class):
bdev.ret = 0
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
- with vfs.open('f', 'w') as f:
+ with vfs.open("f", "w") as f:
for i in range(100):
- f.write('test')
+ f.write("test")
return vfs
+
def test(bdev, vfs_class):
- print('test', vfs_class)
+ print("test", vfs_class)
# statvfs
vfs = create_vfs(bdev, vfs_class)
corrupt(bdev, 0)
corrupt(bdev, 1)
try:
- print(vfs.statvfs(''))
+ print(vfs.statvfs(""))
except OSError:
- print('statvfs OSError')
+ print("statvfs OSError")
# error during read
vfs = create_vfs(bdev, vfs_class)
- f = vfs.open('f', 'r')
- bdev.ret = -5 # EIO
+ f = vfs.open("f", "r")
+ bdev.ret = -5 # EIO
try:
f.read(10)
except OSError:
- print('read OSError')
+ print("read OSError")
# error during write
vfs = create_vfs(bdev, vfs_class)
- f = vfs.open('f', 'a')
- bdev.ret = -5 # EIO
+ f = vfs.open("f", "a")
+ bdev.ret = -5 # EIO
try:
- f.write('test')
+ f.write("test")
except OSError:
- print('write OSError')
+ print("write OSError")
# error during close
vfs = create_vfs(bdev, vfs_class)
- f = vfs.open('f', 'w')
- f.write('test')
- bdev.ret = -5 # EIO
+ f = vfs.open("f", "w")
+ f.write("test")
+ bdev.ret = -5 # EIO
try:
f.close()
except OSError:
- print('close OSError')
+ print("close OSError")
# error during flush
vfs = create_vfs(bdev, vfs_class)
- f = vfs.open('f', 'w')
- f.write('test')
- bdev.ret = -5 # EIO
+ f = vfs.open("f", "w")
+ f.write("test")
+ bdev.ret = -5 # EIO
try:
f.flush()
except OSError:
- print('flush OSError')
+ print("flush OSError")
bdev.ret = 0
f.close()
+
bdev = RAMBlockDevice(30)
test(bdev, uos.VfsLfs1)
test(bdev, uos.VfsLfs2)
diff --git a/tests/extmod/vfs_lfs_error.py b/tests/extmod/vfs_lfs_error.py
index 793fae59e..717284ea0 100644
--- a/tests/extmod/vfs_lfs_error.py
+++ b/tests/extmod/vfs_lfs_error.py
@@ -2,12 +2,14 @@
try:
import uos
+
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
+
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
@@ -25,92 +27,94 @@ class RAMBlockDevice:
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
- if op == 4: # block count
+ if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
- if op == 5: # block size
+ if op == 5: # block size
return self.ERASE_BLOCK_SIZE
- if op == 6: # erase block
+ if op == 6: # erase block
return 0
+
def test(bdev, vfs_class):
- print('test', vfs_class)
+ print("test", vfs_class)
# mkfs with too-small block device
try:
vfs_class.mkfs(RAMBlockDevice(1))
except OSError:
- print('mkfs OSError')
+ print("mkfs OSError")
# mount with invalid filesystem
try:
vfs_class(bdev)
except OSError:
- print('mount OSError')
+ print("mount OSError")
# set up for following tests
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
- with vfs.open('testfile', 'w') as f:
- f.write('test')
- vfs.mkdir('testdir')
+ with vfs.open("testfile", "w") as f:
+ f.write("test")
+ vfs.mkdir("testdir")
# ilistdir
try:
- vfs.ilistdir('noexist')
+ vfs.ilistdir("noexist")
except OSError:
- print('ilistdir OSError')
+ print("ilistdir OSError")
# remove
try:
- vfs.remove('noexist')
+ vfs.remove("noexist")
except OSError:
- print('remove OSError')
+ print("remove OSError")
# rmdir
try:
- vfs.rmdir('noexist')
+ vfs.rmdir("noexist")
except OSError:
- print('rmdir OSError')
+ print("rmdir OSError")
# rename
try:
- vfs.rename('noexist', 'somethingelse')
+ vfs.rename("noexist", "somethingelse")
except OSError:
- print('rename OSError')
+ print("rename OSError")
# mkdir
try:
- vfs.mkdir('testdir')
+ vfs.mkdir("testdir")
except OSError:
- print('mkdir OSError')
+ print("mkdir OSError")
# chdir to nonexistent
try:
- vfs.chdir('noexist')
+ vfs.chdir("noexist")
except OSError:
- print('chdir OSError')
- print(vfs.getcwd()) # check still at root
+ print("chdir OSError")
+ print(vfs.getcwd()) # check still at root
# chdir to file
try:
- vfs.chdir('testfile')
+ vfs.chdir("testfile")
except OSError:
- print('chdir OSError')
- print(vfs.getcwd()) # check still at root
+ print("chdir OSError")
+ print(vfs.getcwd()) # check still at root
# stat
try:
- vfs.stat('noexist')
+ vfs.stat("noexist")
except OSError:
- print('stat OSError')
+ print("stat OSError")
# error during seek
- with vfs.open('testfile', 'r') as f:
- f.seek(1 << 30) # SEEK_SET
+ with vfs.open("testfile", "r") as f:
+ f.seek(1 << 30) # SEEK_SET
try:
- f.seek(1 << 30, 1) # SEEK_CUR
+ f.seek(1 << 30, 1) # SEEK_CUR
except OSError:
- print('seek OSError')
+ print("seek OSError")
+
bdev = RAMBlockDevice(30)
test(bdev, uos.VfsLfs1)
diff --git a/tests/extmod/vfs_lfs_file.py b/tests/extmod/vfs_lfs_file.py
index 477a62e2f..774cca296 100644
--- a/tests/extmod/vfs_lfs_file.py
+++ b/tests/extmod/vfs_lfs_file.py
@@ -2,12 +2,14 @@
try:
import uos
+
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
+
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
@@ -25,15 +27,16 @@ class RAMBlockDevice:
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
- if op == 4: # block count
+ if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
- if op == 5: # block size
+ if op == 5: # block size
return self.ERASE_BLOCK_SIZE
- if op == 6: # erase block
+ if op == 6: # erase block
return 0
+
def test(bdev, vfs_class):
- print('test', vfs_class)
+ print("test", vfs_class)
# mkfs
vfs_class.mkfs(bdev)
@@ -42,57 +45,57 @@ def test(bdev, vfs_class):
vfs = vfs_class(bdev)
# create text, print, write, close
- f = vfs.open('test.txt', 'wt')
+ f = vfs.open("test.txt", "wt")
print(f)
- f.write('littlefs')
+ f.write("littlefs")
f.close()
# close already-closed file
f.close()
# create binary, print, write, flush, close
- f = vfs.open('test.bin', 'wb')
+ f = vfs.open("test.bin", "wb")
print(f)
- f.write('littlefs')
+ f.write("littlefs")
f.flush()
f.close()
# create for append
- f = vfs.open('test.bin', 'ab')
- f.write('more')
+ f = vfs.open("test.bin", "ab")
+ f.write("more")
f.close()
# create exclusive
- f = vfs.open('test2.bin', 'xb')
+ f = vfs.open("test2.bin", "xb")
f.close()
# create exclusive with error
try:
- vfs.open('test2.bin', 'x')
+ vfs.open("test2.bin", "x")
except OSError:
- print('open OSError')
+ print("open OSError")
# read default
- with vfs.open('test.txt', '') as f:
+ with vfs.open("test.txt", "") as f:
print(f.read())
# read text
- with vfs.open('test.txt', 'rt') as f:
+ with vfs.open("test.txt", "rt") as f:
print(f.read())
# read binary
- with vfs.open('test.bin', 'rb') as f:
+ with vfs.open("test.bin", "rb") as f:
print(f.read())
# create read and write
- with vfs.open('test.bin', 'r+b') as f:
+ with vfs.open("test.bin", "r+b") as f:
print(f.read(8))
- f.write('MORE')
- with vfs.open('test.bin', 'rb') as f:
+ f.write("MORE")
+ with vfs.open("test.bin", "rb") as f:
print(f.read())
# seek and tell
- f = vfs.open('test.txt', 'r')
+ f = vfs.open("test.txt", "r")
print(f.tell())
f.seek(3, 0)
print(f.tell())
@@ -100,18 +103,19 @@ def test(bdev, vfs_class):
# open nonexistent
try:
- vfs.open('noexist', 'r')
+ vfs.open("noexist", "r")
except OSError:
- print('open OSError')
+ print("open OSError")
# open multiple files at the same time
- f1 = vfs.open('test.txt', '')
- f2 = vfs.open('test.bin', 'b')
+ f1 = vfs.open("test.txt", "")
+ f2 = vfs.open("test.bin", "b")
print(f1.read())
print(f2.read())
f1.close()
f2.close()
+
bdev = RAMBlockDevice(30)
test(bdev, uos.VfsLfs1)
test(bdev, uos.VfsLfs2)
diff --git a/tests/extmod/vfs_lfs_mount.py b/tests/extmod/vfs_lfs_mount.py
index 76263f497..7ac19184b 100644
--- a/tests/extmod/vfs_lfs_mount.py
+++ b/tests/extmod/vfs_lfs_mount.py
@@ -2,12 +2,14 @@
try:
import uos
+
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
+
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
@@ -25,15 +27,16 @@ class RAMBlockDevice:
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
- if op == 4: # block count
+ if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
- if op == 5: # block size
+ if op == 5: # block size
return self.ERASE_BLOCK_SIZE
- if op == 6: # erase block
+ if op == 6: # erase block
return 0
+
def test(bdev, vfs_class):
- print('test', vfs_class)
+ print("test", vfs_class)
# mkfs
vfs_class.mkfs(bdev)
@@ -42,31 +45,33 @@ def test(bdev, vfs_class):
vfs = vfs_class(bdev)
# mount
- uos.mount(vfs, '/lfs')
+ uos.mount(vfs, "/lfs")
# import
- with open('/lfs/lfsmod.py', 'w') as f:
+ with open("/lfs/lfsmod.py", "w") as f:
f.write('print("hello from lfs")\n')
import lfsmod
# import package
- uos.mkdir('/lfs/lfspkg')
- with open('/lfs/lfspkg/__init__.py', 'w') as f:
+ uos.mkdir("/lfs/lfspkg")
+ with open("/lfs/lfspkg/__init__.py", "w") as f:
f.write('print("package")\n')
import lfspkg
# umount
- uos.umount('/lfs')
+ uos.umount("/lfs")
# clear imported modules
sys.modules.clear()
+
bdev = RAMBlockDevice(30)
# initialise path
import sys
+
sys.path.clear()
-sys.path.append('/lfs')
+sys.path.append("/lfs")
# run tests
test(bdev, uos.VfsLfs1)
diff --git a/tests/extmod/vfs_userfs.py b/tests/extmod/vfs_userfs.py
index 7f6e48cb1..06e546b08 100644
--- a/tests/extmod/vfs_userfs.py
+++ b/tests/extmod/vfs_userfs.py
@@ -5,8 +5,10 @@ import sys
try:
import uio
+
uio.IOBase
import uos
+
uos.mount
except (ImportError, AttributeError):
print("SKIP")
@@ -17,8 +19,10 @@ class UserFile(uio.IOBase):
def __init__(self, data):
self.data = data
self.pos = 0
+
def read(self):
return self.data
+
def readinto(self, buf):
n = 0
while n < len(buf) and self.pos < len(self.data):
@@ -26,44 +30,49 @@ class UserFile(uio.IOBase):
n += 1
self.pos += 1
return n
+
def ioctl(self, req, arg):
- print('ioctl', req, arg)
+ print("ioctl", req, arg)
return 0
class UserFS:
def __init__(self, files):
self.files = files
+
def mount(self, readonly, mksfs):
pass
+
def umount(self):
pass
+
def stat(self, path):
- print('stat', path)
+ print("stat", path)
if path in self.files:
return (32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
raise OSError
+
def open(self, path, mode):
- print('open', path, mode)
+ print("open", path, mode)
return UserFile(self.files[path])
# create and mount a user filesystem
user_files = {
- '/data.txt': b"some data in a text file\n",
- '/usermod1.py': b"print('in usermod1')\nimport usermod2",
- '/usermod2.py': b"print('in usermod2')",
+ "/data.txt": b"some data in a text file\n",
+ "/usermod1.py": b"print('in usermod1')\nimport usermod2",
+ "/usermod2.py": b"print('in usermod2')",
}
-uos.mount(UserFS(user_files), '/userfs')
+uos.mount(UserFS(user_files), "/userfs")
# open and read a file
-f = open('/userfs/data.txt')
+f = open("/userfs/data.txt")
print(f.read())
# import files from the user filesystem
-sys.path.append('/userfs')
+sys.path.append("/userfs")
import usermod1
# unmount and undo path addition
-uos.umount('/userfs')
+uos.umount("/userfs")
sys.path.pop()
diff --git a/tests/extmod/websocket_basic.py b/tests/extmod/websocket_basic.py
index 6cc6f0fd1..10396e914 100644
--- a/tests/extmod/websocket_basic.py
+++ b/tests/extmod/websocket_basic.py
@@ -11,6 +11,7 @@ def ws_read(msg, sz):
ws = uwebsocket.websocket(uio.BytesIO(msg))
return ws.read(sz)
+
# do a websocket write and then return the raw data from the stream
def ws_write(msg, sz):
s = uio.BytesIO()
@@ -19,31 +20,32 @@ def ws_write(msg, sz):
s.seek(0)
return s.read(sz)
+
# basic frame
print(ws_read(b"\x81\x04ping", 4))
-print(ws_read(b"\x80\x04ping", 4)) # FRAME_CONT
+print(ws_read(b"\x80\x04ping", 4)) # FRAME_CONT
print(ws_write(b"pong", 6))
# split frames are not supported
# print(ws_read(b"\x01\x04ping", 4))
# extended payloads
-print(ws_read(b'\x81~\x00\x80' + b'ping' * 32, 128))
+print(ws_read(b"\x81~\x00\x80" + b"ping" * 32, 128))
print(ws_write(b"pong" * 32, 132))
# mask (returned data will be 'mask' ^ 'mask')
print(ws_read(b"\x81\x84maskmask", 4))
# close control frame
-s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE
+s = uio.BytesIO(b"\x88\x00") # FRAME_CLOSE
ws = uwebsocket.websocket(s)
print(ws.read(1))
s.seek(2)
print(s.read(4))
# misc control frames
-print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING
-print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG
+print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING
+print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG
# close method
ws = uwebsocket.websocket(uio.BytesIO())
@@ -51,8 +53,8 @@ ws.close()
# ioctl
ws = uwebsocket.websocket(uio.BytesIO())
-print(ws.ioctl(8)) # GET_DATA_OPTS
-print(ws.ioctl(9, 2)) # SET_DATA_OPTS
+print(ws.ioctl(8)) # GET_DATA_OPTS
+print(ws.ioctl(9, 2)) # SET_DATA_OPTS
print(ws.ioctl(9))
try:
ws.ioctl(-1)