def test_add(self, header, payload_length): payload = payload_length * b"\0" message = header + payload assert isinstance(message, bytes) assert len(message) == len(header) + len(payload) assert FetcherHeader.from_bytes(message) == header assert FetcherHeader.from_bytes(message[:len(header)]) == header assert message[len(header):] == payload
def header(self, stats): return FetcherHeader( FetcherType.TCP, PayloadType.AGENT, status=42, payload_length=69, stats_length=len(stats), )
def header(self, fetcher_type, payload_type, status, payload_length, stats_length): return FetcherHeader( fetcher_type, payload_type, status=status, payload_length=payload_length, stats_length=stats_length, )
def test_neq_other_payload_length(self, header, payload_length): other = payload_length + 1 assert other != header.payload_length assert header != FetcherHeader( header.fetcher_type, header.payload_type, status=header.status, payload_length=other, stats_length=header.stats_length, )
def test_neq_other_status(self, header, status): other = status + 1 assert other != header.status assert header != FetcherHeader( header.fetcher_type, header.payload_type, status=other, payload_length=header.payload_length, stats_length=header.stats_length, )
def test_neq_other_result_type(self, header): other = PayloadType.ERROR assert other != header.payload_type assert header != FetcherHeader( header.fetcher_type, other, status=header.status, payload_length=header.payload_length, stats_length=header.stats_length, )
def test_neq_other_payload_type(self, header): other = FetcherType.TCP assert other != header.payload_type assert header != FetcherHeader( other, payload_type=header.payload_type, status=header.status, payload_length=header.payload_length, stats_length=header.stats_length, )
def test_eq(self, header, fetcher_type, payload_type, status, payload_length, stats_length): assert header == bytes(header) assert bytes(header) == header assert bytes(header) == bytes(header) assert header == FetcherHeader( fetcher_type, payload_type, status=status, payload_length=payload_length, stats_length=stats_length, )
def fetcher_message(self, fetcher_payload, fetcher_stats): return FetcherMessage( FetcherHeader( FetcherType.TCP, PayloadType.AGENT, status=42, payload_length=len(fetcher_payload), stats_length=len(fetcher_stats), ), fetcher_payload, fetcher_stats, )
def test_from_bytes_failure(self): with pytest.raises(ValueError): FetcherHeader.from_bytes(b"random bytes")
def test_from_bytes_success(self, header): assert FetcherHeader.from_bytes(bytes(header) + 42 * b"*") == header