def test_missing_signature(): input_data = b'' with pytest.raises(ValueError) as e: raw_to_arrays(input_data, ()) assert str(e.value) == 'missing postgres signature'
def test_invalid_text(): input_data = postgres_signature + struct.pack( '>iihi1si1shi{}si1s'.format(len(postgres_signature)), 0, # flags 0, # extension area size # row 0 2, # field_count 1, # data_size b'\0', 1, # data_size b'\0', # row 1 2, # field_count len(postgres_signature) + 1, # data_size postgres_signature + b'\0', # postgres signature is invalid unicode 1, # data_size b'\1', ) # we put the invalid unicode as the first column to test that we can clean # up the cell in the second column before we have written a string there str_typeid = _typeid_map[np.dtype(object)] with pytest.raises(UnicodeDecodeError): raw_to_arrays(input_data, (str_typeid, str_typeid))
def test_missing_end_marker(): input_data = postgres_signature + (0).to_bytes(4, 'big') with pytest.raises(ValueError) as e: raw_to_arrays(input_data, ()) assert (str( e.value) == 'reading 4 bytes would cause an out of bounds access')
def test_missing_flags(): input_data = postgres_signature with pytest.raises(ValueError) as e: raw_to_arrays(input_data, ()) assert (str( e.value) == 'reading 4 bytes would cause an out of bounds access')
def test_invalid_date_size(): input_data = _pack_as_invalid_size_postgres_binary_data( 'i', # int32_t 4, (np.datetime64('2014-01-01', 'D') + _epoch_offset).view('int64'), ) dtype = np.dtype('datetime64[D]') with pytest.raises(ValueError) as e: raw_to_arrays(input_data, (_typeid_map[dtype], )) assert str(e.value) == 'mismatched date size: 3'
def test_invalid_datetime_size(): input_data = _pack_as_invalid_size_postgres_binary_data( 'q', # int64_t (quadword) 8, (pd.Timestamp('2014-01-01').to_datetime64().astype('datetime64[us]') + _epoch_offset).view('int64'), ) dtype = np.dtype('datetime64[us]') with pytest.raises(ValueError) as e: raw_to_arrays(input_data, (_typeid_map[dtype], )) assert str(e.value) == 'mismatched datetime size: 7'
def test_invalid_numeric_size(dtype): input_data = _pack_as_invalid_size_postgres_binary_data( dtype.char, dtype.itemsize, dtype.type(), ) with pytest.raises(ValueError) as e: raw_to_arrays(input_data, (_typeid_map[dtype], )) assert str(e.value) == 'mismatched %s size: %s' % ( dtype.name, dtype.itemsize - 1, )