Skip to content

Commit 77f02ac

Browse files
Fix and simplify the update mechanism for functional tests
1 parent 34c2dae commit 77f02ac

File tree

1 file changed

+6
-33
lines changed

1 file changed

+6
-33
lines changed

tests/test_functional.py

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
"""Functional full-module tests for PyLint."""
2323

2424
import csv
25-
import io
2625
import os
2726
import sys
28-
import warnings
2927

3028
import pytest
3129

@@ -53,38 +51,13 @@ class test_dialect(csv.excel):
5351
class LintModuleOutputUpdate(testutils.LintModuleTest):
5452
"""If message files should be updated instead of checked."""
5553

56-
def _open_expected_file(self):
57-
try:
58-
return super()._open_expected_file()
59-
except OSError:
60-
return io.StringIO()
61-
62-
@classmethod
63-
def _split_lines(cls, expected_messages, lines):
64-
emitted, omitted = [], []
65-
for msg in lines:
66-
if (msg[1], msg[0]) in expected_messages:
67-
emitted.append(msg)
68-
else:
69-
omitted.append(msg)
70-
return emitted, omitted
71-
72-
def _check_output_text(self, expected_messages, expected_output, actual_output):
73-
if not expected_messages:
54+
def _check_output_text(self, _, expected_output, actual_output):
55+
if expected_output == actual_output:
7456
return
75-
emitted, remaining = self._split_lines(expected_messages, expected_output)
76-
if emitted != actual_output:
77-
remaining.extend(actual_output)
78-
remaining.sort(key=lambda m: (m[1], m[0], m[3]))
79-
warnings.warn(
80-
"Updated '{}' with the new content generated from '{}'".format(
81-
self._test_file.expected_output, self._test_file.base
82-
)
83-
)
84-
with open(self._test_file.expected_output, "w") as fobj:
85-
writer = csv.writer(fobj, dialect="test")
86-
for line in remaining:
87-
writer.writerow(line.to_csv())
57+
with open(self._test_file.expected_output, "w") as f:
58+
writer = csv.writer(f, dialect="test")
59+
for line in actual_output:
60+
writer.writerow(line.to_csv())
8861

8962

9063
def get_tests():

0 commit comments

Comments
 (0)