From e9d1bc91938f07d92279720e06fb53d8e1e3237b Mon Sep 17 00:00:00 2001 From: LeSingh1 Date: Sat, 8 Aug 2026 19:02:30 -0700 Subject: [PATCH] Fix operator precedence in test_cudart.supportsCudaAPI def supportsCudaAPI(name): return name in dir(cuda) or dir(cudart) parses as `(name in dir(cuda)) or dir(cudart)`. `dir(cudart)` is a non-empty list for any module, so it is unconditionally truthy and the function returns a truthy value for every input, including names that exist nowhere. The left operand is dead too: `cuda` is cuda.bindings.driver and every name passed in is a cudaXxx runtime symbol. cudaGraphGetId, cudaGreenCtxCreate, cudaDeviceGetExecutionCtx and cudaGraphConditionalHandleCreate are all defined in runtime.pyx and appear nowhere in driver.pyx, so `name in dir(cuda)` is always False and the result is always the `dir(cudart)` list. Consequence: `not supportsCudaAPI(...)` is always False, so the API-presence half of all 17 skipif guards that use it (lines 1443-1954) never fires. On a build whose bindings genuinely lack the API, the test runs and dies with AttributeError instead of skipping; only the driver_version_less_than() half of each guard does any work. Adds test_supportsCudaAPI, pinning all three cases: a runtime-only name, a driver-only name, and a name that exists in neither. The last two fail before this change. --- cuda_bindings/tests/test_cudart.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cuda_bindings/tests/test_cudart.py b/cuda_bindings/tests/test_cudart.py index 7b70acdeb46..3dc4fba7461 100644 --- a/cuda_bindings/tests/test_cudart.py +++ b/cuda_bindings/tests/test_cudart.py @@ -34,7 +34,16 @@ def supportsSparseTexturesDeviceFilter(): def supportsCudaAPI(name): - return name in dir(cuda) or dir(cudart) + return name in dir(cuda) or name in dir(cudart) + + +@pytest.mark.agent_authored(model="claude-opus-5") +def test_supportsCudaAPI(): + # Guards the operator precedence: `name in dir(cuda) or dir(cudart)` parses + # as `(name in dir(cuda)) or dir(cudart)`, which is truthy for every name. + assert supportsCudaAPI("cudaMalloc") is True # runtime module + assert supportsCudaAPI("cuInit") is True # driver module + assert supportsCudaAPI("this_is_not_a_cuda_api") is False def test_cudart_memcpy():