Skip to content

Commit

Permalink
Make tests compatible with 14.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Nov 8, 2023
1 parent 12400bc commit 2124c15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
__pycache__
LOCAL.txt
venv*/

45 changes: 24 additions & 21 deletions tests/test_in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
import pyarrow_hotfix


pa_version = tuple(map(int, pa.__version__.split('.')))

here = os.path.dirname(__file__)

ipc_file = os.path.join(here, 'data.arrow')
pq_file = os.path.join(here, 'data.pq')

is_pyarrow_0_14 = pa.__version__.startswith('0.14')
has_parquet_extension_support = pa_version >= (0, 15)

has_parquet_extension_support = not is_pyarrow_0_14
deserialization_disabled = pa_version >= (14, 0, 1)

require_parquet_extension_support = pytest.mark.skipif(
not has_parquet_extension_support,
Expand All @@ -33,7 +35,7 @@ def uninstalled_hotfix():


def assert_hotfix_functional(capsys, func, *args, **kwargs):
if is_pyarrow_0_14:
if pa_version < (0, 15):
table = func(*args, **kwargs)
expected_schema = pa.schema([pa.field('ext', pa.null())])
assert table.schema.equals(expected_schema, check_metadata=False)
Expand All @@ -46,6 +48,22 @@ def assert_hotfix_functional(capsys, func, *args, **kwargs):
assert captured.err == ""


def assert_hotfix_disabled(capsys, func, *args, **kwargs):
if not deserialization_disabled:
with uninstalled_hotfix():
with pytest.raises(Exception):
func(*args, **kwargs)
captured = capsys.readouterr()
assert captured.out.strip() == "hello world!"
assert captured.err == ""
else:
with uninstalled_hotfix():
func(*args, **kwargs)
captured = capsys.readouterr()
assert captured.out.strip() == ""
assert captured.err == ""


def read_ipc(ipc_file):
return pa.ipc.open_file(ipc_file).read_all()

Expand All @@ -64,22 +82,12 @@ def test_parquet(capsys):


def test_ipc_uninstalled(capsys):
with uninstalled_hotfix():
with pytest.raises(Exception):
read_ipc(ipc_file)
captured = capsys.readouterr()
assert captured.out.strip() == "hello world!"
assert captured.err == ""
assert_hotfix_disabled(capsys, read_ipc, ipc_file)


@require_parquet_extension_support
def test_parquet_uninstalled(capsys):
with uninstalled_hotfix():
with pytest.raises(Exception):
read_parquet(pq_file)
captured = capsys.readouterr()
assert captured.out.strip() == "hello world!"
assert captured.err == ""
assert_hotfix_disabled(capsys, read_parquet, pq_file)


def test_uninstall_reinstall(capsys):
Expand All @@ -92,12 +100,7 @@ def test_uninstall_reinstall(capsys):

def test_uninstalled_twice(capsys):
with uninstalled_hotfix():
pyarrow_hotfix.uninstall()
with pytest.raises(Exception):
read_ipc(ipc_file)
captured = capsys.readouterr()
assert captured.out.strip() == "hello world!"
assert captured.err == ""
assert_hotfix_disabled(capsys, read_ipc, ipc_file)


def test_reinstalled_twice(capsys):
Expand Down

0 comments on commit 2124c15

Please sign in to comment.