Skip to content

Commit

Permalink
pytest-lsp: Add additional test cases
Browse files Browse the repository at this point in the history
It's important to also check that warnings are *not* raised when they
are not valid.
  • Loading branch information
alcarney committed Dec 13, 2023
1 parent fbef035 commit 277107d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 6 deletions.
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ repos:
rev: 23.11.0
hooks:
- id: black
exclude: 'lib/pytest-lsp/pytest_lsp/gen.py'

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
name: flake8 (lsp-devtools)
args: [--config=lib/lsp-devtools/setup.cfg]
files: 'lib/lsp-devtools/lsp_devtools/.*\.py'

- id: flake8
name: flake8 (pytest-lsp)
args: [--config=lib/pytest-lsp/setup.cfg]
files: 'lib/pytest-lsp/pytest_lsp/.*\.py'

- repo: https://github.com/pycqa/isort
rev: 5.12.0
Expand All @@ -33,7 +39,6 @@ repos:
name: isort (pytest-lsp)
args: [--settings-file, lib/pytest-lsp/pyproject.toml]
files: 'lib/pytest-lsp/pytest_lsp/.*\.py'
exclude: 'lib/pytest-lsp/pytest_lsp/gen.py'

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.7.0'
Expand Down
1 change: 1 addition & 0 deletions lib/pytest-lsp/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[flake8]
max-line-length = 88
ignore = E501
96 changes: 92 additions & 4 deletions lib/pytest-lsp/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
types.WorkspaceConfigurationParams(items=[]),
"does not support 'workspace/configuration'",
),
(
types.ClientCapabilities(
workspace=types.WorkspaceClientCapabilities(configuration=True)
),
types.WORKSPACE_CONFIGURATION,
types.WorkspaceConfigurationParams(items=[]),
None,
),
],
)
def test_params_check_warning(
Expand Down Expand Up @@ -92,6 +100,20 @@ def test_params_check_warning(
[types.CompletionItem(label="item", commit_characters=["."])],
"does not support commit characters",
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
completion=types.CompletionClientCapabilities(
completion_item=types.CompletionClientCapabilitiesCompletionItemType(
commit_characters_support=True
)
)
)
),
types.TEXT_DOCUMENT_COMPLETION,
[types.CompletionItem(label="item", commit_characters=["."])],
None,
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
Expand All @@ -109,6 +131,27 @@ def test_params_check_warning(
],
"does not support documentation format 'markdown'",
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
completion=types.CompletionClientCapabilities(
completion_item=types.CompletionClientCapabilitiesCompletionItemType(
documentation_format=[types.MarkupKind.Markdown]
)
)
)
),
types.TEXT_DOCUMENT_COMPLETION,
[
types.CompletionItem(
label="item",
documentation=types.MarkupContent(
value="", kind=types.MarkupKind.Markdown
),
)
],
None,
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
Expand All @@ -127,19 +170,52 @@ def test_params_check_warning(
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
document_link=types.DocumentLinkClientCapabilities(
tooltip_support=False
completion=types.CompletionClientCapabilities(
completion_item=types.CompletionClientCapabilitiesCompletionItemType(
snippet_support=True
)
)
)
),
types.TEXT_DOCUMENT_COMPLETION,
[
types.CompletionItem(
label="item",
insert_text_format=types.InsertTextFormat.Snippet,
)
],
None,
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
document_link=types.DocumentLinkClientCapabilities()
)
),
types.TEXT_DOCUMENT_DOCUMENT_LINK,
[types.DocumentLink(range=a_range, tooltip="a tooltip")],
"does not support tooltips",
),
(
types.ClientCapabilities(
text_document=types.TextDocumentClientCapabilities(
document_link=types.DocumentLinkClientCapabilities(
tooltip_support=True
)
)
),
types.TEXT_DOCUMENT_DOCUMENT_LINK,
[types.DocumentLink(range=a_range, tooltip="a tooltip")],
None,
),
],
)
def test_result_check_warning(
capabilities: types.ClientCapabilities, method: str, result: Any, expected: str
capabilities: types.ClientCapabilities,
method: str,
result: Any,
expected: Optional[str],
recwarn,
):
"""Ensure that parameter checks work as expected.
Expand All @@ -156,7 +232,19 @@ def test_result_check_warning(
expected
The expected warning message
recwarn
Builtin fixture from pytest for recording warnings
"""

with pytest.warns(checks.LspSpecificationWarning, match=expected):
if expected is None:
checks.check_result_against_client_capabilities(capabilities, method, result)
assert len(recwarn) == 0

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

checks.check_result_against_client_capabilities(capabilities, method, result)

0 comments on commit 277107d

Please sign in to comment.