def test_datagram_init_length(length: int) -> None: """Test Datagram length attr initialization.""" if 0 <= length <= 0xff: datagrams.Datagram(length=length) else: with pt.raises(ValueError): datagrams.Datagram(length=length)
def test_datagram_init_seq(seq: int) -> None: """Test Datagram seq attr initialization.""" if 0 <= seq <= 0xff: datagrams.Datagram(seq=seq) else: with pt.raises(ValueError): datagrams.Datagram(seq=seq)
def test_datagram_generate(seq: int, length: int, payload: bytes, body: bytes) -> None: """Test Datagram generation of body.""" datagram = datagrams.Datagram() datagram.seq = seq datagram.length = length datagram.payload = payload assert datagram.compute_body() == body
def test_datagram_parse_invariants(seq: int, length: int, payload: bytes) -> None: """Test Datagram parse invariants.""" datagram = datagrams.Datagram() datagram.parse(bytes([seq, length]) + payload) assert datagram.seq == seq assert datagram.length == length assert datagram.payload == payload
def test_datagram_parse(seq: int, length: int, payload: bytes, body: bytes) -> None: """Test Datagram parsing from body.""" datagram = datagrams.Datagram() datagram.parse(body) assert datagram.seq == seq assert datagram.length == length assert datagram.payload == payload
def test_datagram_roundtrip(seq: int, length: int, payload: bytes, body: bytes) -> None: """Test Datagram parse/generate roundtrip.""" generate_datagram = datagrams.Datagram() generate_datagram.seq = seq generate_datagram.length = length generate_datagram.payload = payload generate_datagram.parse(generate_datagram.compute_body()) assert generate_datagram.seq == seq assert generate_datagram.length == length assert generate_datagram.payload == payload parse_datagram = datagrams.Datagram() parse_datagram.parse(generate_datagram.compute_body()) assert parse_datagram.seq == seq assert parse_datagram.length == length assert parse_datagram.payload == payload assert parse_datagram.compute_body() == body
def test_datagram_update(seq: int, length: int, payload: bytes, body: bytes) -> None: """Test Datagram updating from payload.""" datagram = datagrams.Datagram() datagram.seq = seq datagram.payload = payload datagram.update_from_payload() assert datagram.length == length assert datagram.compute_body() == body
def test_datagram_parse_invalid(body: bytes) -> None: """Test Datagram parse errors.""" datagram = datagrams.Datagram() with pt.raises(exceptions.ProtocolDataError): datagram.parse(body)