Skip to content

Commit 007cbdd

Browse files
committed
coverage: refine cuda.core coverage tests comments
1 parent 68191e4 commit 007cbdd

3 files changed

Lines changed: 14 additions & 30 deletions

File tree

cuda_core/tests/test_tensor_map.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,9 @@ def test_invalid_data_type(self, dev, skip_if_no_tma):
309309
)
310310

311311
def test_as_tensor_map_host_view_rejected_without_tma(self):
312-
"""``as_tensor_map`` on a non-device-accessible (host) view fails
313-
gracefully with a clear error, without needing TMA-capable hardware.
314-
315-
This drives the real ``as_tensor_map`` -> ``_from_tiled`` path: every
316-
keyword is assembled and the options are coerced before the
317-
device-accessibility guard rejects the host pointer, so no monkeypatching
318-
is required to cover the forwarding logic.
319-
"""
312+
"""``as_tensor_map`` rejects a non-device-accessible (host) view with a
313+
clear error, exercising the ``as_tensor_map`` -> ``_from_tiled`` path
314+
without needing TMA-capable hardware."""
320315
host = np.zeros((64, 64), dtype=np.float32)
321316
view = StridedMemoryView.from_any_interface(host, stream_ptr=-1)
322317
with pytest.raises(ValueError, match="device-accessible"):

cuda_core/tests/test_utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,11 +1077,9 @@ def test_view_as_cai_device_pointer_and_stream_ordering(init_cuda):
10771077
``stream`` differs from the consumer stream.
10781078
10791079
This only exercises the code path and checks *device* correctness (ptr,
1080-
device_id, shape); it does NOT verify stream-order correctness -- that would
1081-
need many queued kernels on the producer stream plus an observable
1082-
dependency on the consumer side. Uses a synthetic CAI object backed by a
1083-
genuine device allocation, so the cupy/numba-only device branch is exercised
1084-
without those optional deps.
1080+
device_id, shape); it does NOT verify stream-order correctness. Uses a
1081+
synthetic CAI object backed by a genuine device allocation, so the
1082+
cupy/numba-only device branch is exercised without those optional deps.
10851083
"""
10861084
dev = init_cuda
10871085
buffer = dev.memory_resource.allocate(64, stream=dev.default_stream)
@@ -1108,7 +1106,7 @@ def test_strided_memory_view_init_cai_path_deprecated(init_cuda):
11081106
"""The deprecated ``StridedMemoryView(obj)`` constructor routes a CAI-only
11091107
object through the CAI branch (warn + ``view_as_cai``), not the DLPack one."""
11101108
obj = _make_cuda_array_interface_obj(shape=(4,), strides=None, typestr="<f4", data=(0, False))
1111-
with pytest.deprecated_call(match="CUDA-array-interface-supporting"):
1109+
with pytest.deprecated_call(match="CUDA-array-interface-supporting object is deprecated"):
11121110
view = StridedMemoryView(obj, stream_ptr=-1)
11131111
assert view.is_device_accessible is True
11141112
assert view.shape == (4,)

cuda_core/tests/test_utils_dlpack.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

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
97
``__dlpack_c_exchange_api__`` C exchange-API helpers driven through ctypes.
10-
CAI-only behavior stays in ``test_utils.py``.
118
"""
129

1310
import ctypes
@@ -167,12 +164,8 @@ def test_from_dlpack_typeerror_fallback_unversioned_import():
167164
#
168165
# Drive the C function pointers exposed by the capsule the way a native
169166
# 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).
176169
# ---------------------------------------------------------------------------
177170

178171
_PyCapsule_GetPointer = ctypes.pythonapi.PyCapsule_GetPointer
@@ -312,13 +305,11 @@ def test_dlpack_c_exchange_api_to_py_object_null_tensor():
312305

313306

314307
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)."""
320310
api = _get_exchange_api()
321311
out = ctypes.c_void_p(123)
322312
with pytest.raises(NotImplementedError, match="not supported"):
313+
# Currently sets a Python error when `SetError` isn't passed.
323314
api.managed_tensor_allocator(None, ctypes.byref(out), None, None)
324315
assert not out.value # set to NULL before the error

0 commit comments

Comments
 (0)