summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2020-11-29 11:13:06 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2020-11-29 11:59:49 +0100
commit61f2f16b33cfd9f57293d8d6edacaa8d55730d90 (patch)
tree9a60c14dd35bc6836e8c4369daab15e84977f298
parente67f10e9303ba6a73da4ef0b24331cec37a91c78 (diff)
downloadpylint-git-61f2f16b33cfd9f57293d8d6edacaa8d55730d90.tar.gz
Create a file for decorators
-rw-r--r--pylint/testutils/__init__.py3
-rw-r--r--pylint/testutils/decorator.py24
-rw-r--r--pylint/testutils/utils.py19
3 files changed, 26 insertions, 20 deletions
diff --git a/pylint/testutils/__init__.py b/pylint/testutils/__init__.py
index 5050b631c..5de736071 100644
--- a/pylint/testutils/__init__.py
+++ b/pylint/testutils/__init__.py
@@ -43,9 +43,10 @@ __all__ = [
]
from pylint.testutils.constants import UPDATE_OPTION
+from pylint.testutils.decorator import set_config
from pylint.testutils.functional_test_file import FunctionalTestFile
from pylint.testutils.get_test_info import _get_tests_info
from pylint.testutils.lint_module_test import LintModuleTest
from pylint.testutils.output_line import Message
from pylint.testutils.reporter_for_tests import GenericTestReporter, MinimalTestReporter
-from pylint.testutils.utils import CheckerTestCase, _tokenize_str, linter, set_config
+from pylint.testutils.utils import CheckerTestCase, _tokenize_str, linter
diff --git a/pylint/testutils/decorator.py b/pylint/testutils/decorator.py
new file mode 100644
index 000000000..e10fe066d
--- /dev/null
+++ b/pylint/testutils/decorator.py
@@ -0,0 +1,24 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
+
+import functools
+
+from pylint.testutils.utils import CheckerTestCase
+
+
+def set_config(**kwargs):
+ """Decorator for setting config values on a checker."""
+
+ def _wrapper(fun):
+ @functools.wraps(fun)
+ def _forward(self):
+ 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)
+
+ return _forward
+
+ return _wrapper
diff --git a/pylint/testutils/utils.py b/pylint/testutils/utils.py
index 893bb3e2d..4b2a203a2 100644
--- a/pylint/testutils/utils.py
+++ b/pylint/testutils/utils.py
@@ -3,7 +3,6 @@
"""functional/non regression tests for pylint"""
import contextlib
-import functools
import tokenize
from io import StringIO
@@ -47,24 +46,6 @@ class UnittestLinter:
return linter.options_providers
-def set_config(**kwargs):
- """Decorator for setting config values on a checker."""
-
- def _wrapper(fun):
- @functools.wraps(fun)
- def _forward(self):
- 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)
-
- return _forward
-
- return _wrapper
-
-
class CheckerTestCase:
"""A base testcase class for unit testing individual checker classes."""