From ec9bbaff530ec209b29d9e85ee744facd6f79e71 Mon Sep 17 00:00:00 2001 From: Charly-sketch Date: Thu, 26 Mar 2026 16:04:51 +0100 Subject: [PATCH 1/2] 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." --- tests/scenarios/bq27441.yaml | 58 ++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/tests/scenarios/bq27441.yaml b/tests/scenarios/bq27441.yaml index 335374a2..216001d4 100644 --- a/tests/scenarios/bq27441.yaml +++ b/tests/scenarios/bq27441.yaml @@ -8,25 +8,36 @@ i2c: # Register values for mock tests # BQ27441 uses 2-byte little-endian registers read via struct.unpack(" set_capacity() -> writeExtendedData() +# The constructor calls power_on() -> set_capacity() -> write_extended_data() # which enters config mode (needs CFGUPMODE flag in FLAGS register). mock_registers: # CONTROL (0x00): status word (unsealed, INITCOMP set) 0x00: [0x80, 0x00] - # FLAGS (0x06): CFGUPMODE | BAT_DET | DSG — needed for enterConfig/exitConfig - 0x06: [0x19, 0x00] + + # TEMPERATURE (0x02): 298.1 K raw value + 0x02: [0xA5, 0x0B] + # VOLTAGE (0x04): 3700 mV 0x04: [0x74, 0x0E] + + # FLAGS (0x06): CFGUPMODE | BAT_DET | DSG + 0x06: [0x19, 0x00] + # REM_CAPACITY (0x0C): 600 mAh 0x0C: [0x58, 0x02] + # FULL_CAPACITY (0x0E): 650 mAh 0x0E: [0x8A, 0x02] + # AVG_CURRENT (0x10): 50 mA 0x10: [0x32, 0x00] + # AVG_POWER (0x18): 185 mW 0x18: [0xB9, 0x00] + # SOC (0x1C): 92% 0x1C: [0x5C, 0x00] + # SOH (0x20): 99% (low byte = percent, high byte = status) 0x20: [0x63, 0x00] @@ -67,6 +78,41 @@ tests: expect: 185 mode: [mock] + - name: "Read state of health" + action: call + method: state_of_health + expect: 99 + mode: [mock] + + - name: "Read flags register" + action: call + method: flags + expect: 25 + mode: [mock] + + - name: "Battery temperature returns float from mock data" + action: script + script: | + from bq27441.device import TempMeasureType + result = float(dev.temperature(TempMeasureType.BATTERY)) + expect: 2981.0 + mode: [mock] + + - name: "Device type validation returns true" + action: script + script: | + original_read_control_word = dev.read_control_word + + def fake_read_control_word(function): + if function == 0x01: + return 0x0421 + return original_read_control_word(function) + + dev.read_control_word = fake_read_control_word + result = dev.is_valid_device() + expect_true: true + mode: [mock] + - name: "Reset sends CONTROL_RESET command" action: script script: | @@ -78,12 +124,6 @@ tests: expect_true: true mode: [mock] - - name: "Read state of health" - action: call - method: state_of_health - expect: 99 - mode: [mock] - - name: "Battery connected check" action: manual prompt: "Une batterie est-elle connectée à la carte ?" From a7ace9f4b917e1f6d957252e3ddf1523dd81739f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20NEDJAR?= Date: Sat, 28 Mar 2026 06:58:20 +0100 Subject: [PATCH 2/2] test(bq27441): Fix Copilot review comments in mock scenarios. --- tests/scenarios/bq27441.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/scenarios/bq27441.yaml b/tests/scenarios/bq27441.yaml index 216001d4..ea2e1dfd 100644 --- a/tests/scenarios/bq27441.yaml +++ b/tests/scenarios/bq27441.yaml @@ -14,7 +14,7 @@ mock_registers: # CONTROL (0x00): status word (unsealed, INITCOMP set) 0x00: [0x80, 0x00] - # TEMPERATURE (0x02): 298.1 K raw value + # TEMPERATURE (0x02): raw 2981 (0.1 K units = 298.1 K) 0x02: [0xA5, 0x0B] # VOLTAGE (0x04): 3700 mV @@ -90,22 +90,23 @@ tests: expect: 25 mode: [mock] - - name: "Battery temperature returns float from mock data" + - name: "Battery temperature raw register value from mock data" action: script script: | from bq27441.device import TempMeasureType - result = float(dev.temperature(TempMeasureType.BATTERY)) - expect: 2981.0 + result = dev.temperature(TempMeasureType.BATTERY) + expect: 2981 mode: [mock] - name: "Device type validation returns true" action: script script: | + from bq27441.const import BQ27441_CONTROL_DEVICE_TYPE, BQ27441_DEVICE_ID original_read_control_word = dev.read_control_word def fake_read_control_word(function): - if function == 0x01: - return 0x0421 + if function == BQ27441_CONTROL_DEVICE_TYPE: + return BQ27441_DEVICE_ID return original_read_control_word(function) dev.read_control_word = fake_read_control_word