コード例 #1
0
ファイル: test_warp_prism.py プロジェクト: photi/warp_prism
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'
コード例 #2
0
ファイル: test_warp_prism.py プロジェクト: photi/warp_prism
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))
コード例 #3
0
ファイル: test_warp_prism.py プロジェクト: photi/warp_prism
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')
コード例 #4
0
ファイル: test_warp_prism.py プロジェクト: photi/warp_prism
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')
コード例 #5
0
ファイル: test_warp_prism.py プロジェクト: photi/warp_prism
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'
コード例 #6
0
ファイル: test_warp_prism.py プロジェクト: photi/warp_prism
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'
コード例 #7
0
ファイル: test_warp_prism.py プロジェクト: photi/warp_prism
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,
    )