|
| 1 | +""" |
| 2 | +Test suite for the typing utilities module. |
| 3 | +""" |
| 4 | + |
| 5 | +from typing import Annotated, Literal, Union |
| 6 | + |
| 7 | +import pytest |
| 8 | +from typing_extensions import TypeAlias |
| 9 | + |
| 10 | +from guidellm.utils.typing import get_literal_vals |
| 11 | + |
| 12 | +# Local type definitions to avoid imports from other modules |
| 13 | +LocalProfileType = Literal["synchronous", "async", "concurrent", "throughput", "sweep"] |
| 14 | +LocalStrategyType = Annotated[ |
| 15 | + Literal["synchronous", "concurrent", "throughput", "constant", "poisson"], |
| 16 | + "Valid strategy type identifiers for scheduling request patterns", |
| 17 | +] |
| 18 | +StrategyProfileType: TypeAlias = Union[LocalStrategyType, LocalProfileType] |
| 19 | + |
| 20 | + |
| 21 | +class TestGetLiteralVals: |
| 22 | + """Test cases for the get_literal_vals function.""" |
| 23 | + |
| 24 | + @pytest.mark.sanity |
| 25 | + def test_profile_type(self): |
| 26 | + """ |
| 27 | + Test extracting values from ProfileType. |
| 28 | +
|
| 29 | + ### WRITTEN BY AI ### |
| 30 | + """ |
| 31 | + result = get_literal_vals(LocalProfileType) |
| 32 | + expected = frozenset( |
| 33 | + {"synchronous", "async", "concurrent", "throughput", "sweep"} |
| 34 | + ) |
| 35 | + assert result == expected |
| 36 | + |
| 37 | + @pytest.mark.sanity |
| 38 | + def test_strategy_type(self): |
| 39 | + """ |
| 40 | + Test extracting values from StrategyType. |
| 41 | +
|
| 42 | + ### WRITTEN BY AI ### |
| 43 | + """ |
| 44 | + result = get_literal_vals(LocalStrategyType) |
| 45 | + expected = frozenset( |
| 46 | + {"synchronous", "concurrent", "throughput", "constant", "poisson"} |
| 47 | + ) |
| 48 | + assert result == expected |
| 49 | + |
| 50 | + @pytest.mark.smoke |
| 51 | + def test_inline_union_type(self): |
| 52 | + """ |
| 53 | + Test extracting values from inline union of ProfileType | StrategyType. |
| 54 | +
|
| 55 | + ### WRITTEN BY AI ### |
| 56 | + """ |
| 57 | + result = get_literal_vals(Union[LocalProfileType, LocalStrategyType]) |
| 58 | + expected = frozenset( |
| 59 | + { |
| 60 | + "synchronous", |
| 61 | + "async", |
| 62 | + "concurrent", |
| 63 | + "throughput", |
| 64 | + "constant", |
| 65 | + "poisson", |
| 66 | + "sweep", |
| 67 | + } |
| 68 | + ) |
| 69 | + assert result == expected |
| 70 | + |
| 71 | + @pytest.mark.smoke |
| 72 | + def test_type_alias(self): |
| 73 | + """ |
| 74 | + Test extracting values from type alias union. |
| 75 | +
|
| 76 | + ### WRITTEN BY AI ### |
| 77 | + """ |
| 78 | + result = get_literal_vals(StrategyProfileType) |
| 79 | + expected = frozenset( |
| 80 | + { |
| 81 | + "synchronous", |
| 82 | + "async", |
| 83 | + "concurrent", |
| 84 | + "throughput", |
| 85 | + "constant", |
| 86 | + "poisson", |
| 87 | + "sweep", |
| 88 | + } |
| 89 | + ) |
| 90 | + assert result == expected |
| 91 | + |
| 92 | + @pytest.mark.sanity |
| 93 | + def test_single_literal(self): |
| 94 | + """ |
| 95 | + Test extracting values from single Literal type. |
| 96 | +
|
| 97 | + ### WRITTEN BY AI ### |
| 98 | + """ |
| 99 | + result = get_literal_vals(Literal["test"]) |
| 100 | + expected = frozenset({"test"}) |
| 101 | + assert result == expected |
| 102 | + |
| 103 | + @pytest.mark.sanity |
| 104 | + def test_multi_literal(self): |
| 105 | + """ |
| 106 | + Test extracting values from multi-value Literal type. |
| 107 | +
|
| 108 | + ### WRITTEN BY AI ### |
| 109 | + """ |
| 110 | + result = get_literal_vals(Literal["test", "test2"]) |
| 111 | + expected = frozenset({"test", "test2"}) |
| 112 | + assert result == expected |
| 113 | + |
| 114 | + @pytest.mark.smoke |
| 115 | + def test_literal_union(self): |
| 116 | + """ |
| 117 | + Test extracting values from union of Literal types. |
| 118 | +
|
| 119 | + ### WRITTEN BY AI ### |
| 120 | + """ |
| 121 | + result = get_literal_vals(Union[Literal["test", "test2"], Literal["test3"]]) |
| 122 | + expected = frozenset({"test", "test2", "test3"}) |
| 123 | + assert result == expected |
0 commit comments