summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-14 21:42:42 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-15 09:29:56 +0200
commitc507592114354e973c475c3600ad23a625645830 (patch)
treefc63541ed2906b464bfe9eb19bef9ce0f24ab5a5
parent88077431950f0854e16759e8619fcbb4173b708b (diff)
downloadpylint-git-c507592114354e973c475c3600ad23a625645830.tar.gz
Add unit tests for OutputLine
-rw-r--r--pylint/testutils/output_line.py13
-rw-r--r--tests/testutils/test_output_line.py89
2 files changed, 97 insertions, 5 deletions
diff --git a/pylint/testutils/output_line.py b/pylint/testutils/output_line.py
index a5284e47f..492ce7902 100644
--- a/pylint/testutils/output_line.py
+++ b/pylint/testutils/output_line.py
@@ -36,10 +36,13 @@ class MalformedOutputLineException(Exception):
]
reconstructed_row = ""
i = 0
- for i, column in enumerate(row):
- reconstructed_row += f"\t{expected[i]}='{column}' ?\n"
- for missing in expected[i + 1 :]:
- reconstructed_row += f"\t{missing}= Nothing provided !\n"
+ try:
+ for i, column in enumerate(row):
+ reconstructed_row += f"\t{expected[i]}='{column}' ?\n"
+ for missing in expected[i + 1 :]:
+ reconstructed_row += f"\t{missing}= Nothing provided !\n"
+ except IndexError:
+ pass
raw = ":".join(row)
msg = f"""\
{exception}
@@ -73,7 +76,7 @@ class OutputLine(
@classmethod
def get_column(cls, column):
if not PY38_PLUS:
- return ""
+ return "" # pragma: no cover
return str(column)
@classmethod
diff --git a/tests/testutils/test_output_line.py b/tests/testutils/test_output_line.py
new file mode 100644
index 000000000..513d75ee2
--- /dev/null
+++ b/tests/testutils/test_output_line.py
@@ -0,0 +1,89 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+# For details: https://github.com/PyCQA/pylint/blob/master/LICENSE
+
+# pylint: disable=redefined-outer-name
+
+import pytest
+
+from pylint.interfaces import HIGH
+from pylint.message import Message
+from pylint.testutils.output_line import MalformedOutputLineException, OutputLine
+
+
+@pytest.fixture()
+def message():
+ return Message(
+ symbol="missing-docstring",
+ msg_id="C0123",
+ location=[
+ "abspath",
+ "path",
+ "module",
+ "obj",
+ "line",
+ "column",
+ ],
+ msg="msg",
+ confidence=HIGH,
+ )
+
+
+def test_output_line():
+ output_line = OutputLine(
+ symbol="missing-docstring",
+ lineno=0,
+ column=0,
+ object="",
+ msg="Missing docstring's bad.",
+ confidence=HIGH,
+ )
+ assert output_line.symbol == "missing-docstring"
+
+
+def test_output_line_from_message(message):
+ output_line = OutputLine.from_msg(message)
+ assert output_line.symbol == "missing-docstring"
+ assert output_line.msg == "msg"
+
+
+def test_output_line_to_csv(message):
+ output_line = OutputLine.from_msg(message)
+ csv = output_line.to_csv()
+ assert csv == ("missing-docstring", "line", "column", "obj", "msg")
+
+
+def test_output_line_from_csv_error():
+ with pytest.raises(
+ MalformedOutputLineException,
+ match="msg-symbolic-name:42:27:MyClass.my_function:The message",
+ ):
+ OutputLine.from_csv("'missing-docstring', 'line', 'column', 'obj', 'msg'")
+ with pytest.raises(
+ MalformedOutputLineException, match="symbol='missing-docstring' ?"
+ ):
+ csv = ("missing-docstring", "line", "column", "obj", "msg")
+ OutputLine.from_csv(csv)
+
+
+@pytest.mark.parametrize(
+ "confidence,expected", [[None, "HIGH"], ["INFERENCE", "INFERENCE"]]
+)
+def test_output_line_from_csv(confidence, expected):
+ proper_csv = (
+ "missing-docstring",
+ "1",
+ "2",
+ "obj",
+ "msg",
+ )
+ if confidence is not None:
+ proper_csv += (confidence,)
+ output_line = OutputLine.from_csv(proper_csv)
+ assert output_line == OutputLine(
+ symbol="missing-docstring",
+ lineno=1,
+ column="2",
+ object="obj",
+ msg="msg",
+ confidence=expected,
+ )