Skip to content

Commit

Permalink
pytest-lsp: Add test cases covering existing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alcarney committed Nov 12, 2023
1 parent 3ba4d36 commit 57bf078
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pytest-lsp/pytest_lsp/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def check_completion_item(

if isinstance(item.documentation, types.MarkupContent):
kind = item.documentation.kind
message = f"Client does not support documentation format '{kind}'"
message = f"Client does not support documentation format {kind.value!r}"
assert kind in documentation_formats, message

if item.insert_text_format == types.InsertTextFormat.Snippet:
Expand Down
88 changes: 88 additions & 0 deletions lib/pytest-lsp/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

from pytest_lsp import checks

a_range = types.Range(
start=types.Position(line=1, character=0),
end=types.Position(line=2, character=0),
)


@pytest.mark.parametrize(
"capabilities,method,params,expected",
Expand Down Expand Up @@ -41,3 +46,86 @@ def test_params_check_warning(

with pytest.warns(checks.LspSpecificationWarning, match=expected):
checks.check_params_against_client_capabilities(capabilities, method, params)


@pytest.mark.parametrize(
"capabilities,method,result,expected",
[
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
completion=types.CompletionClientCapabilities()
)
),
types.TEXT_DOCUMENT_COMPLETION,
[types.CompletionItem(label="item", commit_characters=["."])],
"does not support commit characters",
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
completion=types.CompletionClientCapabilities()
)
),
types.TEXT_DOCUMENT_COMPLETION,
[
types.CompletionItem(
label="item",
documentation=types.MarkupContent(
value="", kind=types.MarkupKind.Markdown
),
)
],
"does not support documentation format 'markdown'",
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
completion=types.CompletionClientCapabilities()
)
),
types.TEXT_DOCUMENT_COMPLETION,
[
types.CompletionItem(
label="item",
insert_text_format=types.InsertTextFormat.Snippet,
)
],
"does not support snippets",
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
document_link=types.DocumentLinkClientCapabilities(
tooltip_support=False
)
)
),
types.TEXT_DOCUMENT_DOCUMENT_LINK,
[types.DocumentLink(range=a_range, tooltip="a tooltip")],
"does not support tooltips",
),
],
)
def test_result_check_warning(
capabilities: types.ClientCapabilities, method: str, result: Any, expected: str
):
"""Ensure that parameter checks work as expected.
Parameters
----------
capabilities
The client's capabilities
method
The method name to check
params
The params to check
expected
The expected warning message
"""

with pytest.warns(checks.LspSpecificationWarning, match=expected):
checks.check_result_against_client_capabilities(capabilities, method, result)

0 comments on commit 57bf078

Please sign in to comment.