-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest-lsp: Passthrough requested fixtures to user fixture func
- Loading branch information
Showing
6 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixtures created with the `@pytest_lsp.fixture` decorator can now request additional pytest fixtures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
lib/pytest-lsp/tests/examples/fixture-passthrough/server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from lsprotocol.types import TEXT_DOCUMENT_COMPLETION | ||
from lsprotocol.types import CompletionItem | ||
from lsprotocol.types import CompletionParams | ||
from pygls.server import LanguageServer | ||
|
||
server = LanguageServer("hello-world", "v1") | ||
|
||
|
||
@server.feature(TEXT_DOCUMENT_COMPLETION) | ||
def completion(ls: LanguageServer, params: CompletionParams): | ||
return [ | ||
CompletionItem(label="hello"), | ||
CompletionItem(label="world"), | ||
] | ||
|
||
|
||
if __name__ == "__main__": | ||
server.start_io() |
52 changes: 52 additions & 0 deletions
52
lib/pytest-lsp/tests/examples/fixture-passthrough/t_server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import sys | ||
|
||
import pytest | ||
from lsprotocol.types import CompletionList | ||
from lsprotocol.types import CompletionParams | ||
from lsprotocol.types import InitializeParams | ||
from lsprotocol.types import Position | ||
from lsprotocol.types import TextDocumentIdentifier | ||
|
||
import pytest_lsp | ||
from pytest_lsp import ClientServerConfig | ||
from pytest_lsp import LanguageClient | ||
from pytest_lsp import client_capabilities | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def client_name(): | ||
return "neovim" | ||
|
||
|
||
@pytest_lsp.fixture( | ||
config=ClientServerConfig(server_command=[sys.executable, "server.py"]), | ||
) | ||
async def client(client_name: str, lsp_client: LanguageClient): | ||
# Setup | ||
params = InitializeParams(capabilities=client_capabilities(client_name)) | ||
await lsp_client.initialize_session(params) | ||
|
||
yield | ||
|
||
# Teardown | ||
await lsp_client.shutdown_session() | ||
|
||
|
||
async def test_completions(client: LanguageClient): | ||
"""Ensure that the server implements completions correctly.""" | ||
|
||
results = await client.text_document_completion_async( | ||
params=CompletionParams( | ||
position=Position(line=1, character=0), | ||
text_document=TextDocumentIdentifier(uri="file:///path/to/file.txt"), | ||
) | ||
) | ||
assert results is not None | ||
|
||
if isinstance(results, CompletionList): | ||
items = results.items | ||
else: | ||
items = results | ||
|
||
labels = [item.label for item in items] | ||
assert labels == ["hello", "world"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters