|
6 | 6 | from textwrap import dedent |
7 | 7 | from unittest.mock import patch |
8 | 8 |
|
| 9 | +import pytest |
| 10 | + |
9 | 11 | from pylsp import lsp, uris |
10 | 12 | from pylsp.plugins import flake8_lint |
11 | 13 | from pylsp.workspace import Document |
@@ -60,6 +62,33 @@ def test_flake8_lint(workspace) -> None: |
60 | 62 | os.remove(name) |
61 | 63 |
|
62 | 64 |
|
| 65 | +@pytest.mark.parametrize( |
| 66 | + "line, column, expected_character", |
| 67 | + [ |
| 68 | + (" # comment", 0, 0), |
| 69 | + ("", 0, 0), |
| 70 | + (" # comment", 1, 0), |
| 71 | + (" # comment", 5, 4), |
| 72 | + ], |
| 73 | +) |
| 74 | +def test_flake8_diagnostic_columns(workspace, line, column, expected_character) -> None: |
| 75 | + source = f"def myfun():\n{line}\n pass\n" |
| 76 | + doc = Document("", workspace, source) |
| 77 | + output = ( |
| 78 | + f"stdin:2:{column}: ANN201 Missing return type annotation for public function\n" |
| 79 | + ) |
| 80 | + |
| 81 | + with patch("pylsp.plugins.flake8_lint.run_flake8", return_value=output): |
| 82 | + diagnostics = flake8_lint.pylsp_lint(workspace, doc) |
| 83 | + |
| 84 | + assert len(diagnostics) == 1 |
| 85 | + assert diagnostics[0]["range"] == { |
| 86 | + "start": {"line": 1, "character": expected_character}, |
| 87 | + "end": {"line": 1, "character": len(line) + 1}, |
| 88 | + } |
| 89 | + assert diagnostics[0]["code"] == "ANN201" |
| 90 | + |
| 91 | + |
63 | 92 | def test_flake8_respecting_configuration(workspace) -> None: |
64 | 93 | docs = [ |
65 | 94 | ("src/__init__.py", ""), |
|
0 commit comments