twnet_parser/tests/chunk_header7_test.py

44 lines
1.3 KiB
Python

from twnet_parser.packet import \
ChunkHeaderParser
from twnet_parser.chunk_header import \
ChunkHeader
def test_chunk_header_unpack_vital1() -> None:
parser = ChunkHeaderParser()
header: ChunkHeader = parser.parse_header7(b'\x40\x10\x0a')
assert header.flags.resend is False
assert header.flags.vital is True
assert header.size == 16
assert header.seq == 10
def cmp_bytes_as_bin(got: bytes, expected: bytes) -> None:
g_bin = [format(int(x), '#010b') for x in got]
e_bin = [format(int(x), '#010b') for x in expected]
assert g_bin == e_bin
# TODO: uncomment when working
# def test_chunk_header_pack_vital1() -> None:
# header: ChunkHeader = ChunkHeader()
#
# header.flags.resend = False
# header.flags.vital = True
# header.size = 16
# header.seq = 10
#
# assert bytes([0b01000000, 0b00010000, 0b00001010]) == b'\x40\x10\x0a'
#
# cmp_bytes_as_bin(header.pack(), b'\x40\x10\x0a')
# assert header.pack() == b'\x40\x10\x0a'
def test_chunk_header_unpack_vital2() -> None:
parser = ChunkHeaderParser()
header: ChunkHeader = parser.parse_header7(b'\x40\x10\x09')
assert header.flags.resend is False
assert header.flags.vital is True
assert header.size == 16
assert header.seq == 9