Commit 86f75a9
ENH: Add comprehensive tests for itk.Image buffer protocol and lifetime
Add three test suites with automatic feature detection so they can be
cherry-picked into ITKv5.4.5 — tests for unavailable features are
skipped with descriptive messages rather than failing.
Feature detection at runtime:
- hasattr(image, '__buffer__'): PEP 688 (ITK 6.x)
- hasattr(image, '__array_interface__'): NumPy v3 interface (ITK 6.x)
- image.__array__(copy=None): NumPy 2.0 copy param (ITK 6.x)
- np.asarray zero-copy mutation test: zero-copy support (ITK 6.x)
itkImageTest.py (25-27 assertions depending on Python version):
- Basic __array__() and np.asarray() [all ITK versions]
- __buffer__() PEP 688: 2D/3D, UC/SS/F [skip if unavailable]
- memoryview(image) auto-dispatch [skip if Python < 3.12]
- np.asarray zero-copy mutation [skip if unavailable]
- __array__(copy=None/True/False) [skip if unavailable]
itkImageLifetimeTest.py (54-56 assertions):
- Deep copy: np.array(copy=True), array_from_image [all versions]
- __array__() zero-copy lifetime [skip if unavailable]
- np.asarray del-image safety [skip if unavailable]
- __buffer__/memoryview lifetime [skip if unavailable]
- Chained refs: slice, transpose, ravel [skip if unavailable]
- Filter pipeline output lifetime [skip if unavailable]
- Weak reference GC verification [skip if unavailable]
- Reference count verification [skip if unavailable]
- Circular reference detection [all versions]
- RSS memory growth (200x cycles) [all versions]
itkImageInteropTest.py (37 assertions when fully supported):
- NumPy: CT/MRI/DWI clinical sizes [all versions]
- Zero-copy assertions gated on HAS_ZEROCOPY [skip if unavailable]
- __array__(copy=...) protocol gated on HAS_ARRAY_COPY_PARAM
- PyTorch: 14 tests [optional, skip if not installed]
- Dask: 9 tests [optional, skip if not installed]
Co-Authored-By: Hans J. Johnson <hans-johnson@uiowa.edu>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 1e73a2b commit 86f75a9
4 files changed
Lines changed: 1298 additions & 6 deletions
File tree
- Modules/Core/Common/wrapping/test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
59 | 69 | | |
0 commit comments