|
| 1 | +# Copyright 2021- Python Language Server Contributors. |
| 2 | + |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +from test.test_utils import send_initialize_request |
| 6 | +from test.test_notebook_document import wait_for_condition |
| 7 | + |
| 8 | +import pytest |
| 9 | + |
| 10 | +from pylsp import IS_WIN |
| 11 | + |
| 12 | + |
| 13 | +INITIALIZATION_OPTIONS = { |
| 14 | + "pylsp": { |
| 15 | + "plugins": { |
| 16 | + "flake8": {"enabled": True}, |
| 17 | + "pycodestyle": {"enabled": False}, |
| 18 | + "pyflakes": {"enabled": False}, |
| 19 | + }, |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") |
| 25 | +def test_set_flake8_using_init_opts(client_server_pair): |
| 26 | + client, server = client_server_pair |
| 27 | + send_initialize_request(client, INITIALIZATION_OPTIONS) |
| 28 | + for key, value in INITIALIZATION_OPTIONS["pylsp"]["plugins"].items(): |
| 29 | + assert server.workspace._config.settings().get("plugins").get(key).get( |
| 30 | + "enabled" |
| 31 | + ) == value.get("enabled") |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") |
| 35 | +def test_set_flake8_using_workspace_did_change_configuration(client_server_pair): |
| 36 | + client, server = client_server_pair |
| 37 | + send_initialize_request(client, None) |
| 38 | + assert ( |
| 39 | + server.workspace._config.settings().get("plugins").get("flake8").get("enabled") |
| 40 | + is False |
| 41 | + ) |
| 42 | + |
| 43 | + with patch.object(server.workspace, "update_config") as mock_update_config: |
| 44 | + client._endpoint.notify( |
| 45 | + "workspace/didChangeConfiguration", |
| 46 | + {"settings": INITIALIZATION_OPTIONS}, |
| 47 | + ) |
| 48 | + wait_for_condition(lambda: mock_update_config.call_count >= 1) |
| 49 | + |
| 50 | + for key, value in INITIALIZATION_OPTIONS["pylsp"]["plugins"].items(): |
| 51 | + assert server.workspace._config.settings().get("plugins").get(key).get( |
| 52 | + "enabled" |
| 53 | + ) == value.get("enabled") |
0 commit comments