Skip to content

Commit 2e21eb4

Browse files
Burst what remain of utils into files
1 parent 61f2f16 commit 2e21eb4

File tree

5 files changed

+54
-45
lines changed

5 files changed

+54
-45
lines changed

pylint/testutils/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@
4242
"UPDATE_OPTION",
4343
]
4444

45+
from pylint.testutils.checker_test_case import CheckerTestCase
4546
from pylint.testutils.constants import UPDATE_OPTION
4647
from pylint.testutils.decorator import set_config
4748
from pylint.testutils.functional_test_file import FunctionalTestFile
4849
from pylint.testutils.get_test_info import _get_tests_info
50+
from pylint.testutils.global_test_linter import linter
4951
from pylint.testutils.lint_module_test import LintModuleTest
5052
from pylint.testutils.output_line import Message
5153
from pylint.testutils.reporter_for_tests import GenericTestReporter, MinimalTestReporter
52-
from pylint.testutils.utils import CheckerTestCase, _tokenize_str, linter
54+
from pylint.testutils.tokenize_str import _tokenize_str
Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,13 @@
11
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22
# For details: https://github.com/PyCQA/pylint/blob/master/COPYING
33

4-
"""functional/non regression tests for pylint"""
54
import contextlib
6-
import tokenize
7-
from io import StringIO
85

96
from pylint.testutils.global_test_linter import linter
10-
from pylint.testutils.output_line import Message
7+
from pylint.testutils.unittest_linter import UnittestLinter
118
from pylint.utils import ASTWalker
129

1310

14-
class UnittestLinter:
15-
"""A fake linter class to capture checker messages."""
16-
17-
# pylint: disable=unused-argument, no-self-use
18-
19-
def __init__(self):
20-
self._messages = []
21-
self.stats = {}
22-
23-
def release_messages(self):
24-
try:
25-
return self._messages
26-
finally:
27-
self._messages = []
28-
29-
def add_message(
30-
self, msg_id, line=None, node=None, args=None, confidence=None, col_offset=None
31-
):
32-
# Do not test col_offset for now since changing Message breaks everything
33-
self._messages.append(Message(msg_id, line, node, args, confidence))
34-
35-
@staticmethod
36-
def is_message_enabled(*unused_args, **unused_kwargs):
37-
return True
38-
39-
def add_stats(self, **kwargs):
40-
for name, value in kwargs.items():
41-
self.stats[name] = value
42-
return self.stats
43-
44-
@property
45-
def options_providers(self):
46-
return linter.options_providers
47-
48-
4911
class CheckerTestCase:
5012
"""A base testcase class for unit testing individual checker classes."""
5113

@@ -86,7 +48,3 @@ def walk(self, node):
8648
walker = ASTWalker(linter)
8749
walker.add_checker(self.checker)
8850
walker.walk(node)
89-
90-
91-
def _tokenize_str(code):
92-
return list(tokenize.generate_tokens(StringIO(code).readline))

pylint/testutils/decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import functools
55

6-
from pylint.testutils.utils import CheckerTestCase
6+
from pylint.testutils.checker_test_case import CheckerTestCase
77

88

99
def set_config(**kwargs):

pylint/testutils/tokenize_str.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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 tokenize
5+
from io import StringIO
6+
7+
8+
def _tokenize_str(code):
9+
return list(tokenize.generate_tokens(StringIO(code).readline))

pylint/testutils/unittest_linter.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
from pylint.testutils.global_test_linter import linter
5+
from pylint.testutils.output_line import Message
6+
7+
8+
class UnittestLinter:
9+
"""A fake linter class to capture checker messages."""
10+
11+
# pylint: disable=unused-argument, no-self-use
12+
13+
def __init__(self):
14+
self._messages = []
15+
self.stats = {}
16+
17+
def release_messages(self):
18+
try:
19+
return self._messages
20+
finally:
21+
self._messages = []
22+
23+
def add_message(
24+
self, msg_id, line=None, node=None, args=None, confidence=None, col_offset=None
25+
):
26+
# Do not test col_offset for now since changing Message breaks everything
27+
self._messages.append(Message(msg_id, line, node, args, confidence))
28+
29+
@staticmethod
30+
def is_message_enabled(*unused_args, **unused_kwargs):
31+
return True
32+
33+
def add_stats(self, **kwargs):
34+
for name, value in kwargs.items():
35+
self.stats[name] = value
36+
return self.stats
37+
38+
@property
39+
def options_providers(self):
40+
return linter.options_providers

0 commit comments

Comments
 (0)