| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | from vllm.utils.import_utils import has_helion |
| 7 | |
| 8 | if not has_helion(): |
| 9 | pytest.skip( |
| 10 | "Helion is not installed. Install with: pip install vllm[helion]", |
| 11 | allow_module_level=True, |
| 12 | ) |
| 13 | |
| 14 | from vllm.kernels.helion.case_key import CaseKey |
| 15 | |
| 16 | |
| 17 | class TestCaseKey: |
| 18 | """Test suite for CaseKey class.""" |
| 19 | |
| 20 | def test_construction_with_dict(self): |
| 21 | key = CaseKey({"intermediate": 2048, "numtokens": 256}) |
| 22 | assert key["intermediate"] == 2048 |
| 23 | assert key["numtokens"] == 256 |
| 24 | |
| 25 | def test_empty_construction_raises(self): |
| 26 | with pytest.raises(TypeError, match="at least one key-value pair"): |
| 27 | CaseKey() |
| 28 | with pytest.raises(TypeError, match="at least one key-value pair"): |
| 29 | CaseKey({}) |
| 30 | |
| 31 | def test_default_construction(self): |
| 32 | key = CaseKey.default() |
| 33 | assert len(key) == 0 |
| 34 | assert key.is_default() |
| 35 | |
| 36 | def test_non_default_is_not_default(self): |
| 37 | key = CaseKey({"intermediate": 2048}) |
| 38 | assert not key.is_default() |
| 39 | |
| 40 | def test_hashable_and_equality(self): |
| 41 | a = CaseKey({"intermediate": 2048, "numtokens": 256}) |
| 42 | b = CaseKey({"numtokens": 256, "intermediate": 2048}) |
| 43 | assert a == b |
| 44 | assert hash(a) == hash(b) |
| 45 | assert a != CaseKey({"intermediate": 4096}) |
| 46 | assert CaseKey.default() == CaseKey.default() |
| 47 | |
| 48 | configs = { |
| 49 | CaseKey.default(): "default_config", |
| 50 | a: "a_config", |
| 51 | } |
| 52 | assert configs[b] == "a_config" |
| 53 | assert configs[CaseKey.default()] == "default_config" |
| 54 | |
| 55 | def test_str_is_sorted_json(self): |
| 56 | assert str(CaseKey({"z": 1, "a": 2})) == '{"a":2,"z":1}' |
| 57 | assert str(CaseKey.default()) == "{}" |
| 58 | |
| 59 | def test_immutable(self): |
| 60 | key = CaseKey({"intermediate": 2048}) |
| 61 | with pytest.raises(TypeError, match="immutable"): |
| 62 | key["intermediate"] = 4096 |
| 63 | with pytest.raises(TypeError, match="immutable"): |
| 64 | del key["intermediate"] |
| 65 | with pytest.raises(TypeError, match="immutable"): |
| 66 | key.update({"numtokens": 256}) |
| 67 | with pytest.raises(TypeError, match="immutable"): |
| 68 | key.clear() |