Skip to content

Commit

Permalink
Code action test should wait for diagnostics. #66 (#223)
Browse files Browse the repository at this point in the history
Co-authored-by: Eleanor Boyd <[email protected]>
  • Loading branch information
jessienguyen2312 and eleanorjboyd authored Oct 5, 2023
1 parent 9a1ea5b commit 65e3d76
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/test/python_tests/test_code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import os
from threading import Event

import pytest
from hamcrest import assert_that, is_
Expand All @@ -14,6 +15,7 @@
TEST_FILE_PATH = constants.TEST_DATA / "sample1" / "sample.py"
TEST_FILE_URI = utils.as_uri(str(TEST_FILE_PATH))
LINTER = utils.get_server_info_defaults()["name"]
TIMEOUT = 10 # 10 seconds


@pytest.mark.parametrize(
Expand Down Expand Up @@ -223,11 +225,22 @@
)
def test_command_code_action(code, contents, command):
"""Tests for code actions which run a command."""

actual = []
with utils.python_file(contents, TEST_FILE_PATH.parent) as temp_file:
uri = utils.as_uri(os.fspath(temp_file))
with session.LspSession() as ls_session:
ls_session.initialize()

done = Event()

def _handler(params):
nonlocal actual
actual = params
done.set()

ls_session.set_notification_callback(session.PUBLISH_DIAGNOSTICS, _handler)

ls_session.notify_did_open(
{
"textDocument": {
Expand All @@ -239,6 +252,9 @@ def test_command_code_action(code, contents, command):
}
)

# wait for some time to receive all notifications
done.wait(TIMEOUT)

diagnostics = [
{
"range": {
Expand Down

0 comments on commit 65e3d76

Please sign in to comment.