Skip to content

Commit 1643d64

Browse files
committed
tests: Address Copilot review feedback on PR #49.
1 parent 6341c38 commit 1643d64

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

tests/runner/executor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def run_action(action, driver_instance):
112112

113113
if action_type == "interactive":
114114
# Prompt first, then call method (used for hold-button-and-read tests)
115+
import sys
116+
if not sys.stdin.isatty():
117+
return None # skip in non-interactive mode
115118
prompt = action.get("pre_prompt", "Perform action then press Enter")
116119
input(f"\n [INTERACTIVE] {prompt} ")
117120
method_name = action["method"]

tests/runner/mpremote_bridge.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ def run_script(
114114
The script has access to ``i2c`` and ``dev`` variables and must
115115
set a ``result`` variable. The method returns the JSON-decoded
116116
value of ``result``.
117+
118+
The script must not print anything: any additional output on
119+
stdout will cause JSON parsing to fail.
120+
121+
When ``hardware_init`` is provided it takes precedence over
122+
``i2c_address`` for device construction.
117123
"""
118124
mod = module_name or driver_name
119125
i2c_init = _i2c_init_code(i2c_config)
@@ -132,7 +138,9 @@ def run_script(
132138
f"print(json.dumps(result))"
133139
)
134140
output = self._run(code, mount_dir=self._driver_dir(driver_name))
135-
return json.loads(output)
141+
# Parse only the last non-empty line as JSON to ignore stray output
142+
last_line = output.strip().rsplit("\n", 1)[-1]
143+
return json.loads(last_line)
136144

137145
def scan_bus(self, i2c_config):
138146
"""Scan I2C bus and return list of addresses."""

tests/scenarios/mcp23009e.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ tests:
179179
from machine import Pin
180180
from time import sleep_ms, ticks_ms, ticks_diff
181181
led = Pin("LED_GREEN", Pin.OUT)
182-
dev._send_enable_interrupt(7)
182+
dev.interrupt_on_change(7, lambda l: None)
183183
dev.get_gpio()
184184
led.on()
185185
start = ticks_ms()
@@ -203,7 +203,7 @@ tests:
203203
from machine import Pin
204204
from time import sleep_ms, ticks_ms, ticks_diff
205205
led = Pin("LED_GREEN", Pin.OUT)
206-
dev._send_enable_interrupt(5)
206+
dev.interrupt_on_change(5, lambda l: None)
207207
dev.get_gpio()
208208
led.on()
209209
start = ticks_ms()
@@ -227,7 +227,7 @@ tests:
227227
from machine import Pin
228228
from time import sleep_ms, ticks_ms, ticks_diff
229229
led = Pin("LED_GREEN", Pin.OUT)
230-
dev._send_enable_interrupt(6)
230+
dev.interrupt_on_change(6, lambda l: None)
231231
dev.get_gpio()
232232
led.on()
233233
start = ticks_ms()
@@ -251,7 +251,7 @@ tests:
251251
from machine import Pin
252252
from time import sleep_ms, ticks_ms, ticks_diff
253253
led = Pin("LED_GREEN", Pin.OUT)
254-
dev._send_enable_interrupt(4)
254+
dev.interrupt_on_change(4, lambda l: None)
255255
dev.get_gpio()
256256
led.on()
257257
start = ticks_ms()

0 commit comments

Comments
 (0)