Skip to content

Commit 80ab8fa

Browse files
committed
Cover the repr dunders with tests
1 parent b64d121 commit 80ab8fa

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

python/pyarrow/tests/test_flight.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@
4747
ServerAuthHandler, ClientAuthHandler,
4848
ServerMiddleware, ServerMiddlewareFactory,
4949
ClientMiddleware, ClientMiddlewareFactory,
50+
FlightCallOptions,
5051
)
5152
except ImportError:
5253
flight = None
5354
FlightClient, FlightServerBase = object, object
5455
ServerAuthHandler, ClientAuthHandler = object, object
5556
ServerMiddleware, ServerMiddlewareFactory = object, object
5657
ClientMiddleware, ClientMiddlewareFactory = object, object
58+
FlightCallOptions = object
5759

5860
# Marks all of the tests in this module
5961
# Ignore these with pytest ... -m 'not flight'
@@ -2536,3 +2538,41 @@ def received_headers(self, headers):
25362538
assert ("x-header-bin", b"header\x01value") in factory.headers
25372539
assert ("x-trailer", "trailer-value") in factory.headers
25382540
assert ("x-trailer-bin", b"trailer\x01value") in factory.headers
2541+
2542+
2543+
@pytest.fixture
2544+
def call_options_args(request):
2545+
match request.param:
2546+
case "default":
2547+
return {
2548+
"timeout": 3,
2549+
"headers": None,
2550+
"write_options": None,
2551+
"read_options": None,
2552+
}
2553+
case "all":
2554+
return {
2555+
"timeout": 7,
2556+
"headers": [(b"abc", b"def")],
2557+
"write_options": pa.ipc.IpcWriteOptions(compression="zstd"),
2558+
"read_options": pa.ipc.IpcReadOptions(use_threads=False),
2559+
}
2560+
2561+
2562+
@pytest.mark.parametrize(
2563+
"call_options_args", ["default", "all"], indirect=True)
2564+
def test_call_options_repr(call_options_args):
2565+
call_options = FlightCallOptions(**call_options_args)
2566+
repr = call_options.__repr__()
2567+
2568+
for arg, val in call_options_args.items():
2569+
if val is None:
2570+
continue
2571+
2572+
if arg not in ("read_options", "write_options"):
2573+
assert f"{arg}={val}" in repr
2574+
continue
2575+
2576+
val_repr = val.__repr__()
2577+
assert val_repr in repr
2578+

python/pyarrow/tests/test_ipc.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,3 +1338,79 @@ def test_record_batch_file_writer_with_empty_metadata():
13381338
buffer = sink.getvalue()
13391339
with pa.ipc.open_file(buffer) as r:
13401340
assert r.metadata is None
1341+
1342+
1343+
def check_ipc_options_repr(options_obj, options_args):
1344+
options = options_obj(**options_args)
1345+
repr = options.__repr__()
1346+
1347+
for arg, val in options_args.items():
1348+
if val is None:
1349+
continue
1350+
1351+
value = val if not isinstance(val, str) else f"\"{val}\""
1352+
1353+
if arg == "ensure_alignment":
1354+
value = pa.ipc.Alignment(val).name
1355+
elif arg == "metadata_version":
1356+
value = pa.ipc.MetadataVersion(val).name
1357+
1358+
assert f"{arg}={value}" in repr
1359+
1360+
1361+
@pytest.fixture
1362+
def write_options_args(request):
1363+
match request.param:
1364+
case "default":
1365+
return {
1366+
"allow_64bit": False,
1367+
"use_legacy_format": False,
1368+
"metadata_version": pa.ipc.MetadataVersion.V5,
1369+
"compression": None,
1370+
"use_threads": True,
1371+
"emit_dictionary_deltas": False,
1372+
"unify_dictionaries": False,
1373+
}
1374+
case "all":
1375+
return {
1376+
"allow_64bit": True,
1377+
"use_legacy_format": True,
1378+
"metadata_version": pa.ipc.MetadataVersion.V4,
1379+
"compression": "zstd",
1380+
"use_threads": False,
1381+
"emit_dictionary_deltas": True,
1382+
"unify_dictionaries": True,
1383+
}
1384+
1385+
1386+
@pytest.mark.parametrize(
1387+
"write_options_args", ["default", "all"], indirect=True)
1388+
def test_write_options_repr(write_options_args):
1389+
# https://github.com/apache/arrow/issues/47358
1390+
check_ipc_options_repr(pa.ipc.IpcWriteOptions, write_options_args)
1391+
1392+
1393+
@pytest.fixture
1394+
def read_options_args(request):
1395+
match request.param:
1396+
case "default":
1397+
return {
1398+
"ensure_native_endian": True,
1399+
"ensure_alignment": pa.ipc.Alignment.Any,
1400+
"use_threads": True,
1401+
"included_fields": None,
1402+
}
1403+
case "all":
1404+
return {
1405+
"ensure_native_endian": False,
1406+
"ensure_alignment": pa.ipc.Alignment.DataTypeSpecific,
1407+
"use_threads": False,
1408+
"included_fields": [1, 2, 3],
1409+
}
1410+
1411+
1412+
@pytest.mark.parametrize(
1413+
"read_options_args", ["default", "all"], indirect=True)
1414+
def test_read_options_repr(read_options_args):
1415+
# https://github.com/apache/arrow/issues/47358
1416+
check_ipc_options_repr(pa.ipc.IpcReadOptions, read_options_args)

0 commit comments

Comments
 (0)