|
2 | 2 |
|
3 | 3 | import os
|
4 | 4 | import time
|
5 |
| -from unittest.mock import patch, call |
6 | 5 |
|
| 6 | +from unittest.mock import patch, call |
7 | 7 | from test.fixtures import CALL_TIMEOUT_IN_SECONDS
|
8 |
| - |
9 | 8 | import pytest
|
| 9 | +from pylsp.workspace import Notebook |
10 | 10 |
|
11 | 11 | from pylsp import IS_WIN
|
12 | 12 | from pylsp.lsp import NotebookCellKind
|
@@ -37,6 +37,59 @@ def test_initialize(client_server_pair):
|
37 | 37 | assert isinstance(selector, list)
|
38 | 38 |
|
39 | 39 |
|
| 40 | +@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") |
| 41 | +def test_workspace_did_change_configuration(client_server_pair): |
| 42 | + """Test that we can update a workspace config w/o error when a notebook is open.""" |
| 43 | + client, server = client_server_pair |
| 44 | + client._endpoint.request( |
| 45 | + "initialize", |
| 46 | + { |
| 47 | + "processId": 1234, |
| 48 | + "rootPath": os.path.dirname(__file__), |
| 49 | + }, |
| 50 | + ).result(timeout=CALL_TIMEOUT_IN_SECONDS) |
| 51 | + assert server.workspace is not None |
| 52 | + |
| 53 | + with patch.object(server._endpoint, "notify") as mock_notify: |
| 54 | + client._endpoint.notify( |
| 55 | + "notebookDocument/didOpen", |
| 56 | + { |
| 57 | + "notebookDocument": { |
| 58 | + "uri": "notebook_uri", |
| 59 | + "notebookType": "jupyter-notebook", |
| 60 | + "cells": [ |
| 61 | + { |
| 62 | + "kind": NotebookCellKind.Code, |
| 63 | + "document": "cell_1_uri", |
| 64 | + }, |
| 65 | + ], |
| 66 | + }, |
| 67 | + "cellTextDocuments": [ |
| 68 | + { |
| 69 | + "uri": "cell_1_uri", |
| 70 | + "languageId": "python", |
| 71 | + "text": "", |
| 72 | + }, |
| 73 | + ], |
| 74 | + }, |
| 75 | + ) |
| 76 | + wait_for_condition(lambda: mock_notify.call_count >= 1) |
| 77 | + assert isinstance(server.workspace.get_document("notebook_uri"), Notebook) |
| 78 | + assert len(server.workspace.documents) == 2 |
| 79 | + |
| 80 | + server.workspace.update_config( |
| 81 | + {"pylsp": {"plugins": {"flake8": {"enabled": True}}}} |
| 82 | + ) |
| 83 | + |
| 84 | + assert server.config.plugin_settings("flake8").get("enabled") is True |
| 85 | + assert ( |
| 86 | + server.workspace.get_document("cell_1_uri") |
| 87 | + ._config.plugin_settings("flake8") |
| 88 | + .get("enabled") |
| 89 | + is True |
| 90 | + ) |
| 91 | + |
| 92 | + |
40 | 93 | @pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
|
41 | 94 | def test_notebook_document__did_open(
|
42 | 95 | client_server_pair,
|
|
0 commit comments