test_config_validator.py 981 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

import ast

import pytest

from tools.validate_config import validate_ast

10
_TestConfig1 = """
11
12
13
@config
class _TestConfig1:
    pass
14
"""
15
16
17
18
19
20
21
22
23

_TestConfig2 = '''
@config
@dataclass
class _TestConfig2:
    a: int
    """docstring"""
'''

24
_TestConfig3 = """
25
26
27
28
@config
@dataclass
class _TestConfig3:
    a: int = 1
29
"""
30
31
32
33
34
35
36
37
38
39

_TestConfig4 = '''
@config
@dataclass
class _TestConfig4:
    a: Union[Literal[1], Literal[2]] = 1
    """docstring"""
'''


40
41
42
43
44
45
46
47
48
@pytest.mark.parametrize(
    ("test_config", "expected_error"),
    [
        (_TestConfig1, "must be a dataclass"),
        (_TestConfig2, "must have a default"),
        (_TestConfig3, "must have a docstring"),
        (_TestConfig4, "must use a single Literal"),
    ],
)
49
50
51
52
def test_config(test_config, expected_error):
    tree = ast.parse(test_config)
    with pytest.raises(Exception, match=expected_error):
        validate_ast(tree)