mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
tests/micropython: Improve skipping of tests using micropython module.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Traceback (most recent call last):
|
||||
, line 22, in f
|
||||
, line 21, in f
|
||||
ValueError: 1
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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).
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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"))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
StopIteration
|
||||
Traceback (most recent call last):
|
||||
File , line 25, in test
|
||||
File , line 24, in test
|
||||
StopIteration:
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# test micropython.schedule() function
|
||||
|
||||
try:
|
||||
import micropython
|
||||
|
||||
try:
|
||||
micropython.schedule
|
||||
except AttributeError:
|
||||
except (ImportError, AttributeError):
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user