summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2020-11-29 11:17:56 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2020-11-29 11:59:49 +0100
commit2e21eb481cd9229931af8d303b7e9adbe7887503 (patch)
treedead3152e4e5be8ee24d142fffd9ccb793a3ee93
parent61f2f16b33cfd9f57293d8d6edacaa8d55730d90 (diff)
downloadpylint-git-2e21eb481cd9229931af8d303b7e9adbe7887503.tar.gz
Burst what remain of utils into files
-rw-r--r--pylint/testutils/__init__.py4
-rw-r--r--pylint/testutils/checker_test_case.py (renamed from pylint/testutils/utils.py)44
-rw-r--r--pylint/testutils/decorator.py2
-rw-r--r--pylint/testutils/tokenize_str.py9
-rw-r--r--pylint/testutils/unittest_linter.py40
5 files changed, 54 insertions, 45 deletions
diff --git a/pylint/testutils/__init__.py b/pylint/testutils/__init__.py
index 5de736071..8f132ab9f 100644
--- a/pylint/testutils/__init__.py
+++ b/pylint/testutils/__init__.py
@@ -42,11 +42,13 @@ __all__ = [
"UPDATE_OPTION",
]
+from pylint.testutils.checker_test_case import CheckerTestCase
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.global_test_linter import linter
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
+from pylint.testutils.tokenize_str import _tokenize_str
diff --git a/pylint/testutils/utils.py b/pylint/testutils/checker_test_case.py
index 4b2a203a2..9b8281513 100644
--- a/pylint/testutils/utils.py
+++ b/pylint/testutils/checker_test_case.py
@@ -1,51 +1,13 @@
# 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
-"""functional/non regression tests for pylint"""
import contextlib
-import tokenize
-from io import StringIO
from pylint.testutils.global_test_linter import linter
-from pylint.testutils.output_line import Message
+from pylint.testutils.unittest_linter import UnittestLinter
from pylint.utils import ASTWalker
-class UnittestLinter:
- """A fake linter class to capture checker messages."""
-
- # pylint: disable=unused-argument, no-self-use
-
- def __init__(self):
- self._messages = []
- self.stats = {}
-
- def release_messages(self):
- try:
- return self._messages
- finally:
- self._messages = []
-
- def add_message(
- self, msg_id, line=None, node=None, args=None, confidence=None, col_offset=None
- ):
- # Do not test col_offset for now since changing Message breaks everything
- self._messages.append(Message(msg_id, line, node, args, confidence))
-
- @staticmethod
- def is_message_enabled(*unused_args, **unused_kwargs):
- return True
-
- def add_stats(self, **kwargs):
- for name, value in kwargs.items():
- self.stats[name] = value
- return self.stats
-
- @property
- def options_providers(self):
- return linter.options_providers
-
-
class CheckerTestCase:
"""A base testcase class for unit testing individual checker classes."""
@@ -86,7 +48,3 @@ class CheckerTestCase:
walker = ASTWalker(linter)
walker.add_checker(self.checker)
walker.walk(node)
-
-
-def _tokenize_str(code):
- return list(tokenize.generate_tokens(StringIO(code).readline))
diff --git a/pylint/testutils/decorator.py b/pylint/testutils/decorator.py
index e10fe066d..3b70867cb 100644
--- a/pylint/testutils/decorator.py
+++ b/pylint/testutils/decorator.py
@@ -3,7 +3,7 @@
import functools
-from pylint.testutils.utils import CheckerTestCase
+from pylint.testutils.checker_test_case import CheckerTestCase
def set_config(**kwargs):
diff --git a/pylint/testutils/tokenize_str.py b/pylint/testutils/tokenize_str.py
new file mode 100644
index 000000000..2b3c5f2c1
--- /dev/null
+++ b/pylint/testutils/tokenize_str.py
@@ -0,0 +1,9 @@
+# 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 tokenize
+from io import StringIO
+
+
+def _tokenize_str(code):
+ return list(tokenize.generate_tokens(StringIO(code).readline))
diff --git a/pylint/testutils/unittest_linter.py b/pylint/testutils/unittest_linter.py
new file mode 100644
index 000000000..540874611
--- /dev/null
+++ b/pylint/testutils/unittest_linter.py
@@ -0,0 +1,40 @@
+# 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
+
+from pylint.testutils.global_test_linter import linter
+from pylint.testutils.output_line import Message
+
+
+class UnittestLinter:
+ """A fake linter class to capture checker messages."""
+
+ # pylint: disable=unused-argument, no-self-use
+
+ def __init__(self):
+ self._messages = []
+ self.stats = {}
+
+ def release_messages(self):
+ try:
+ return self._messages
+ finally:
+ self._messages = []
+
+ def add_message(
+ self, msg_id, line=None, node=None, args=None, confidence=None, col_offset=None
+ ):
+ # Do not test col_offset for now since changing Message breaks everything
+ self._messages.append(Message(msg_id, line, node, args, confidence))
+
+ @staticmethod
+ def is_message_enabled(*unused_args, **unused_kwargs):
+ return True
+
+ def add_stats(self, **kwargs):
+ for name, value in kwargs.items():
+ self.stats[name] = value
+ return self.stats
+
+ @property
+ def options_providers(self):
+ return linter.options_providers