Skip to content

Commit cfa4f96

Browse files
Move LintModuleOutputUpdate to pylint.testutil.functional
1 parent 6c7fbc2 commit cfa4f96

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

pylint/testutils/functional/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"get_functional_test_files_from_directory",
88
"NoFileError",
99
"parse_python_version",
10+
"LintModuleOutputUpdate",
1011
]
1112

1213
from pylint.testutils.functional.find_functional_tests import (
1314
REASONABLY_DISPLAYABLE_VERTICALLY,
1415
get_functional_test_files_from_directory,
1516
)
17+
from pylint.testutils.functional.lint_module_output_update import LintModuleOutputUpdate
1618
from pylint.testutils.functional.test_file import (
1719
FunctionalTestFile,
1820
NoFileError,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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/main/LICENSE
3+
4+
import csv
5+
import os
6+
7+
from pylint.testutils.lint_module_test import LintModuleTest
8+
9+
10+
class LintModuleOutputUpdate(LintModuleTest):
11+
"""If message files should be updated instead of checked."""
12+
13+
class TestDialect(csv.excel):
14+
delimiter = ":"
15+
lineterminator = "\n"
16+
17+
csv.register_dialect("test", TestDialect)
18+
19+
def _check_output_text(self, _, expected_output, actual_output):
20+
if not expected_output and not actual_output:
21+
if os.path.exists(self._test_file.expected_output):
22+
os.remove(self._test_file.expected_output)
23+
return
24+
with open(self._test_file.expected_output, "w", encoding="utf-8") as f:
25+
writer = csv.writer(f, dialect="test")
26+
for line in actual_output:
27+
writer.writerow(line.to_csv())

tests/test_functional.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
2323

2424
"""Functional full-module tests for PyLint."""
25-
import csv
26-
import os
2725
import sys
2826
from pathlib import Path
2927
from typing import Union
@@ -38,6 +36,7 @@
3836
FunctionalTestFile,
3937
get_functional_test_files_from_directory,
4038
)
39+
from pylint.testutils.functional.lint_module_output_update import LintModuleOutputUpdate
4140
from pylint.utils import HAS_ISORT_5
4241

4342
# TODOs
@@ -47,26 +46,6 @@
4746
FUNCTIONAL_DIR = Path(__file__).parent.resolve() / "functional"
4847

4948

50-
class LintModuleOutputUpdate(testutils.LintModuleTest):
51-
"""If message files should be updated instead of checked."""
52-
53-
class TestDialect(csv.excel):
54-
delimiter = ":"
55-
lineterminator = "\n"
56-
57-
csv.register_dialect("test", TestDialect)
58-
59-
def _check_output_text(self, _, expected_output, actual_output):
60-
if not expected_output and not actual_output:
61-
if os.path.exists(self._test_file.expected_output):
62-
os.remove(self._test_file.expected_output)
63-
return
64-
with open(self._test_file.expected_output, "w", encoding="utf-8") as f:
65-
writer = csv.writer(f, dialect="test")
66-
for line in actual_output:
67-
writer.writerow(line.to_csv())
68-
69-
7049
# isort 5 has slightly different rules as isort 4. Testing both would be hard: test with isort 5 only.
7150
TESTS = [
7251
t

0 commit comments

Comments
 (0)