|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | | -"""DLPack-focused tests for ``StridedMemoryView``. |
6 | | -
|
7 | | -Split out of ``test_utils.py`` (which had grown large): export/import |
8 | | -round-trips, capsule + deleter paths, ``from_dlpack`` error handling, and the |
| 5 | +"""DLPack tests for ``StridedMemoryView``: export/import round-trips, capsule + |
| 6 | +deleter paths, ``from_dlpack`` error handling, and the |
9 | 7 | ``__dlpack_c_exchange_api__`` C exchange-API helpers driven through ctypes. |
10 | | -CAI-only behavior stays in ``test_utils.py``. |
11 | 8 | """ |
12 | 9 |
|
13 | 10 | import ctypes |
@@ -167,12 +164,8 @@ def test_from_dlpack_typeerror_fallback_unversioned_import(): |
167 | 164 | # |
168 | 165 | # Drive the C function pointers exposed by the capsule the way a native |
169 | 166 | # consumer would, exercising the StridedMemoryView exchange-API implementation. |
170 | | -# |
171 | | -# The C functions report failure by setting a Python error and returning -1. |
172 | | -# Defining the pointers with PYFUNCTYPE (Python calling convention) lets ctypes |
173 | | -# propagate that real exception (TypeError/RuntimeError/NotImplementedError) |
174 | | -# instead of wrapping it in a SystemError, so the tests assert the meaningful |
175 | | -# type directly. |
| 167 | +# Pointers use PYFUNCTYPE so a failing call raises its real Python exception |
| 168 | +# (TypeError/RuntimeError/NotImplementedError). |
176 | 169 | # --------------------------------------------------------------------------- |
177 | 170 |
|
178 | 171 | _PyCapsule_GetPointer = ctypes.pythonapi.PyCapsule_GetPointer |
@@ -312,13 +305,11 @@ def test_dlpack_c_exchange_api_to_py_object_null_tensor(): |
312 | 305 |
|
313 | 306 |
|
314 | 307 | def test_dlpack_c_exchange_api_managed_tensor_allocator_not_supported(): |
315 | | - """``managed_tensor_allocator`` is unsupported (NotImplementedError). |
316 | | -
|
317 | | - The implementation sets a Python error even when no ``SetError`` callback is |
318 | | - passed, so with PYFUNCTYPE ctypes surfaces the NotImplementedError directly. |
319 | | - """ |
| 308 | + """Covers the ``managed_tensor_allocator`` entry point, which is unsupported |
| 309 | + and only ever raises NotImplementedError (StridedMemoryView never allocates).""" |
320 | 310 | api = _get_exchange_api() |
321 | 311 | out = ctypes.c_void_p(123) |
322 | 312 | with pytest.raises(NotImplementedError, match="not supported"): |
| 313 | + # Currently sets a Python error when `SetError` isn't passed. |
323 | 314 | api.managed_tensor_allocator(None, ctypes.byref(out), None, None) |
324 | 315 | assert not out.value # set to NULL before the error |
0 commit comments