Example #1
0
 def test_encode_decode_round_trips(self, integer, prefix_bits):
     """
     Given valid data, the encoder and decoder can round trip.
     """
     encoded_result = encode_integer(integer, prefix_bits)
     decoded_integer, consumed = decode_integer(bytes(encoded_result),
                                                prefix_bits)
     assert integer == decoded_integer
     assert consumed > 0
Example #2
0
 def test_encode_decode_round_trips(self, integer, prefix_bits):
     """
     Given valid data, the encoder and decoder can round trip.
     """
     encoded_result = encode_integer(integer, prefix_bits)
     decoded_integer, consumed = decode_integer(
         bytes(encoded_result), prefix_bits
     )
     assert integer == decoded_integer
     assert consumed > 0
Example #3
0
 def test_decode_either_succeeds_or_raises_error(self, data, prefix_bits):
     """
     Attempting to decode data either returns a positive integer or throws a
     HPACKDecodingError.
     """
     try:
         result, consumed = decode_integer(data, prefix_bits)
     except HPACKDecodingError:
         pass
     else:
         assert isinstance(result, int)
         assert result >= 0
         assert consumed > 0
Example #4
0
 def test_decode_either_succeeds_or_raises_error(self, data, prefix_bits):
     """
     Attempting to decode data either returns a positive integer or throws a
     HPACKDecodingError.
     """
     try:
         result, consumed = decode_integer(data, prefix_bits)
     except HPACKDecodingError:
         pass
     else:
         assert isinstance(result, int)
         assert result >= 0
         assert consumed > 0
Example #5
0
 def test_decode_insufficient_data_fails(self):
     with pytest.raises(HPACKDecodingError):
         decode_integer(b'\x1f', 5)
Example #6
0
 def test_decode_empty_string_fails(self):
     with pytest.raises(HPACKDecodingError):
         decode_integer(b'', 8)
Example #7
0
 def test_encoding_42_with_8_bit_prefix(self):
     val = decode_integer(b'\x2a', 8)
     assert val == (42, 1)
Example #8
0
 def test_encoding_1337_with_5_bit_prefix(self):
     val = decode_integer(b'\x1f\x9a\x0a', 5)
     assert val == (1337, 3)
Example #9
0
 def test_decoding_10_with_5_bit_prefix(self):
     val = decode_integer(b'\x0a', 5)
     assert val == (10, 1)
Example #10
0
 def test_decode_fails_for_invalid_prefixes(self, prefix_bits):
     """
     If the prefix is out of the range [1,8], the encoder fails.
     """
     with pytest.raises(ValueError):
         decode_integer(b'\x00', prefix_bits)
Example #11
0
 def test_decode_fails_for_invalid_prefixes(self, prefix_bits):
     """
     If the prefix is out of the range [1,8], the encoder fails.
     """
     with pytest.raises(ValueError):
         decode_integer(b'\x00', prefix_bits)
Example #12
0
 def test_decode_insufficient_data_fails(self):
     with pytest.raises(HPACKDecodingError):
         decode_integer(b'\x1f', 5)
Example #13
0
 def test_decode_empty_string_fails(self):
     with pytest.raises(HPACKDecodingError):
         decode_integer(b'', 8)
Example #14
0
 def test_encoding_42_with_8_bit_prefix(self):
     val = decode_integer(b'\x2a', 8)
     assert val == (42, 1)
Example #15
0
 def test_encoding_1337_with_5_bit_prefix(self):
     val = decode_integer(b'\x1f\x9a\x0a', 5)
     assert val == (1337, 3)
Example #16
0
 def test_decoding_10_with_5_bit_prefix(self):
     val = decode_integer(b'\x0a', 5)
     assert val == (10, 1)