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

Function test_export_import_exception_reader

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

Source from the content-addressed store, hash-verified

505
506@needs_cffi
507def test_export_import_exception_reader():
508 # See: https://github.com/apache/arrow/issues/37164
509 c_stream = ffi.new("struct ArrowArrayStream*")
510 ptr_stream = int(ffi.cast("uintptr_t", c_stream))
511
512 gc.collect() # Make sure no Arrow data dangles in a ref cycle
513 old_allocated = pa.total_allocated_bytes()
514
515 def gen():
516 if True:
517 try:
518 raise ValueError('foo')
519 except ValueError as e:
520 raise NotImplementedError('bar') from e
521 else:
522 yield from make_batches()
523
524 original = pa.RecordBatchReader.from_batches(make_schema(), gen())
525 original._export_to_c(ptr_stream)
526
527 reader = pa.RecordBatchReader._import_from_c(ptr_stream)
528 with pytest.raises(NotImplementedError) as exc_info:
529 reader.read_next_batch()
530
531 # inner *and* outer exception should be present
532 assert 'ValueError: foo' in str(exc_info.value)
533 assert 'NotImplementedError: bar' in str(exc_info.value)
534 # Stacktrace containing line of the raise statement
535 assert 'raise ValueError(\'foo\')' in str(exc_info.value)
536
537 assert pa.total_allocated_bytes() == old_allocated
538
539
540@needs_cffi

Callers

nothing calls this directly

Calls 4

genFunction · 0.85
make_schemaFunction · 0.70
newMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected