diff --git a/tests/test_micromate_framing.py b/tests/test_micromate_framing.py index 2fe4396..3e72f81 100644 --- a/tests/test_micromate_framing.py +++ b/tests/test_micromate_framing.py @@ -444,12 +444,16 @@ def test_a_literal_0x10_in_data_round_trips(): assert _destuffed_payload(build_request(0x71, 0x082C, bytes(10), data))[16:] == data -def test_a_checksum_that_lands_on_an_escape_byte_is_escaped(): - # Pick the last data byte so SUM8 of the payload is exactly 0x03. +@pytest.mark.parametrize("target", [0x02, 0x03, 0x04, 0x10]) +def test_a_checksum_that_lands_on_an_escape_byte_is_escaped(target): + # Pick the last data byte so SUM8 of the payload is exactly `target`. If that + # byte is itself an escape byte the earlier bytes shift, but the last three + # on the wire stay DLE target ETX. head = bytes([0x10, 0x00, 0x7E, 0x00, 0x00, 0x7E]) + bytes(10) + b"\x01\x02" - last = (0x03 - sum(head)) & 0xFF + last = (target - sum(head)) & 0xFF f = build_request(0x7E, 0x007E, bytes(10), b"\x01\x02" + bytes([last])) - assert f[-3:] == bytes([DLE, 0x03, ETX]) + assert unstuff(f[2:-1])[-1] == target # the checksum byte itself + assert f[-3:] == bytes([DLE, target, ETX]) def test_without_data_the_frame_is_unchanged():