meshcore_py/tests
Matthew Wolter 2bf3f1b9dd fix: BATTERY handler drops frames shorter than 3 bytes (level field guard)
A BATTERY frame with len(data) < 3 caused dbuf.read(2) to return short
bytes; int.from_bytes(b"", ...) silently yielded 0, propagating a bogus
level=0 to HA sensors.  Same silent-zero class as N07 (storage fields).

Option B: early-return with debug log, matching the NEW-C pattern for
STATUS_RESPONSE.  No BATTERY event is dispatched for malformed frames.

Not in the original forensics report — discovered during G1 N07 work and
logged in issues_log.md.  Resolved here because no later branch touches
this handler.

Files changed:
- src/meshcore/reader.py: add `if len(data) < 3: return` guard before
  the level read in the BATTERY branch
- tests/unit/test_reader.py: add test_g1_battery_too_short_for_level —
  sends a 1-byte frame (type only), asserts no BATTERY event dispatched
  and debug log emitted
2026-04-11 19:24:26 -07:00
..
unit fix: BATTERY handler drops frames shorter than 3 bytes (level field guard) 2026-04-11 19:24:26 -07:00
README.md Added in some unit tests 2025-04-13 22:55:39 -07:00
test_ble_connection.py Implement BLE PIN pairing support for enhanced security 2025-09-24 00:21:30 +02:00
test_ble_pin_pairing.py Implement BLE PIN pairing support for enhanced security 2025-09-24 00:21:30 +02:00
test_meshcore_ble_pin.py Implement BLE PIN pairing support for enhanced security 2025-09-24 00:21:30 +02:00

MeshCore Tests

Running Tests

To run the tests, first install the development dependencies:

pip install -e ".[dev]"

Then run the tests using pytest:

# Run all tests
pytest

# Run tests with verbose output
pytest -v

# Run a specific test file
pytest tests/unit/test_commands.py

# Run a specific test
pytest tests/unit/test_commands.py::test_send_msg