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 # test that emergency exceptions work
import micropython
import sys import sys
try: try:
import io import io, micropython
except ImportError: except ImportError:
print("SKIP") print("SKIP")
raise SystemExit raise SystemExit

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,10 @@
import micropython try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
# Tests both code paths for built-in exception raising. # 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_varg (exception requires decompression at raise-time to format)

View File

@@ -1,4 +1,10 @@
import micropython 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 # 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). # locked (this can only work when the emergency exception buf is enabled).

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,12 @@
# String operations which don't require allocation # String operations which don't require allocation
import micropython
try:
import micropython
micropython.heap_lock
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
micropython.heap_lock() micropython.heap_lock()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,9 +1,10 @@
# tests meminfo functions in micropython module # tests meminfo functions in micropython module
import micropython try:
import micropython
# these functions are not always available micropython.mem_total
if not hasattr(micropython, "mem_total"): except (ImportError, AttributeError):
print("SKIP") print("SKIP")
raise SystemExit 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 # check we can get and set the level
micropython.opt_level(0) 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 # check that level 3 doesn't store line numbers
# the expected output is that any line is printed as "line 1" # the expected output is that any line is printed as "line 1"

View File

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

View File

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

View File

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

View File

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

View File

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