@@ -171,21 +171,27 @@ tests:
171171
172172 # ----- Configuration -----
173173
174- - name : " Configure accel changes scale "
174+ - name : " Configure accel writes correct register value "
175175 action : script
176176 script : |
177177 from ism330dl.const import ACCEL_ODR_104HZ, ACCEL_FS_4G
178+ i2c.clear_write_log()
178179 dev.configure_accel(ACCEL_ODR_104HZ, ACCEL_FS_4G)
179- result = dev._accel_scale == ACCEL_FS_4G
180+ log = i2c.get_write_log()
181+ reg, data = log[-1]
182+ result = reg == 0x10 and data[0] == (0x04 << 4) | (0x02 << 2)
180183 expect_true : true
181184 mode : [mock]
182185
183- - name : " Configure gyro changes scale "
186+ - name : " Configure gyro writes correct register value "
184187 action : script
185188 script : |
186189 from ism330dl.const import GYRO_ODR_104HZ, GYRO_FS_500DPS
190+ i2c.clear_write_log()
187191 dev.configure_gyro(GYRO_ODR_104HZ, GYRO_FS_500DPS)
188- result = dev._gyro_scale == GYRO_FS_500DPS
192+ log = i2c.get_write_log()
193+ reg, data = log[-1]
194+ result = reg == 0x11 and data[0] == (0x04 << 4) | (0x01 << 2)
189195 expect_true : true
190196 mode : [mock]
191197
@@ -201,6 +207,18 @@ tests:
201207 expect_true : true
202208 mode : [mock]
203209
210+ - name : " Configure accel rejects invalid ODR"
211+ action : script
212+ script : |
213+ from ism330dl.const import ACCEL_FS_2G
214+ try:
215+ dev.configure_accel(99, ACCEL_FS_2G)
216+ result = False
217+ except Exception:
218+ result = True
219+ expect_true : true
220+ mode : [mock]
221+
204222 - name : " Configure gyro rejects invalid scale"
205223 action : script
206224 script : |
@@ -213,15 +231,28 @@ tests:
213231 expect_true : true
214232 mode : [mock]
215233
234+ - name : " Configure gyro rejects invalid ODR"
235+ action : script
236+ script : |
237+ from ism330dl.const import GYRO_FS_250DPS
238+ try:
239+ dev.configure_gyro(99, GYRO_FS_250DPS)
240+ result = False
241+ except Exception:
242+ result = True
243+ expect_true : true
244+ mode : [mock]
245+
216246 # ----- Power -----
217247
218248 - name : " Power down writes zero to CTRL registers"
219249 action : script
220250 script : |
251+ i2c.clear_write_log()
221252 dev.power_down()
222- ctrl1 = dev._read_u8(0x10 )
223- ctrl2 = dev._read_u8(0x11)
224- result = ctrl1 == 0 and ctrl2 == 0
253+ log = i2c.get_write_log( )
254+ writes = {reg: data[0] for reg, data in log}
255+ result = writes.get(0x10) == 0 and writes.get(0x11) == 0
225256 expect_true : true
226257 mode : [mock]
227258
@@ -230,11 +261,12 @@ tests:
230261 - name : " Reset sets BDU and IF_INC in CTRL3_C"
231262 action : script
232263 script : |
264+ i2c.clear_write_log()
233265 dev.reset()
234- ctrl3 = dev._read_u8(0x12 )
235- bdu = bool(ctrl3 & (1 << 6))
236- if_inc = bool(ctrl3 & (1 << 2) )
237- result = bdu and if_inc
266+ log = i2c.get_write_log( )
267+ ctrl3_writes = [data[0] for reg, data in log if reg == 0x12]
268+ bdu_if_inc = (1 << 6) | (1 << 2)
269+ result = len(ctrl3_writes) == 2 and ctrl3_writes[1] == bdu_if_inc
238270 expect_true : true
239271 mode : [mock]
240272
0 commit comments