third_party.pylibs.pylint.src/pylint/testutils/decorator.py

29 lines
940 B
Python
Raw Normal View History

2020-11-29 10:13:06 +00:00
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
2020-11-29 10:13:06 +00:00
import functools
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):
"""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
def _wrapper(fun):
@functools.wraps(fun)
def _forward(self, *args, **test_function_kwargs):
2020-11-29 10:13:06 +00:00
for key, value in kwargs.items():
setattr(self.checker.config, key, value)
if isinstance(self, CheckerTestCase):
# reopen checker in case, it may be interested in configuration change
self.checker.open()
fun(self, *args, **test_function_kwargs)
2020-11-29 10:13:06 +00:00
return _forward
return _wrapper