def init_counts(self, counts_len): """Called after instantiating with a compressed payload Params: counts_len counts size to use based on decoded settings in the header """ assert(self._data and counts_len and self.counts_len == 0) self.counts_len = counts_len self._init_counts() results = decode(self._data, payload_header_size, addressof(self.counts), counts_len) # no longer needed self._data = None return results
def init_counts(self, counts_len): '''Called after instantiating with a compressed payload Params: counts_len counts size to use based on decoded settings in the header ''' assert self._data and counts_len and self.counts_len == 0 self.counts_len = counts_len self._init_counts() results = decode(self._data, payload_header_size, addressof(self.counts), counts_len, self.word_size) # no longer needed self._data = None return results
def check_zz_identity(src_array, int_type, min_nz_index, max_nz_index, total_count, offset): dst_len = (sizeof(int_type) + 1) * ARRAY_SIZE dst = (c_uint8 * (offset + dst_len))() varint_len = encode(addressof(src_array), ARRAY_SIZE, sizeof(int_type), addressof(dst) + offset, dst_len) varint_string = string_at(dst, varint_len + offset) dst_array = (int_type * ARRAY_SIZE)() res = decode(varint_string, offset, addressof(dst_array), ARRAY_SIZE, sizeof(int_type)) assert(res['total'] == total_count) if total_count: assert(res['min_nonzero_index'] == min_nz_index) assert(res['max_nonzero_index'] == max_nz_index) for index in range(ARRAY_SIZE): assert(dst_array[index] == src_array[index])
def check_zz_identity(src_array, int_type, min_nz_index, max_nz_index, total_count, offset): dst_len = (sizeof(int_type) + 1) * ARRAY_SIZE dst = (c_uint8 * (offset + dst_len))() varint_len = encode(addressof(src_array), ARRAY_SIZE, sizeof(int_type), addressof(dst) + offset, dst_len) varint_string = string_at(dst, varint_len + offset) dst_array = (int_type * ARRAY_SIZE)() res = decode(varint_string, offset, addressof(dst_array), ARRAY_SIZE, sizeof(int_type)) assert res['total'] == total_count if total_count: assert res['min_nonzero_index'] == min_nz_index assert res['max_nonzero_index'] == max_nz_index for index in range(ARRAY_SIZE): assert dst_array[index] == src_array[index]
def test_zz_decode_errors(): with pytest.raises(TypeError): decode(None, None, 0, 0) dst_array = (c_uint16 * ARRAY_SIZE)() # negative array size with pytest.raises(IndexError): decode(b' ', 0, addressof(dst_array), -1, sizeof(c_uint16)) # invalid word size with pytest.raises(ValueError): decode(b' ', 0, addressof(dst_array), ARRAY_SIZE, 3) # read index negative with pytest.raises(IndexError): decode(b'', -1, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # Truncated end with pytest.raises(ValueError): decode(TRUNCATED_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # Too large positive value for this counter size with pytest.raises(OverflowError): decode(LARGE_POSITIVE_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # Negative overflow with pytest.raises(OverflowError): decode(LARGE_NEGATIVE_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # zero count skip index out of bounds with pytest.raises(IndexError): decode(INDEX_SKIPPER_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # read index too large => empty results res = decode(b'BUMMER', 8, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) assert res['total'] == 0
def test_zz_decode_errors(): with pytest.raises(TypeError): decode(None, None, 0, 0) dst_array = (c_uint16 * ARRAY_SIZE)() # negative array size with pytest.raises(IndexError): decode(b' ', 0, addressof(dst_array), -1, sizeof(c_uint16)) # invalid word size with pytest.raises(ValueError): decode(b' ', 0, addressof(dst_array), ARRAY_SIZE, 3) # read index negative with pytest.raises(IndexError): decode(b'', -1, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # Truncated end with pytest.raises(ValueError): decode(TRUNCATED_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # Too large positive value for this counter size with pytest.raises(OverflowError): decode(LARGE_POSITIVE_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # Negative overflow with pytest.raises(OverflowError): decode(LARGE_NEGATIVE_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # zero count skip index out of bounds with pytest.raises(IndexError): decode(INDEX_SKIPPER_VALUE, 0, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) # read index too large => empty results res = decode(b'BUMMER', 8, addressof(dst_array), ARRAY_SIZE, sizeof(c_uint16)) assert(res['total'] == 0)