2025-07-01 05:10:28 -04:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
|
|
|
|
|
|
import ast
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
2025-10-29 16:04:33 +08:00
|
|
|
from tools.pre_commit.validate_config import validate_ast
|
2025-07-01 05:10:28 -04:00
|
|
|
|
2026-02-03 17:40:59 +00:00
|
|
|
_TestConfig1 = '''
|
2025-07-01 05:10:28 -04:00
|
|
|
@config
|
|
|
|
|
class _TestConfig1:
|
|
|
|
|
a: int
|
|
|
|
|
"""docstring"""
|
|
|
|
|
'''
|
|
|
|
|
|
2026-02-03 17:40:59 +00:00
|
|
|
_TestConfig2 = """
|
2025-07-01 05:10:28 -04:00
|
|
|
@config
|
2026-02-03 17:40:59 +00:00
|
|
|
class _TestConfig2:
|
2025-07-01 05:10:28 -04:00
|
|
|
a: int = 1
|
2025-10-05 15:06:22 +01:00
|
|
|
"""
|
2025-07-01 05:10:28 -04:00
|
|
|
|
2026-02-03 17:40:59 +00:00
|
|
|
_TestConfig3 = '''
|
2025-07-01 05:10:28 -04:00
|
|
|
@config
|
2026-02-03 17:40:59 +00:00
|
|
|
class _TestConfig3:
|
2025-07-01 05:10:28 -04:00
|
|
|
a: Union[Literal[1], Literal[2]] = 1
|
|
|
|
|
"""docstring"""
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
("test_config", "expected_error"),
|
|
|
|
|
[
|
2026-02-03 17:40:59 +00:00
|
|
|
(_TestConfig1, "must have a default"),
|
|
|
|
|
(_TestConfig2, "must have a docstring"),
|
|
|
|
|
(_TestConfig3, "must use a single Literal"),
|
2025-07-01 05:10:28 -04:00
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_config(test_config, expected_error):
|
|
|
|
|
tree = ast.parse(test_config)
|
|
|
|
|
with pytest.raises(Exception, match=expected_error):
|
|
|
|
|
validate_ast(tree)
|