From 5588647ad28ea51682fafab50b95ae9f161d18fe Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Thu, 24 Nov 2022 09:06:49 +0100 Subject: [PATCH 1/2] tests/misc/cexample_module: Test class presence. Now that the Timer class has been merged in a separate pull request, this can be added to the module test too. Signed-off-by: Laurens Valk --- tests/misc/cexample_module.py | 2 ++ tests/misc/cexample_module.py.exp | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/misc/cexample_module.py b/tests/misc/cexample_module.py index cf1d46f7509e5..c1da2ecf7ab24 100644 --- a/tests/misc/cexample_module.py +++ b/tests/misc/cexample_module.py @@ -7,8 +7,10 @@ raise SystemExit print(cexample) +print(cexample.__name__) d = dir(cexample) d.index("add_ints") +d.index("Timer") print(cexample.add_ints(1, 3)) diff --git a/tests/misc/cexample_module.py.exp b/tests/misc/cexample_module.py.exp index 81fcc2f2dda80..bb305060e90f8 100644 --- a/tests/misc/cexample_module.py.exp +++ b/tests/misc/cexample_module.py.exp @@ -1,2 +1,3 @@ +cexample 4 From 3c1a2a942a3264da7861891eb9852cdd2a889666 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Thu, 24 Nov 2022 08:58:10 +0100 Subject: [PATCH 2/2] tests/misc/cexample_class: Fix timing sensitivity. This test could occasionally fail because some operations take longer than expected. This relaxes the timing constraints and defers printing until the very end. Signed-off-by: Laurens Valk --- tests/misc/cexample_class.py | 16 ++++++++++------ tests/misc/cexample_class.py.exp | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/misc/cexample_class.py b/tests/misc/cexample_class.py index bdeb9a8cb21b2..6b8718ad8cc5f 100644 --- a/tests/misc/cexample_class.py +++ b/tests/misc/cexample_class.py @@ -7,14 +7,18 @@ print("SKIP") raise SystemExit -t = cexample.Timer() -print(t) -print(t.time() <= 1) +SLEEP_MS = 100 +TOLERANCE_MS = 20 + +timer = cexample.Timer() + +t_start = timer.time() time.sleep_ms(100) -elapsed = t.time() +t_end = timer.time() -if not (99 <= elapsed <= 110): - print("Elapsed time should be approx. 100ms but it is", elapsed) +print(timer) +print(0 <= t_start <= TOLERANCE_MS) +print(SLEEP_MS - TOLERANCE_MS <= t_end <= SLEEP_MS + TOLERANCE_MS) diff --git a/tests/misc/cexample_class.py.exp b/tests/misc/cexample_class.py.exp index 67d98761b0a64..b9a06602a316a 100644 --- a/tests/misc/cexample_class.py.exp +++ b/tests/misc/cexample_class.py.exp @@ -1,2 +1,3 @@ True +True