X-Git-Url: https://robinkrens.nl/gitweb/?a=blobdiff_plain;f=tests%2Ftest_parse.py;h=b18673d876c744bd89dd0508f018204b212837cb;hb=HEAD;hp=2aedd5c510e062ffde3b6e186269662f897eef11;hpb=5ef1572a84e6e6c7207ada35c0f17f2268fde26f;p=renesas-ra-flasher diff --git a/tests/test_parse.py b/tests/test_parse.py index 2aedd5c..b18673d 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -1,4 +1,4 @@ -from flasher.flasher import calc_sum, unpack_pkt, pack_pkt +from raflash.RAPacker import calc_sum, unpack_pkt, pack_pkt import pytest def test_calc_sum(): @@ -11,8 +11,16 @@ def test_unpack(): assert unpack_pkt(b'\x81\x00\x02\x12\x00\xEC\x03') == ['0x00'] assert unpack_pkt(b'\x81\x00\x02\x13\x00\xEB\x03') == ['0x00'] +def test_read_unpack(): + assert unpack_pkt(b'\x81\x00\x04\x15\xAA\xBB\xCC\xB6\x03') == ['0xAA', '0xBB', '0xCC'] + def test_pack_unpack(): - assert unpack_pkt(pack_pkt(0x13, ['0x00','0x01','0x02'])) == ['0x00', '0x01', '0x02'] - assert unpack_pkt(pack_pkt(0x34, ['0x00'])) == ['0x00'] - assert unpack_pkt(pack_pkt(0x00, ['0x00'])) == ['0x00'] - assert unpack_pkt(pack_pkt(0x12, ['0x00'])) == ['0x00'] + assert unpack_pkt(pack_pkt(0x13, ['0x00','0x01','0x02'], ack=True)) == ['0x00', '0x01', '0x02'] + assert unpack_pkt(pack_pkt(0x34, ['0x00'], ack=True)) == ['0x00'] + assert unpack_pkt(pack_pkt(0x00, ['0x00'], ack=True)) == ['0x00'] + assert unpack_pkt(pack_pkt(0x12, ['0x00'], ack=True)) == ['0x00'] + +def test_err_unpack(): + with pytest.raises(ValueError, match=r".*0xC3.*") as excinfo: + unpack_pkt(b'\x81\x00\x02\x93\xC3\x38\x03') + assert str(excinfo.value) == 'MCU encountered error 0xC3'