from ah_wrapper.ah_parser import parse_packet
from ah_wrapper.ppp_stuffing import PPPUnstuff

data = [
    # REGULAR UART DATA
    [
        b"~\x12\xe7'\x11\x00b/+\x00\xd52&\x00\xa11\xe1\xff\x8c+\xac\xff\xb2\xdc\xfb\xffe\x0c\xee\x08\xa7\x01$\xfa\x10\xf6\xc6\x03\x00N~",
        b"~",
        b'\x12\x16(\x11\x00}^/"\x00\xd52&\x00\x8b1\xe1\xffi+\xb7\xff\n\xdd\xfa\xffF\x0b\xc4\x06\xa7\x01$\xfa\xc7\xf6\xd3\x03',
        b"\x00i~",
        b"~\x12\x16(\x11\x00}^/\"\x00\xda2E\x00s1\xe9\xffA+\xbf\xff \xdd\x08\x00F\x0b\xc4\x06\x08\x01\x97\xfa'\xf5r\x03\x00}^~",
        b"~\x12<(\x11\x00\x98/4\x00\xde2(\x00^1\xdd\xffA+\xbf\xff \xdd\x08",
        b"\x00\xe7\t\x9d\x06,\x01\xb9\xfa'\xf5r\x03\x00\xa8~",
    ],
    # RS485 NULL BEGINNING AND END DATA WITH MISSING BEGINNING OF FRAME CHAR LINE 5
    [
        b"",
        b'\x00~\x111"\xe5\xff\x84\x08&\x005"\xfe\xff\x8a\x08\xf9\xff\x9b\x19\x12\x00o\xe6\x10\x00\x8aP\t\xbc\xb02f\xa0\rb&"|\x10\x1e\xc8\x91^\xbd\x96,\x9b@K\x94q*\xf2A\x0c\xa6 \\\xf1!\x17\xa3\xa0\x0b\x88DNL\xf1\x15\x00F~\x00',
        b"",
        b'\x00~\x111"(\x00\x85\x08C\x005"\xde\xff\x8a\x08\xf9\xff\x9b\x19\x12\x00`\xe6\x10\x00\x8d\x10\t\xb8`3i0\x0ed\x96"}]@\x1e\xcaQ^\xbd\x96,\x9b@K\x94q*\xf2A\x0c\xa6 \\\xf1!\x17\xa3\xa0\x0b\x88DNL\xf1\x15\x00\xaa~\x00',
        b"",
        b"\x00|\xc2",
        b'\xff\xff5"\xff\xff\x8a\x08\xfe\xff\x9b\x19\xe3\xffc\xe6\xe3\xff\x8b0\t\xb7P3e\xb0\rd\x96"}]@\x1e\xcaQ^\xbf\xa6,\x9cPK\x94\x91*\xf2A\x0c\xa6 \\\xf1!\x17\xa6 \x0c\x8e\x84NRq\x16\x00\x17~\x00',
        b'\x00~\x111"\x19\x00\x85\x08\xff\xff5"\xff\xff\x8a\x08\xfd\xff\x9b\x19\x0c\x00f\xe6\xd6\xff\x8b0\t\xb7P3e\xb0\rd\x96"}]@\x1e\xcaQ^\xbf\xa6,\x9cPK\x94\x91*\xf7q\x0c\xa8p\\\xf3a\x17\xa6 \x0c\x8e\x84NRq\x16\x00/~\x00',
    ],
]

frames_per_bytearray = [[1, 1, 1, 2, 3, 3, 4], [0, 1, 1, 2, 2, 2, 2, 3]]


def test_mock_bytearrays():
    unstuffer = PPPUnstuff()
    for data_idx in range(len(data)):
        parsed_frames = 0
        for i in range(len(data[data_idx])):
            for b in data[data_idx][i]:
                unstuffed = unstuffer.unstuff_byte(b)
                if unstuffed:
                    parsed = parse_packet(unstuffed)
                    if parsed and parsed.valid:
                        parsed_frames += 1

            assert frames_per_bytearray[data_idx][i] == parsed_frames
