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

import ast

import pytest

8
from tools.pre_commit.validate_config import validate_ast
9

10
_TestConfig1 = '''
11
12
13
14
15
16
@config
class _TestConfig1:
    a: int
    """docstring"""
'''

17
_TestConfig2 = """
18
@config
19
class _TestConfig2:
20
    a: int = 1
21
"""
22

23
_TestConfig3 = '''
24
@config
25
class _TestConfig3:
26
27
28
29
30
    a: Union[Literal[1], Literal[2]] = 1
    """docstring"""
'''


31
32
33
@pytest.mark.parametrize(
    ("test_config", "expected_error"),
    [
34
35
36
        (_TestConfig1, "must have a default"),
        (_TestConfig2, "must have a docstring"),
        (_TestConfig3, "must use a single Literal"),
37
38
    ],
)
39
40
41
42
def test_config(test_config, expected_error):
    tree = ast.parse(test_config)
    with pytest.raises(Exception, match=expected_error):
        validate_ast(tree)