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>
This commit is contained in:
Laurens Valk
2022-11-21 14:10:02 +01:00
committed by Damien George
parent 1d27c7d423
commit a67989aa20
4 changed files with 95 additions and 3 deletions

View File

@@ -0,0 +1,20 @@
# 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)