2020-11-29 10:13:06 +00:00
|
|
|
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2021-07-01 10:47:58 +00:00
|
|
|
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
|
2022-03-01 15:04:49 +00:00
|
|
|
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
|
2020-11-29 10:13:06 +00:00
|
|
|
|
|
|
|
import functools
|
|
|
|
|
2022-04-02 10:08:30 +00:00
|
|
|
from pylint.config.utils import _parse_rich_type_value
|
2020-11-29 10:17:56 +00:00
|
|
|
from pylint.testutils.checker_test_case import CheckerTestCase
|
2020-11-29 10:13:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
def set_config(**kwargs):
|
2021-04-09 17:27:53 +00:00
|
|
|
"""Decorator for setting config values on a checker.
|
|
|
|
|
|
|
|
Passing the args and kwargs back to the test function itself
|
|
|
|
allows this decorator to be used on parametrized test cases.
|
|
|
|
"""
|
2020-11-29 10:13:06 +00:00
|
|
|
|
2021-09-29 08:21:52 +00:00
|
|
|
def _wrapper(fun):
|
|
|
|
@functools.wraps(fun)
|
|
|
|
def _forward(self, *args, **test_function_kwargs):
|
2022-04-13 10:34:35 +00:00
|
|
|
"""Set option via argparse."""
|
2022-04-02 09:27:07 +00:00
|
|
|
# pylint: disable-next=fixme
|
|
|
|
# TODO: Revisit this decorator after all checkers have switched
|
|
|
|
options = []
|
|
|
|
for key, value in kwargs.items():
|
2022-04-02 10:08:30 +00:00
|
|
|
options += [f"--{key.replace('_', '-')}", _parse_rich_type_value(value)]
|
2022-04-02 09:27:07 +00:00
|
|
|
self.linter.namespace = self.linter._arg_parser.parse_known_args(
|
|
|
|
options, self.linter.namespace
|
|
|
|
)[0]
|
|
|
|
|
2021-09-29 08:21:52 +00:00
|
|
|
if isinstance(self, CheckerTestCase):
|
|
|
|
# reopen checker in case, it may be interested in configuration change
|
|
|
|
self.checker.open()
|
2022-04-02 09:27:07 +00:00
|
|
|
|
2021-09-29 08:21:52 +00:00
|
|
|
fun(self, *args, **test_function_kwargs)
|
|
|
|
|
|
|
|
return _forward
|
|
|
|
|
|
|
|
return _wrapper
|