diff options
author | Laurens Valk <laurens@pybricks.com> | 2022-12-05 16:51:20 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-07-25 11:57:13 +1000 |
commit | 19b1333cb1376ef60376a07e8e76a41854014840 (patch) | |
tree | 71527e14bca10b0be10e2e52c655baa35f39dfe5 /tests/misc/cexample_class.py | |
parent | 7fe8f030eea0015962e729eae1f1c309dc83a469 (diff) |
examples/usercmodule/cexample: Add more advanced native class.
This adds a separate `AdvancedTimer` class that demonstrates a few more
advanced concepts usch as custom handlers for printing and attributes.
Signed-off-by: Laurens Valk <laurens@pybricks.com>
Diffstat (limited to 'tests/misc/cexample_class.py')
-rw-r--r-- | tests/misc/cexample_class.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/misc/cexample_class.py b/tests/misc/cexample_class.py index 6b8718ad8..06d741922 100644 --- a/tests/misc/cexample_class.py +++ b/tests/misc/cexample_class.py @@ -22,3 +22,20 @@ t_end = timer.time() print(timer) print(0 <= t_start <= TOLERANCE_MS) print(SLEEP_MS - TOLERANCE_MS <= t_end <= SLEEP_MS + TOLERANCE_MS) + +advanced_timer = cexample.AdvancedTimer() + +time.sleep_ms(100) + +print(repr(advanced_timer)) +print(str(advanced_timer)) + +print(advanced_timer.seconds) +advanced_timer.seconds = 123 +print(advanced_timer.seconds) +print(advanced_timer.time() < 123000 + TOLERANCE_MS) + +try: + advanced_timer.seconds = "bad input" +except TypeError: + print("TypeError") |