main
py 42 lines 851 Bytes
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import ast
5
6 import pytest
7
8 from tools.pre_commit.validate_config import validate_ast
9
10 _TestConfig1 = '''
11 @config
12 class _TestConfig1:
13 a: int
14 """docstring"""
15 '''
16
17 _TestConfig2 = """
18 @config
19 class _TestConfig2:
20 a: int = 1
21 """
22
23 _TestConfig3 = '''
24 @config
25 class _TestConfig3:
26 a: Union[Literal[1], Literal[2]] = 1
27 """docstring"""
28 '''
29
30
31 @pytest.mark.parametrize(
32 ("test_config", "expected_error"),
33 [
34 (_TestConfig1, "must have a default"),
35 (_TestConfig2, "must have a docstring"),
36 (_TestConfig3, "must use a single Literal"),
37 ],
38 )
39 def test_config(test_config, expected_error):
40 tree = ast.parse(test_config)
41 with pytest.raises(Exception, match=expected_error):
42 validate_ast(tree)