From bf2d96140b87f9901e0b227493f337f2e6e039f3 Mon Sep 17 00:00:00 2001 From: Timothy Allen Date: Sat, 10 Oct 2026 10:59:34 +0200 Subject: [PATCH] Test a failed JBD read collect_data returns False if requestMessage returns False or None, for the first request and for the second one. Before the earlier fix, these values raised TypeError and ended the server. --- tests/test_jbd_bms.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_jbd_bms.py b/tests/test_jbd_bms.py index 9896d9b..2e16414 100644 --- a/tests/test_jbd_bms.py +++ b/tests/test_jbd_bms.py @@ -528,6 +528,18 @@ class TestCollectData: result = collect_data(MagicMock()) assert result is False + @pytest.mark.parametrize("failed", [False, None]) + @pytest.mark.parametrize("first_ok", [False, True], ids=["0x03", "0x04"]) + def test_failed_read_returns_false(self, valid_03_response, failed, first_ok): + """requestMessage returns False or None for a port that it cannot read. + + len() of these values raised TypeError, which ended the server. + """ + responses = [bytes(valid_03_response), failed] if first_ok else [failed] + with patch("bmspy.jbd_bms.requestMessage", side_effect=responses) as request: + assert collect_data(MagicMock()) is False + assert request.call_count == len(responses) + def test_empty_04_response_returns_false(self, valid_03_response): responses = [bytes(valid_03_response), b""] idx = 0