|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
| 5 | +import inspect |
| 6 | + |
5 | 7 | import pytest |
6 | 8 |
|
7 | 9 | from cuda.core import Device, Linker, LinkerOptions, Program, ProgramOptions, _linker |
@@ -242,3 +244,40 @@ def test_linker_options_nvjitlink_options_as_str(): |
242 | 244 | assert f"-arch={ARCH}" in options |
243 | 245 | assert "-g" in options |
244 | 246 | 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