Skip to content

Commit 61f2f16

Browse files
Create a file for decorators
1 parent e67f10e commit 61f2f16

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

pylint/testutils/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
]
4444

4545
from pylint.testutils.constants import UPDATE_OPTION
46+
from pylint.testutils.decorator import set_config
4647
from pylint.testutils.functional_test_file import FunctionalTestFile
4748
from pylint.testutils.get_test_info import _get_tests_info
4849
from pylint.testutils.lint_module_test import LintModuleTest
4950
from pylint.testutils.output_line import Message
5051
from pylint.testutils.reporter_for_tests import GenericTestReporter, MinimalTestReporter
51-
from pylint.testutils.utils import CheckerTestCase, _tokenize_str, linter, set_config
52+
from pylint.testutils.utils import CheckerTestCase, _tokenize_str, linter

pylint/testutils/decorator.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2+
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
3+
4+
import functools
5+
6+
from pylint.testutils.utils import CheckerTestCase
7+
8+
9+
def set_config(**kwargs):
10+
"""Decorator for setting config values on a checker."""
11+
12+
def _wrapper(fun):
13+
@functools.wraps(fun)
14+
def _forward(self):
15+
for key, value in kwargs.items():
16+
setattr(self.checker.config, key, value)
17+
if isinstance(self, CheckerTestCase):
18+
# reopen checker in case, it may be interested in configuration change
19+
self.checker.open()
20+
fun(self)
21+
22+
return _forward
23+
24+
return _wrapper

pylint/testutils/utils.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
"""functional/non regression tests for pylint"""
55
import contextlib
6-
import functools
76
import tokenize
87
from io import StringIO
98

@@ -47,24 +46,6 @@ def options_providers(self):
4746
return linter.options_providers
4847

4948

50-
def set_config(**kwargs):
51-
"""Decorator for setting config values on a checker."""
52-
53-
def _wrapper(fun):
54-
@functools.wraps(fun)
55-
def _forward(self):
56-
for key, value in kwargs.items():
57-
setattr(self.checker.config, key, value)
58-
if isinstance(self, CheckerTestCase):
59-
# reopen checker in case, it may be interested in configuration change
60-
self.checker.open()
61-
fun(self)
62-
63-
return _forward
64-
65-
return _wrapper
66-
67-
6849
class CheckerTestCase:
6950
"""A base testcase class for unit testing individual checker classes."""
7051

0 commit comments

Comments
 (0)