micropython/tests/misc/cexample_class.py
Laurens Valk a67989aa20 examples/usercmodule: Add example of a native C class.
This shows how ports can add their own custom types/classes.

It is part of the unix coverage build, so we can use it for tests too.

Signed-off-by: Laurens Valk <laurens@pybricks.com>
2022-11-23 11:46:17 +11:00

21 lines
322 B
Python

# test custom native class
try:
import cexample
import time
except ImportError:
print("SKIP")
raise SystemExit
t = cexample.Timer()
print(t)
print(t.time() <= 1)
time.sleep_ms(100)
elapsed = t.time()
if not (99 <= elapsed <= 110):
print("Elapsed time should be approx. 100ms but it is", elapsed)