Skip to content

Commit

Permalink
Move to __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Nov 25, 2021
1 parent f0c6055 commit 602b8ce
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pylint/testutils/lint_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def __init__(
pass
self._test_file = test_file
self._config = config
self._check_end_position = (
sys.version_info >= self._test_file.options["min_pyver_end_position"]
)

def setUp(self) -> None:
if self._should_be_skipped_due_to_version():
Expand Down Expand Up @@ -159,23 +162,19 @@ def _open_source_file(self) -> TextIO:
return open(self._test_file.source, encoding="latin1")
return open(self._test_file.source, encoding="utf8")

def _get_expected(
self, check_end_position: bool
) -> Tuple["MessageCounter", List[OutputLine]]:
def _get_expected(self) -> Tuple["MessageCounter", List[OutputLine]]:
with self._open_source_file() as f:
expected_msgs = self.get_expected_messages(f)
if not expected_msgs:
expected_msgs = Counter()
with self._open_expected_file() as f:
expected_output_lines = [
OutputLine.from_csv(row, check_end_position)
OutputLine.from_csv(row, self._check_end_position)
for row in csv.reader(f, "test")
]
return expected_msgs, expected_output_lines

def _get_actual(
self, check_end_position: bool
) -> Tuple["MessageCounter", List[OutputLine]]:
def _get_actual(self) -> Tuple["MessageCounter", List[OutputLine]]:
messages: List[Message] = self._linter.reporter.messages
messages.sort(key=lambda m: (m.line, m.symbol, m.msg))
received_msgs: "MessageCounter" = Counter()
Expand All @@ -185,18 +184,17 @@ def _get_actual(
msg.symbol != "fatal"
), f"Pylint analysis failed because of '{msg.msg}'"
received_msgs[msg.line, msg.symbol] += 1
received_output_lines.append(OutputLine.from_msg(msg, check_end_position))
received_output_lines.append(
OutputLine.from_msg(msg, self._check_end_position)
)
return received_msgs, received_output_lines

def _runTest(self) -> None:
__tracebackhide__ = True # pylint: disable=unused-variable
modules_to_check = [self._test_file.source]
self._linter.check(modules_to_check)
check_end_position = (
sys.version_info >= self._test_file.options["min_pyver_end_position"]
)
expected_messages, expected_output = self._get_expected(check_end_position)
actual_messages, actual_output = self._get_actual(check_end_position)
expected_messages, expected_output = self._get_expected()
actual_messages, actual_output = self._get_actual()
assert (
expected_messages == actual_messages
), self.error_msg_for_unequal_messages(
Expand Down

0 comments on commit 602b8ce

Please sign in to comment.