def check_hdr_payload(counter_size): # Create an HdrPayload class with given counters count payload = HdrPayload(counter_size, HDR_PAYLOAD_COUNTS) # put some known numbers in the buckets fill_counts(payload, HDR_PAYLOAD_COUNTS) # get a compressed version of that payload cpayload = payload.compress(HDR_PAYLOAD_COUNTS) # now decompress it into a new hdr payload instance dpayload = HdrPayload(counter_size, compressed_payload=cpayload) dpayload.init_counts(HDR_PAYLOAD_COUNTS) # now verify that the counters are identical to the original check_counts(dpayload, HDR_PAYLOAD_COUNTS)
def test_hdr_payload_exceptions(): # test invalid zlib compressed buffer with pytest.raises(zlib.error): HdrPayload(2, compressed_payload=b'junk data') # unsupported word size with pytest.raises(ValueError): HdrPayload(1, HDR_PAYLOAD_COUNTS) with pytest.raises(ValueError): HdrPayload(1000, HDR_PAYLOAD_COUNTS) # invalid cookie payload = HdrPayload(8, HDR_PAYLOAD_COUNTS) payload.payload.cookie = 12345 cpayload = payload.compress(HDR_PAYLOAD_COUNTS) with pytest.raises(HdrCookieException): HdrPayload(2, compressed_payload=cpayload)
def test_hdr_payload_exceptions(): # test invalid zlib compressed buffer with pytest.raises(zlib.error): HdrPayload(2, compressed_payload=b'junk data') # unsupported word size with pytest.raises(ValueError): payload = HdrPayload(1, HDR_PAYLOAD_COUNTS) with pytest.raises(ValueError): payload = HdrPayload(1000, HDR_PAYLOAD_COUNTS) # invalid cookie payload = HdrPayload(8, HDR_PAYLOAD_COUNTS) payload.payload.cookie = 12345 cpayload = payload.compress(HDR_PAYLOAD_COUNTS) with pytest.raises(HdrCookieException): HdrPayload(2, compressed_payload=cpayload)
def check_hdr_payload(counter_size): # Create an HdrPayload class with given counters count payload = HdrPayload(counter_size, HDR_PAYLOAD_COUNTS) # put some known numbers in the buckets fill_counts(payload, HDR_PAYLOAD_COUNTS) # get a compressed version of that payload cpayload = payload.compress(HDR_PAYLOAD_COUNTS) # now decompress it into a new hdr payload instance dpayload = HdrPayload(counter_size, compressed_payload=cpayload) dpayload.init_counts(HDR_PAYLOAD_COUNTS) # now verify that the counters are identical to the original check_counts(dpayload, HDR_PAYLOAD_COUNTS) # run dump payload.dump(label='test')