Skip to content

Commit 0225f78

Browse files
committed
tests: Use single keypress for manual test prompts.
1 parent 12ed6f5 commit 0225f78

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

tests/test_scenarios.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@
1717
SCENARIOS_DIR = Path(__file__).parent / "scenarios"
1818

1919

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+
2045
def _print_result(result, test):
2146
"""Print the measured value for report capture."""
2247
if isinstance(result, float):
@@ -108,8 +133,7 @@ def test_scenario(scenario, test, mode, port):
108133
else:
109134
print(f" {label}: {value} {unit}")
110135
prompt = test.get("prompt", "Manual check")
111-
response = input(f" [MANUAL] {prompt} [y/n] ")
112-
result = response.strip().lower() == "y"
136+
result = _prompt_yes_no(prompt)
113137
elif action == "call":
114138
result = bridge.call_method(
115139
scenario["driver"],

0 commit comments

Comments
 (0)