Skip to content

Commit 5aac341

Browse files
committed
tests: Address Copilot review feedback on PR #55.
1 parent 0225f78 commit 5aac341

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

tests/runner/executor.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55
from pathlib import Path
66

77

8+
def prompt_yes_no(prompt):
9+
"""Prompt user and wait for a single key: Enter=yes, Escape=no.
10+
11+
Returns True for yes, False for no.
12+
"""
13+
print(f" [MANUAL] {prompt} [Entree=oui / Echap=non] ", end="", flush=True)
14+
try:
15+
import tty
16+
import termios
17+
fd = sys.stdin.fileno()
18+
old = termios.tcgetattr(fd)
19+
try:
20+
tty.setraw(fd)
21+
ch = sys.stdin.read(1)
22+
finally:
23+
termios.tcsetattr(fd, termios.TCSADRAIN, old)
24+
print() # newline after keypress
25+
return ch in ("\r", "\n")
26+
except (ImportError, OSError):
27+
# Fallback for non-Unix or piped stdin
28+
response = input("")
29+
return response.strip().lower() in ("", "y", "yes")
30+
31+
832
def load_driver_mock(driver_name, fake_i2c, module_name=None):
933
"""Load a driver using FakeI2C on CPython.
1034
@@ -86,6 +110,7 @@ def cleanup_driver(driver_name, module_name=None):
86110
del sys.modules[mod_name]
87111
sys.modules.pop("machine", None)
88112
sys.modules.pop("micropython", None)
113+
sys.modules.pop("framebuf", None)
89114

90115

91116
def run_action(action, driver_instance):
@@ -109,8 +134,7 @@ def run_action(action, driver_instance):
109134

110135
if action_type == "manual":
111136
prompt = action.get("prompt", "Manual check required")
112-
from tests.test_scenarios import _prompt_yes_no
113-
return _prompt_yes_no(prompt)
137+
return prompt_yes_no(prompt)
114138

115139
if action_type == "interactive":
116140
# Prompt first, then call method (used for hold-button-and-read tests)

tests/test_scenarios.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,13 @@
1111
check_result,
1212
cleanup_driver,
1313
load_driver_mock,
14+
prompt_yes_no,
1415
run_action,
1516
)
1617

1718
SCENARIOS_DIR = Path(__file__).parent / "scenarios"
1819

1920

20-
def _prompt_yes_no(prompt):
21-
"""Prompt user and wait for a single key: Enter=yes, Escape=no.
22-
23-
Returns True for yes, False for no.
24-
"""
25-
import sys
26-
print(f" [MANUAL] {prompt} [Entree=oui / Echap=non] ", end="", flush=True)
27-
try:
28-
import tty
29-
import termios
30-
fd = sys.stdin.fileno()
31-
old = termios.tcgetattr(fd)
32-
try:
33-
tty.setraw(fd)
34-
ch = sys.stdin.read(1)
35-
finally:
36-
termios.tcsetattr(fd, termios.TCSADRAIN, old)
37-
print() # newline after keypress
38-
return ch in ("\r", "\n")
39-
except (ImportError, OSError):
40-
# Fallback for non-Unix or piped stdin
41-
response = input("")
42-
return response.strip().lower() != "n"
43-
44-
4521
def _print_result(result, test):
4622
"""Print the measured value for report capture."""
4723
if isinstance(result, float):
@@ -133,7 +109,7 @@ def test_scenario(scenario, test, mode, port):
133109
else:
134110
print(f" {label}: {value} {unit}")
135111
prompt = test.get("prompt", "Manual check")
136-
result = _prompt_yes_no(prompt)
112+
result = prompt_yes_no(prompt)
137113
elif action == "call":
138114
result = bridge.call_method(
139115
scenario["driver"],

0 commit comments

Comments
 (0)