MCPcopy Create free account
hub / github.com/apache/arrow / test_imported_batch_reader_error

Function test_imported_batch_reader_error

python/pyarrow/tests/test_cffi.py:508–539  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

506
507@needs_cffi
508def test_imported_batch_reader_error():
509 c_stream = ffi.new("struct ArrowArrayStream*")
510 ptr_stream = int(ffi.cast("uintptr_t", c_stream))
511
512 schema = pa.schema([('foo', pa.int32())])
513 batches = [pa.record_batch([[1, 2, 3]], schema=schema),
514 pa.record_batch([[4, 5, 6]], schema=schema)]
515 buf = make_serialized(schema, batches)
516
517 # Open a corrupt/incomplete stream and export it
518 reader = pa.ipc.open_stream(buf[:-16])
519 reader._export_to_c(ptr_stream)
520 del reader
521
522 reader_new = pa.RecordBatchReader._import_from_c(ptr_stream)
523 batch = reader_new.read_next_batch()
524 assert batch == batches[0]
525 with pytest.raises(OSError,
526 match="Expected to be able to read 16 bytes "
527 "for message body, got 8"):
528 reader_new.read_next_batch()
529
530 # Again, but call read_all()
531 reader = pa.ipc.open_stream(buf[:-16])
532 reader._export_to_c(ptr_stream)
533 del reader
534
535 reader_new = pa.RecordBatchReader._import_from_c(ptr_stream)
536 with pytest.raises(OSError,
537 match="Expected to be able to read 16 bytes "
538 "for message body, got 8"):
539 reader_new.read_all()
540
541
542@pytest.mark.parametrize('obj', [pa.int32(), pa.field('foo', pa.int32()),

Callers

nothing calls this directly

Calls 4

make_serializedFunction · 0.85
newMethod · 0.45
castMethod · 0.45
schemaMethod · 0.45

Tested by

no test coverage detected