File: test_pydocstyle_lint.py

package info (click to toggle)
python-lsp-server 1.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 796 kB
  • sloc: python: 7,791; sh: 12; makefile: 4
file content (59 lines) | stat: -rw-r--r-- 1,803 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

import os

from pylsp import lsp, uris
from pylsp.plugins import pydocstyle_lint
from pylsp.workspace import Document

DOC_URI = uris.from_fs_path(os.path.join(os.path.dirname(__file__), "pydocstyle.py"))
TEST_DOC_URI = uris.from_fs_path(__file__)

DOC = """import sys

def hello():
\tpass

import json
"""


def test_pydocstyle(config, workspace) -> None:
    doc = Document(DOC_URI, workspace, DOC)
    diags = pydocstyle_lint.pylsp_lint(config, workspace, doc)

    assert all(d["source"] == "pydocstyle" for d in diags)

    # One we're expecting is:
    assert diags[0] == {
        "code": "D100",
        "message": "D100: Missing docstring in public module",
        "severity": lsp.DiagnosticSeverity.Warning,
        "range": {
            "start": {"line": 0, "character": 0},
            "end": {"line": 0, "character": 11},
        },
        "source": "pydocstyle",
    }


def test_pydocstyle_test_document(config, workspace) -> None:
    # The default --match argument excludes test_* documents.
    doc = Document(TEST_DOC_URI, workspace, "")
    diags = pydocstyle_lint.pylsp_lint(config, workspace, doc)
    assert not diags


def test_pydocstyle_empty_source(config, workspace) -> None:
    doc = Document(DOC_URI, workspace, "")
    diags = pydocstyle_lint.pylsp_lint(config, workspace, doc)
    assert diags[0]["message"] == "D100: Missing docstring in public module"
    assert len(diags) == 1


def test_pydocstyle_invalid_source(config, workspace) -> None:
    doc = Document(DOC_URI, workspace, "bad syntax")
    diags = pydocstyle_lint.pylsp_lint(config, workspace, doc)
    # We're unable to parse the file, so can't get any pydocstyle diagnostics
    assert not diags