Skip to content

Commit 7d4bedf

Browse files
authored
test(lis2mdl,apds9960): Add mock scenarios for calibration, heading, gesture, and setters. (#302)
* test(lis2mdl): Add mock scenarios for calibration and heading logic. * test(apds9960): Add mock scenarios for gesture and setter/getter methods. * test(lis2mdl,apds9960): Fix Copilot review comments on mock tests.
1 parent 8ad7a4e commit 7d4bedf

2 files changed

Lines changed: 458 additions & 0 deletions

File tree

tests/scenarios/apds9960.yaml

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,232 @@ tests:
143143
expect_true: true
144144
mode: [mock]
145145

146+
# ----- Getter/Setter round-trips -----
147+
148+
- name: "Proximity gain round-trip"
149+
action: script
150+
script: |
151+
dev.set_proximity_gain(2)
152+
result = dev.get_proximity_gain() == 2
153+
expect_true: true
154+
mode: [mock]
155+
156+
- name: "Ambient light gain round-trip"
157+
action: script
158+
script: |
159+
dev.set_ambient_light_gain(2)
160+
result = dev.get_ambient_light_gain() == 2
161+
expect_true: true
162+
mode: [mock]
163+
164+
- name: "LED drive round-trip"
165+
action: script
166+
script: |
167+
dev.set_led_drive(1)
168+
result = dev.get_led_drive() == 1
169+
expect_true: true
170+
mode: [mock]
171+
172+
- name: "LED boost round-trip"
173+
action: script
174+
script: |
175+
dev.set_led_boost(2)
176+
result = dev.get_led_boost() == 2
177+
expect_true: true
178+
mode: [mock]
179+
180+
- name: "Proximity int low threshold round-trip"
181+
action: script
182+
script: |
183+
dev.set_prox_int_low_thresh(50)
184+
result = dev.get_prox_int_low_thresh() == 50
185+
expect_true: true
186+
mode: [mock]
187+
188+
- name: "Proximity int high threshold round-trip"
189+
action: script
190+
script: |
191+
dev.set_prox_int_high_thresh(200)
192+
result = dev.get_prox_int_high_thresh() == 200
193+
expect_true: true
194+
mode: [mock]
195+
196+
- name: "Gesture gain round-trip"
197+
action: script
198+
script: |
199+
dev.set_gesture_gain(2)
200+
result = dev.get_gesture_gain() == 2
201+
expect_true: true
202+
mode: [mock]
203+
204+
- name: "Gesture LED drive round-trip"
205+
action: script
206+
script: |
207+
dev.set_gesture_led_drive(1)
208+
result = dev.get_gesture_led_drive() == 1
209+
expect_true: true
210+
mode: [mock]
211+
212+
- name: "Gesture enter threshold round-trip"
213+
action: script
214+
script: |
215+
dev.set_gesture_enter_thresh(30)
216+
result = dev.get_gesture_enter_thresh() == 30
217+
expect_true: true
218+
mode: [mock]
219+
220+
- name: "Gesture exit threshold round-trip"
221+
action: script
222+
script: |
223+
dev.set_gesture_exit_thresh(20)
224+
result = dev.get_gesture_exit_thresh() == 20
225+
expect_true: true
226+
mode: [mock]
227+
228+
# ----- Gesture sensor enable/disable -----
229+
230+
- name: "Enable gesture sensor sets GEN bit"
231+
action: script
232+
script: |
233+
dev.enable_gesture_sensor(False)
234+
mode = dev.get_mode()
235+
has_gen = bool(mode & 0x40)
236+
has_pon = bool(mode & 0x01)
237+
result = has_gen and has_pon
238+
expect_true: true
239+
mode: [mock]
240+
241+
- name: "Disable gesture sensor clears GEN bit"
242+
action: script
243+
script: |
244+
dev.enable_gesture_sensor(False)
245+
dev.disable_gesture_sensor()
246+
mode = dev.get_mode()
247+
has_gen = bool(mode & 0x40)
248+
result = not has_gen
249+
expect_true: true
250+
mode: [mock]
251+
252+
- name: "is_gesture_available returns False when GSTATUS not set"
253+
action: script
254+
script: |
255+
# Mock GSTATUS (0xAF) not configured, so GVALID bit is 0
256+
result = dev.is_gesture_available() is False
257+
expect_true: true
258+
mode: [mock]
259+
260+
# ----- Power on/off -----
261+
262+
- name: "Power off clears PON bit"
263+
action: script
264+
script: |
265+
dev.power_on()
266+
dev.power_off()
267+
mode = dev.get_mode()
268+
result = not bool(mode & 0x01)
269+
expect_true: true
270+
mode: [mock]
271+
272+
- name: "Power on sets PON bit"
273+
action: script
274+
script: |
275+
dev.power_off()
276+
dev.power_on()
277+
mode = dev.get_mode()
278+
result = bool(mode & 0x01)
279+
expect_true: true
280+
mode: [mock]
281+
282+
# ----- Additional setter/getter round-trips -----
283+
284+
- name: "Gesture wait time round-trip"
285+
action: script
286+
script: |
287+
dev.set_gesture_wait_time(3)
288+
result = dev.get_gesture_wait_time() == 3
289+
expect_true: true
290+
mode: [mock]
291+
292+
- name: "Light int low threshold round-trip"
293+
action: script
294+
script: |
295+
dev.set_light_int_low_threshold(100)
296+
result = dev.get_light_int_low_threshold() == 100
297+
expect_true: true
298+
mode: [mock]
299+
300+
- name: "Light int high threshold round-trip"
301+
action: script
302+
script: |
303+
dev.set_light_int_high_threshold(5000)
304+
result = dev.get_light_int_high_threshold() == 5000
305+
expect_true: true
306+
mode: [mock]
307+
308+
- name: "Gesture mode round-trip"
309+
action: script
310+
script: |
311+
dev.set_gesture_mode(True)
312+
result = dev.get_gesture_mode() == True
313+
expect_true: true
314+
mode: [mock]
315+
316+
- name: "Proximity int enable round-trip"
317+
action: script
318+
script: |
319+
dev.set_proximity_int_enable(True)
320+
result = dev.get_proximity_int_enable() == True
321+
expect_true: true
322+
mode: [mock]
323+
324+
- name: "Ambient light int enable round-trip"
325+
action: script
326+
script: |
327+
dev.set_ambient_light_int_enable(True)
328+
result = dev.get_ambient_light_int_enable() == True
329+
expect_true: true
330+
mode: [mock]
331+
332+
- name: "data_ready returns True when status indicates valid data"
333+
action: script
334+
script: |
335+
# Mock STATUS register is 0x03 (AVALID + PVALID set)
336+
result = dev.data_ready() is True
337+
expect_true: true
338+
mode: [mock]
339+
340+
- name: "light_ready returns True when AVALID set"
341+
action: script
342+
script: |
343+
# Mock STATUS register is 0x03 (AVALID bit set)
344+
result = dev.light_ready() is True
345+
expect_true: true
346+
mode: [mock]
347+
348+
- name: "proximity_ready returns True when PVALID set"
349+
action: script
350+
script: |
351+
# Mock STATUS register is 0x03 (PVALID bit set)
352+
result = dev.proximity_ready() is True
353+
expect_true: true
354+
mode: [mock]
355+
356+
- name: "Green light returns int"
357+
action: script
358+
script: |
359+
dev.enable_light_sensor(False)
360+
result = isinstance(dev.green_light(), int)
361+
expect_true: true
362+
mode: [mock]
363+
364+
- name: "Blue light returns int"
365+
action: script
366+
script: |
367+
dev.enable_light_sensor(False)
368+
result = isinstance(dev.blue_light(), int)
369+
expect_true: true
370+
mode: [mock]
371+
146372
# ----- Hardware -----
147373

148374
- name: "Ambient light in plausible range"

0 commit comments

Comments
 (0)