Skip to content

Commit 6327b22

Browse files
committed
test(core): add tests for Linker.backend classmethod
Covers classmethod invocation (Linker.backend() without an instance), memoisation flag handling, probe-on-first-use, and non-property attribute semantics.
1 parent 432771c commit 6327b22

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

cuda_core/tests/test_linker.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import inspect
6+
57
import pytest
68

79
from cuda.core import Device, Linker, LinkerOptions, Program, ProgramOptions, _linker
@@ -242,3 +244,40 @@ def test_linker_options_nvjitlink_options_as_str():
242244
assert f"-arch={ARCH}" in options
243245
assert "-g" in options
244246
assert "-lineinfo" in options
247+
248+
249+
class TestBackendClassmethod:
250+
def test_backend_returns_nvjitlink(self, monkeypatch):
251+
monkeypatch.setattr(_linker, "_use_nvjitlink_backend", True)
252+
assert Linker.backend() == "nvJitLink"
253+
254+
def test_backend_returns_driver(self, monkeypatch):
255+
monkeypatch.setattr(_linker, "_use_nvjitlink_backend", False)
256+
assert Linker.backend() == "driver"
257+
258+
def test_backend_invokes_probe_when_not_memoised(self, monkeypatch):
259+
monkeypatch.setattr(_linker, "_use_nvjitlink_backend", None)
260+
called = []
261+
262+
def fake_decide():
263+
called.append(True)
264+
return False # False = not falling back to driver = nvJitLink
265+
266+
monkeypatch.setattr(_linker, "_decide_nvjitlink_or_driver", fake_decide)
267+
result = Linker.backend()
268+
assert result == "nvJitLink"
269+
assert called, "_decide_nvjitlink_or_driver was not called"
270+
271+
def test_backend_is_classmethod(self):
272+
attr = inspect.getattr_static(Linker, "backend")
273+
assert isinstance(attr, classmethod)
274+
275+
def test_backend_is_not_property(self):
276+
"""backend is a classmethod, not a property.
277+
278+
This is an intentional breaking change from the prior property API.
279+
Attribute-style access (``linker.backend``) now returns a bound method,
280+
not a string. All call sites must use parens: ``Linker.backend()``.
281+
"""
282+
attr = inspect.getattr_static(Linker, "backend")
283+
assert not isinstance(attr, property)

0 commit comments

Comments
 (0)