Skip to content

Commit 0d06b66

Browse files
committed
Add tests
1 parent d5605a2 commit 0d06b66

7 files changed

Lines changed: 48 additions & 6 deletions

File tree

‎cuda_core/cuda/core/_memoryview.pyi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class StridedMemoryView:
170170
individual keyword arguments directly, or provide bundled tiled
171171
options via ``options=``.
172172
"""
173-
def copy_from(self, other: StridedMemoryView, stream: Stream, allocator: object | None=None, blocking: bool | None=None) -> None:
173+
def copy_from(self, other: StridedMemoryView, stream: Stream | None, allocator: object | None=None, blocking: bool | None=None) -> None:
174174
"""
175175
Copies the data from the other view into this view.
176176

‎cuda_core/cuda/core/_memoryview.pyx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ cdef class StridedMemoryView:
419419
def copy_from(
420420
self,
421421
StridedMemoryView other not None: StridedMemoryView,
422-
stream not None: Stream,
422+
stream: Stream | None,
423423
allocator: object = None,
424424
blocking: bool | None = None,
425425
) -> None:

‎cuda_core/cuda/core/graph/_adjacency_set_proxy.pyi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AdjacencySetProxy(MutableSet[GraphNode]):
2323
def __iter__(self) -> Iterator[GraphNode]: ...
2424
def __len__(self) -> int: ...
2525
def add(self, value: GraphNode) -> None: ...
26-
def discard(self, value: GraphNode) -> None: ...
26+
def discard(self, value: object) -> None: ...
2727
def clear(self) -> None:
2828
"""Remove all edges in a single driver call."""
2929
def __isub__(self, it: Set[Any]) -> AdjacencySetProxy:

‎cuda_core/cuda/core/graph/_adjacency_set_proxy.pyx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from cuda.core._rt cimport (
1515
graph_node_get_graph,
1616
)
1717
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN
18-
import cython
1918
from collections.abc import Iterable, Iterator, MutableSet, Set
2019
from typing import Any, TypeVar
2120

@@ -60,8 +59,8 @@ class AdjacencySetProxy(MutableSet[GraphNode]):
6059
return
6160
(<_AdjacencySetCore>self._core).add_edge(<GraphNode>value)
6261

63-
@cython.annotation_typing(False)
64-
def discard(self, GraphNode value not None: GraphNode) -> None:
62+
def discard(self, value: object) -> None:
63+
# Non-GraphNode values are a no-op, matching MutableSet semantics.
6564
(<_AdjacencySetCore>self._core).check_owner_mutable()
6665
if value not in self:
6766
return

‎cuda_core/tests/graph/test_graph_definition_errors.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ def test_conditional_rejects_non_condition(init_cuda, method, args):
4747
getattr(g, method)(*args)
4848

4949

50+
@pytest.mark.agent_authored(model="claude-sonnet-5-5")
51+
@pytest.mark.parametrize("none_arg", ["config", "kernel"])
52+
@pytest.mark.parametrize("target", ["GraphDefinition", "GraphNode"])
53+
def test_launch_rejects_none(init_cuda, target, none_arg):
54+
"""launch() on a graph or node rejects None for config and kernel."""
55+
kernel = compile_common_kernels().get_kernel("add_one")
56+
g = GraphDefinition()
57+
if target == "GraphDefinition":
58+
owner = g
59+
else:
60+
owner = g.empty()
61+
args = {"config": LaunchConfig(grid=1, block=1), "kernel": kernel}
62+
args[none_arg] = None
63+
64+
with pytest.raises(TypeError):
65+
owner.launch(args["config"], args["kernel"])
66+
67+
5068
def test_embed_rejects_non_graphdef(init_cuda):
5169
"""embed() rejects non-GraphDefinition arguments."""
5270
g = GraphDefinition()

‎cuda_core/tests/memory/test_copy_single_options.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ def pinned_mr():
4646
return LegacyPinnedMemoryResource()
4747

4848

49+
@pytest.mark.agent_authored(model="claude-sonnet-5-5")
50+
def test_copy_from_rejects_none_src(single_copy_device, single_copy_stream, pinned_mr):
51+
"""copy_from(None) raises TypeError instead of dereferencing a null source."""
52+
dst = pinned_mr.allocate(SIZE)
53+
54+
with pytest.raises(TypeError):
55+
dst.copy_from(None, stream=single_copy_stream)
56+
57+
dst.close()
58+
59+
4960
@pytest.mark.agent_authored(model="Claude Sonnet 4.6")
5061
@thread_unsafe_on_windows
5162
def test_options_none_copy_to_data_correct(single_copy_device, single_copy_stream, pinned_mr):

‎cuda_core/tests/test_launcher.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,20 @@ def test_launch_cluster_scheduling_policy_smoke(init_cuda):
494494
stream.sync()
495495

496496

497+
@pytest.mark.agent_authored(model="claude-sonnet-5-5")
498+
@pytest.mark.parametrize("none_arg", ["config", "kernel"])
499+
def test_launch_rejects_none(init_cuda, none_arg):
500+
"""None for a cdef-class argument raises TypeError instead of reaching C."""
501+
program = Program('extern "C" __global__ void my_kernel() {}', SourceCodeType.CXX)
502+
ker = program.compile(ObjectCodeFormatType.CUBIN).get_kernel("my_kernel")
503+
config = LaunchConfig(grid=(1, 1, 1), block=(1, 1, 1))
504+
args = {"config": config, "kernel": ker}
505+
args[none_arg] = None
506+
507+
with pytest.raises(TypeError):
508+
launch(Device().create_stream(), args["config"], args["kernel"])
509+
510+
497511
def test_launch_invalid_values(init_cuda):
498512
code = 'extern "C" __global__ void my_kernel() {}'
499513
program = Program(code, SourceCodeType.CXX)

0 commit comments

Comments
 (0)