-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from anu-ka/test-initialization
Test for invalid initialization options
- Loading branch information
Showing
2 changed files
with
80 additions
and
3 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,53 @@ | ||
"""Tests for initialization options over language server protocol.""" | ||
|
||
import copy | ||
from threading import Event | ||
|
||
from hamcrest import assert_that, is_ | ||
|
||
from tests.lsp_test_client import defaults, session | ||
|
||
|
||
def test_invalid_initialization_options() -> None: | ||
"""Test what happens when invalid initialization is sent.""" | ||
initialize_params = copy.deepcopy(defaults.VSCODE_DEFAULT_INITIALIZE) | ||
initialize_params["initializationOptions"]["diagnostics"] = 1 | ||
|
||
with session.LspSession() as ls_session: | ||
window_show_message_done = Event() | ||
window_log_message_done = Event() | ||
|
||
actual = [] | ||
|
||
def _window_show_message_handler(params): | ||
actual.append(params) | ||
window_show_message_done.set() | ||
|
||
ls_session.set_notification_callback( | ||
session.WINDOW_SHOW_MESSAGE, _window_show_message_handler | ||
) | ||
|
||
def _window_log_message_handler(params): | ||
actual.append(params) | ||
window_log_message_done.set() | ||
|
||
ls_session.set_notification_callback( | ||
session.WINDOW_LOG_MESSAGE, _window_log_message_handler | ||
) | ||
|
||
ls_session.initialize(initialize_params) | ||
|
||
window_show_message_done.wait(5) | ||
window_log_message_done.wait(5) | ||
expected = [ | ||
{ | ||
"type": 1, | ||
"message": "Invalid InitializationOptions, using defaults: 1 validation error for InitializationOptions\ndiagnostics\n value is not a valid dict (type=type_error.dict)", | ||
}, | ||
{ | ||
"type": 1, | ||
"message": "Invalid InitializationOptions, using defaults: 1 validation error for InitializationOptions\ndiagnostics\n value is not a valid dict (type=type_error.dict)", | ||
}, | ||
] | ||
|
||
assert_that(actual, is_(expected)) |