Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code action test should wait for diagnostics #223

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this in seconds or milliseconds?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is seconds. Python in most cases uses seconds and floating point for milliseconds



@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
Loading