|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from cuda.bindings.utils import envvar_bool |
| 7 | + |
| 8 | +_VAR = "CUDA_PYTHON_TEST_ENVVAR_BOOL" |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.agent_authored(model="claude-opus-5") |
| 12 | +@pytest.mark.parametrize( |
| 13 | + ("raw", "expected"), |
| 14 | + [ |
| 15 | + pytest.param("0", False, id="zero"), |
| 16 | + pytest.param(" 0 ", False, id="zero-padded"), |
| 17 | + pytest.param("", False, id="empty"), |
| 18 | + pytest.param(" ", False, id="blank"), |
| 19 | + pytest.param("1", True, id="one"), |
| 20 | + pytest.param("2", True, id="two"), |
| 21 | + pytest.param("-0", False, id="negative-zero"), |
| 22 | + pytest.param("false", False, id="false"), |
| 23 | + pytest.param("FALSE", False, id="false-upper"), |
| 24 | + pytest.param("no", False, id="no"), |
| 25 | + pytest.param("off", False, id="off"), |
| 26 | + pytest.param("true", True, id="true"), |
| 27 | + pytest.param("True", True, id="true-capitalised"), |
| 28 | + pytest.param("yes", True, id="yes"), |
| 29 | + pytest.param("on", True, id="on"), |
| 30 | + # Anything unrecognised keeps the historical set-means-true behaviour. |
| 31 | + pytest.param("banana", True, id="unrecognised"), |
| 32 | + ], |
| 33 | +) |
| 34 | +def test_envvar_bool_parsing(monkeypatch, raw, expected): |
| 35 | + monkeypatch.setenv(_VAR, raw) |
| 36 | + assert envvar_bool(_VAR) is expected |
| 37 | + |
| 38 | + |
| 39 | +@pytest.mark.agent_authored(model="claude-opus-5") |
| 40 | +@pytest.mark.parametrize("default", [False, True]) |
| 41 | +def test_envvar_bool_unset_returns_default(monkeypatch, default): |
| 42 | + monkeypatch.delenv(_VAR, raising=False) |
| 43 | + assert envvar_bool(_VAR, default) is default |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.agent_authored(model="claude-opus-5") |
| 47 | +@pytest.mark.parametrize("raw", ["", " "]) |
| 48 | +def test_envvar_bool_blank_returns_default(monkeypatch, raw): |
| 49 | + """Blank is "not set", so it must not override a True default.""" |
| 50 | + monkeypatch.setenv(_VAR, raw) |
| 51 | + assert envvar_bool(_VAR, True) is True |
0 commit comments