tests/micropython: Improve skipping of tests using micropython module.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-09-14 11:51:36 +10:00
parent 3de5a4c63c
commit 381cd730c8
32 changed files with 165 additions and 50 deletions

View File

@@ -1,10 +1,9 @@
# test that emergency exceptions work
import micropython
import sys
try:
import io
import io, micropython
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,4 +1,4 @@
Traceback (most recent call last):
, line 22, in f
, line 21, in f
ValueError: 1

View File

@@ -1,6 +1,10 @@
# test some extreme cases of allocating exceptions and tracebacks
try:
import micropython
except ImportError:
print("SKIP")
raise SystemExit
# Check for stackless build, which can't call functions without
# allocating a frame on the heap.

View File

@@ -1,6 +1,10 @@
# check that heap_lock/heap_unlock work as expected
try:
import micropython
except ImportError:
print("SKIP")
raise SystemExit
l = []
l2 = list(range(100))

View File

@@ -1,8 +1,10 @@
# test micropython.heap_locked()
try:
import micropython
if not hasattr(micropython, "heap_locked"):
micropython.heap_locked
except (AttributeError, ImportError):
print("SKIP")
raise SystemExit

View File

@@ -1,6 +1,10 @@
# check that we can do certain things without allocating heap memory
try:
import micropython
except ImportError:
print("SKIP")
raise SystemExit
# Check for stackless build, which can't call functions without
# allocating a frame on heap.

View File

@@ -1,5 +1,11 @@
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# Tests both code paths for built-in exception raising.
# mp_obj_new_exception_msg_varg (exception requires decompression at raise-time to format)
# mp_obj_new_exception_msg (decompression can be deferred)

View File

@@ -1,5 +1,11 @@
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# Does the full test from heapalloc_exc_compressed.py but while the heap is
# locked (this can only work when the emergency exception buf is enabled).

View File

@@ -1,7 +1,13 @@
# Test that we can raise and catch (preallocated) exception
# without memory allocation.
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
e = ValueError("error")

View File

@@ -1,7 +1,13 @@
# test handling of failed heap allocation with bytearray
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class GetSlice:
def __getitem__(self, idx):

View File

@@ -1,7 +1,13 @@
# test handling of failed heap allocation with dict
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# create dict
x = 1
micropython.heap_lock()

View File

@@ -1,7 +1,13 @@
# test handling of failed heap allocation with list
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class GetSlice:
def __getitem__(self, idx):

View File

@@ -1,7 +1,13 @@
# test handling of failed heap allocation with memoryview
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class GetSlice:
def __getitem__(self, idx):

View File

@@ -1,7 +1,13 @@
# test handling of failed heap allocation with set
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# create set
x = 1
micropython.heap_lock()

View File

@@ -1,7 +1,13 @@
# test handling of failed heap allocation with tuple
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# create tuple
x = 1
micropython.heap_lock()

View File

@@ -1,7 +1,14 @@
# Test that calling clazz.__call__() with up to at least 3 arguments
# doesn't require heap allocation.
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class Foo0:
def __call__(self):

View File

@@ -1,7 +1,14 @@
# Test that int.from_bytes() for small number of bytes generates
# small int.
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
micropython.heap_lock()
print(int.from_bytes(b"1", "little"))
print(int.from_bytes(b"12", "little"))

View File

@@ -1,6 +1,13 @@
# String operations which don't require allocation
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
micropython.heap_lock()
# Concatenating empty string returns original string

View File

@@ -1,6 +1,13 @@
# test super() operations which don't require allocation
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# Check for stackless build, which can't call functions without
# allocating a frame on heap.
try:

View File

@@ -1,10 +1,9 @@
# test that we can generate a traceback without allocating
import micropython
import sys
try:
import io
import io, micropython
except ImportError:
print("SKIP")
raise SystemExit

View File

@@ -1,5 +1,5 @@
StopIteration
Traceback (most recent call last):
File , line 25, in test
File , line 24, in test
StopIteration:

View File

@@ -1,7 +1,13 @@
# Check that yield-from can work without heap allocation
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# Yielding from a function generator
def sub_gen(a):

View File

@@ -1,10 +1,10 @@
# test the micropython.kbd_intr() function
try:
import micropython
try:
micropython.kbd_intr
except AttributeError:
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit

View File

@@ -1,9 +1,10 @@
# tests meminfo functions in micropython module
try:
import micropython
# these functions are not always available
if not hasattr(micropython, "mem_info"):
micropython.mem_info
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit

View File

@@ -1,9 +1,10 @@
# tests meminfo functions in micropython module
try:
import micropython
# these functions are not always available
if not hasattr(micropython, "mem_total"):
micropython.mem_total
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit

View File

@@ -1,4 +1,10 @@
import micropython as micropython
# test micropython.opt_level()
try:
import micropython
except ImportError:
print("SKIP")
raise SystemExit
# check we can get and set the level
micropython.opt_level(0)

View File

@@ -1,4 +1,10 @@
import micropython as micropython
# test micropython.opt_level() and line numbers
try:
import micropython
except ImportError:
print("SKIP")
raise SystemExit
# check that level 3 doesn't store line numbers
# the expected output is that any line is printed as "line 1"

View File

@@ -1,10 +1,10 @@
# Check that micropython.RingIO works correctly.
try:
import micropython
try:
micropython.RingIO
except AttributeError:
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit

View File

@@ -1,9 +1,7 @@
# Check that micropython.RingIO works correctly with asyncio.Stream.
import micropython
try:
import asyncio
import asyncio, micropython
asyncio.StreamWriter
micropython.RingIO

View File

@@ -1,10 +1,10 @@
# Check that micropython.RingIO works correctly.
try:
import micropython
try:
micropython.RingIO
except AttributeError:
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit

View File

@@ -1,10 +1,10 @@
# test micropython.schedule() function
try:
import micropython
try:
micropython.schedule
except AttributeError:
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit

View File

@@ -1,7 +1,10 @@
# tests stack_use function in micropython module
try:
import micropython
if not hasattr(micropython, "stack_use"):
micropython.stack_use
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit