Skip to content

Commit 202cde1

Browse files
tests: Add mock scenarios for bq27441 missing methods. (#253)
* test(bq27441): add missing mock coverage Add mock tests for is_valid_device(), temperature(), and flags() in tests/scenarios/bq27441.yaml. Extend mock_registers with the values needed for the new read paths and keep the existing scenario structure unchanged. This improves mock coverage for basic device validation and additional battery data reads without affecting current tests." * test(bq27441): Fix Copilot review comments in mock scenarios. --------- Co-authored-by: Sébastien NEDJAR <sebastien@nedjar.com>
1 parent ad2e1fd commit 202cde1

1 file changed

Lines changed: 50 additions & 9 deletions

File tree

tests/scenarios/bq27441.yaml

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,36 @@ i2c:
88

99
# Register values for mock tests
1010
# BQ27441 uses 2-byte little-endian registers read via struct.unpack("<h")
11-
# The constructor calls power_on() -> set_capacity() -> writeExtendedData()
11+
# The constructor calls power_on() -> set_capacity() -> write_extended_data()
1212
# which enters config mode (needs CFGUPMODE flag in FLAGS register).
1313
mock_registers:
1414
# CONTROL (0x00): status word (unsealed, INITCOMP set)
1515
0x00: [0x80, 0x00]
16-
# FLAGS (0x06): CFGUPMODE | BAT_DET | DSG — needed for enterConfig/exitConfig
17-
0x06: [0x19, 0x00]
16+
17+
# TEMPERATURE (0x02): raw 2981 (0.1 K units = 298.1 K)
18+
0x02: [0xA5, 0x0B]
19+
1820
# VOLTAGE (0x04): 3700 mV
1921
0x04: [0x74, 0x0E]
22+
23+
# FLAGS (0x06): CFGUPMODE | BAT_DET | DSG
24+
0x06: [0x19, 0x00]
25+
2026
# REM_CAPACITY (0x0C): 600 mAh
2127
0x0C: [0x58, 0x02]
28+
2229
# FULL_CAPACITY (0x0E): 650 mAh
2330
0x0E: [0x8A, 0x02]
31+
2432
# AVG_CURRENT (0x10): 50 mA
2533
0x10: [0x32, 0x00]
34+
2635
# AVG_POWER (0x18): 185 mW
2736
0x18: [0xB9, 0x00]
37+
2838
# SOC (0x1C): 92%
2939
0x1C: [0x5C, 0x00]
40+
3041
# SOH (0x20): 99% (low byte = percent, high byte = status)
3142
0x20: [0x63, 0x00]
3243

@@ -67,6 +78,42 @@ tests:
6778
expect: 185
6879
mode: [mock]
6980

81+
- name: "Read state of health"
82+
action: call
83+
method: state_of_health
84+
expect: 99
85+
mode: [mock]
86+
87+
- name: "Read flags register"
88+
action: call
89+
method: flags
90+
expect: 25
91+
mode: [mock]
92+
93+
- name: "Battery temperature raw register value from mock data"
94+
action: script
95+
script: |
96+
from bq27441.device import TempMeasureType
97+
result = dev.temperature(TempMeasureType.BATTERY)
98+
expect: 2981
99+
mode: [mock]
100+
101+
- name: "Device type validation returns true"
102+
action: script
103+
script: |
104+
from bq27441.const import BQ27441_CONTROL_DEVICE_TYPE, BQ27441_DEVICE_ID
105+
original_read_control_word = dev.read_control_word
106+
107+
def fake_read_control_word(function):
108+
if function == BQ27441_CONTROL_DEVICE_TYPE:
109+
return BQ27441_DEVICE_ID
110+
return original_read_control_word(function)
111+
112+
dev.read_control_word = fake_read_control_word
113+
result = dev.is_valid_device()
114+
expect_true: true
115+
mode: [mock]
116+
70117
- name: "Reset sends CONTROL_RESET command"
71118
action: script
72119
script: |
@@ -78,12 +125,6 @@ tests:
78125
expect_true: true
79126
mode: [mock]
80127

81-
- name: "Read state of health"
82-
action: call
83-
method: state_of_health
84-
expect: 99
85-
mode: [mock]
86-
87128
- name: "Battery connected check"
88129
action: manual
89130
prompt: "Une batterie est-elle connectée à la carte ?"

0 commit comments

Comments
 (0)