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:474–504  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

472
473@needs_cffi
474def test_export_import_exception_reader():
475 # See: https://github.com/apache/arrow/issues/37164
476 c_stream = ffi.new("struct ArrowArrayStream*")
477 ptr_stream = int(ffi.cast("uintptr_t", c_stream))
478
479 gc.collect() # Make sure no Arrow data dangles in a ref cycle
480 old_allocated = pa.total_allocated_bytes()
481
482 def gen():
483 if True:
484 try:
485 raise ValueError('foo')
486 except ValueError as e:
487 raise NotImplementedError('bar') from e
488 else:
489 yield from make_batches()
490
491 original = pa.RecordBatchReader.from_batches(make_schema(), gen())
492 original._export_to_c(ptr_stream)
493
494 reader = pa.RecordBatchReader._import_from_c(ptr_stream)
495 with pytest.raises(NotImplementedError) as exc_info:
496 reader.read_next_batch()
497
498 # inner *and* outer exception should be present
499 assert 'ValueError: foo' in str(exc_info.value)
500 assert 'NotImplementedError: bar' in str(exc_info.value)
501 # Stacktrace containing line of the raise statement
502 assert 'raise ValueError(\'foo\')' in str(exc_info.value)
503
504 assert pa.total_allocated_bytes() == old_allocated
505
506
507@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