Skip to content

Commit 17e99fd

Browse files
committed
tests: Fix multidriver board scenario to mount lib/ via mpremote.
1 parent 8bde63a commit 17e99fd

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

tests/runner/mpremote_bridge.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,21 @@ def run_script(
142142
last_line = output.strip().rsplit("\n", 1)[-1]
143143
return json.loads(last_line)
144144

145-
def run_raw_script(self, script):
145+
def run_raw_script(self, script, mount_dir=None):
146146
"""Run a raw MicroPython script on the board without driver context.
147147
148148
The script must set a ``result`` variable. Returns the
149149
JSON-decoded value of ``result``.
150+
151+
Args:
152+
mount_dir: optional local directory to mount on the board.
150153
"""
151154
code = (
152155
f"import json\n"
153156
f"{script}\n"
154157
f"print(json.dumps(result))"
155158
)
156-
output = self._run(code)
159+
output = self._run(code, mount_dir=mount_dir)
157160
last_line = output.strip().rsplit("\n", 1)[-1]
158161
return json.loads(last_line)
159162

tests/scenarios/board_temperature_comparison.yaml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ name: "Temperature comparison (all sensors)"
44
i2c:
55
id: 1
66

7+
# List of drivers needed — triggers mounting lib/ via mpremote
8+
drivers:
9+
- hts221
10+
- wsen-hids
11+
- wsen-pads
12+
- lis2mdl
13+
- bq27441
14+
715
tests:
816
- name: "Read all temperature sensors"
917
action: hardware_script
1018
script: |
1119
import sys
12-
sys.path.insert(0, '/flash/lib/hts221')
13-
sys.path.insert(0, '/flash/lib/wsen-hids')
14-
sys.path.insert(0, '/flash/lib/wsen-pads')
15-
sys.path.insert(0, '/flash/lib/lis2mdl')
16-
sys.path.insert(0, '/flash/lib/bq27441')
20+
sys.path.insert(0, '/remote/hts221')
21+
sys.path.insert(0, '/remote/wsen-hids')
22+
sys.path.insert(0, '/remote/wsen-pads')
23+
sys.path.insert(0, '/remote/lis2mdl')
24+
sys.path.insert(0, '/remote/bq27441')
1725
1826
from machine import I2C
1927
from time import sleep_ms
@@ -55,15 +63,15 @@ tests:
5563
# Print comparison table
5664
print('--- Temperature Comparison ---')
5765
for name, t in temps.items():
58-
print(f' {name:12s}: {t:6.2f} C')
66+
print(' ' + name.ljust(12) + ': ' + str(round(t, 2)) + ' C')
5967
6068
# Check all in plausible range
6169
all_ok = all(5.0 <= t <= 50.0 for t in temps.values())
6270
6371
# Check spread between dedicated thermometers
6472
dedicated = [temps['HTS221'], temps['WSEN-HIDS']]
6573
spread = max(dedicated) - min(dedicated)
66-
print(f' Spread (HTS221 vs WSEN-HIDS): {spread:.2f} C')
74+
print(' Spread (HTS221 vs WSEN-HIDS): ' + str(round(spread, 2)) + ' C')
6775
6876
result = all_ok and spread < 3.0
6977
expect_true: true
@@ -73,8 +81,8 @@ tests:
7381
action: hardware_script
7482
script: |
7583
import sys
76-
sys.path.insert(0, '/flash/lib/hts221')
77-
sys.path.insert(0, '/flash/lib/wsen-pads')
84+
sys.path.insert(0, '/remote/hts221')
85+
sys.path.insert(0, '/remote/wsen-pads')
7886
7987
from machine import I2C
8088
from time import sleep_ms
@@ -94,7 +102,7 @@ tests:
94102
t_pads = pads.temperature()
95103
96104
spread = abs(t_hts - t_pads)
97-
print(f' HTS221: {t_hts:.2f} C | WSEN-PADS: {t_pads:.2f} C | Spread: {spread:.2f} C')
105+
print(' HTS221: ' + str(round(t_hts, 2)) + ' C | WSEN-PADS: ' + str(round(t_pads, 2)) + ' C | Spread: ' + str(round(spread, 2)) + ' C')
98106
result = spread < 5.0
99107
expect_true: true
100108
mode: [hardware]

tests/test_scenarios.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ def test_scenario(scenario, test, mode, port):
172172
else:
173173
print(f" [INTERACTIVE] {pre_prompt}")
174174
if is_board:
175-
result = bridge.run_raw_script(test["script"])
175+
mount_dir = None
176+
if scenario.get("drivers"):
177+
mount_dir = Path(__file__).parent.parent / "lib"
178+
result = bridge.run_raw_script(
179+
test["script"], mount_dir=mount_dir,
180+
)
176181
else:
177182
result = bridge.run_script(
178183
scenario["driver"],

0 commit comments

Comments
 (0)