Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrabel-db committed Oct 15, 2023
1 parent 13fb7fc commit 7f77bad
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions test/test_notebook_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import os
import time
from unittest.mock import patch, call

from unittest.mock import patch, call
from test.fixtures import CALL_TIMEOUT_IN_SECONDS

import pytest
from pylsp.workspace import Notebook

from pylsp import IS_WIN
from pylsp.lsp import NotebookCellKind
Expand Down Expand Up @@ -37,6 +37,59 @@ def test_initialize(client_server_pair):
assert isinstance(selector, list)


@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
def test_workspace_did_change_configuration(client_server_pair):
"""Test that we can update a workspace config w/o error when a notebook is open."""
client, server = client_server_pair
client._endpoint.request(
"initialize",
{
"processId": 1234,
"rootPath": os.path.dirname(__file__),
},
).result(timeout=CALL_TIMEOUT_IN_SECONDS)
assert server.workspace is not None

with patch.object(server._endpoint, "notify") as mock_notify:
client._endpoint.notify(
"notebookDocument/didOpen",
{
"notebookDocument": {
"uri": "notebook_uri",
"notebookType": "jupyter-notebook",
"cells": [
{
"kind": NotebookCellKind.Code,
"document": "cell_1_uri",
},
],
},
"cellTextDocuments": [
{
"uri": "cell_1_uri",
"languageId": "python",
"text": "",
},
],
},
)
wait_for_condition(lambda: mock_notify.call_count >= 1)
assert isinstance(server.workspace.get_document("notebook_uri"), Notebook)
assert len(server.workspace.documents) == 2

server.workspace.update_config(
{"pylsp": {"plugins": {"flake8": {"enabled": True}}}}
)

assert server.config.plugin_settings("flake8").get("enabled") is True
assert (
server.workspace.get_document("cell_1_uri")
._config.plugin_settings("flake8")
.get("enabled")
is True
)


@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
def test_notebook_document__did_open(
client_server_pair,
Expand Down

0 comments on commit 7f77bad

Please sign in to comment.