Skip to content

Commit a14ce3b

Browse files
committed
tests: Add mock tests for WSEN-HIDS temperature calibration.
1 parent c51eafe commit a14ce3b

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/runner/executor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def run_action(action, driver_instance):
153153
method = getattr(driver_instance, method_name)
154154
return method(*args)
155155

156+
if action_type == "script":
157+
local_vars = {"dev": driver_instance}
158+
exec(action["script"], {}, local_vars)
159+
return local_vars.get("result")
160+
156161
if action_type == "hardware_script":
157162
# hardware_script is hardware-only; skip in mock mode
158163
return None

tests/scenarios/wsen_hids.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ tests:
7777
expect_range: [24.0, 26.0]
7878
mode: [mock]
7979

80+
- name: "Temperature with offset"
81+
action: script
82+
script: |
83+
dev.set_temp_offset(-2.0)
84+
result = dev.temperature()
85+
expect_range: [22.0, 24.0]
86+
mode: [mock]
87+
88+
- name: "Temperature with two-point calibration"
89+
action: script
90+
script: |
91+
dev.calibrate_temperature(20.0, 25.0, 30.0, 35.0)
92+
result = dev.temperature()
93+
expect_range: [19.0, 21.0]
94+
mode: [mock]
95+
8096
- name: "Humidity in plausible range"
8197
action: call
8298
method: humidity

tests/test_scenarios.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ def test_scenario(scenario, test, mode, port):
122122
print(f" {label}: {value} {unit}")
123123
prompt = test.get("prompt", "Manual check")
124124
result = prompt_yes_no(prompt)
125+
elif action == "script":
126+
if is_board:
127+
pytest.fail(
128+
"Board scenarios do not support 'script' action; "
129+
"use 'hardware_script' instead"
130+
)
131+
result = bridge.run_script(
132+
scenario["driver"],
133+
scenario["driver_class"],
134+
scenario["i2c"],
135+
test["script"],
136+
module_name=scenario.get("module_name"),
137+
hardware_init=scenario.get("hardware_init"),
138+
i2c_address=scenario.get("i2c_address"),
139+
)
125140
elif action in ("call", "read_register", "interactive"):
126141
if is_board:
127142
pytest.fail(

0 commit comments

Comments
 (0)