Skip to content

Commit 61338fa

Browse files
committed
Changing how debounce is controlled during testing
1 parent 93f6f91 commit 61338fa

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

hdl_checker/tests/test_lsp.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
)
5555
from tabulate import tabulate
5656

57-
# pylint: disable=wrong-import-position
5857
from hdl_checker.tests import getTestTempPath, setupTestSuport, toCheckerDiagnostic
5958

60-
from hdl_checker import DEFAULT_LIBRARY
59+
import hdl_checker
60+
from hdl_checker import DEFAULT_LIBRARY, lsp
6161
from hdl_checker.diagnostics import CheckerDiagnostic
6262
from hdl_checker.parsers.elements.dependency_spec import RequiredDesignUnit
6363
from hdl_checker.parsers.elements.design_unit import (
@@ -70,27 +70,6 @@
7070
from hdl_checker.types import Location
7171
from hdl_checker.utils import ON_WINDOWS
7272

73-
74-
# Debouncing will hurt testing since it won't actually call the debounced
75-
# function if we call it too quickly.
76-
def noDebounce(interval_s, keyed_by=None): # pylint: disable=unused-argument
77-
def wrapper(func):
78-
def debounced(*args, **kwargs):
79-
result = func(*args, **kwargs)
80-
_logger.info("%s(%s, %s) returned %s", func.__name__, args, kwargs, result)
81-
return result
82-
83-
return debounced
84-
85-
return wrapper
86-
87-
88-
# This has to come before import hdl_checker.lsp
89-
import hdl_checker # isort:skip
90-
91-
hdl_checker.utils.debounce = noDebounce
92-
from hdl_checker import lsp # isort:skip
93-
9473
_logger = logging.getLogger(__name__)
9574

9675
TEST_TEMP_PATH = getTestTempPath(__name__)
@@ -269,7 +248,11 @@ def checkLintFileOnMethod(
269248
with patch.object(
270249
self.server.checker, "getMessagesByPath", return_value=list(expected_diags),
271250
):
272-
self.client.lsp.send_request(method, params).result(LSP_REQUEST_TIMEOUT)
251+
hdl_checker.utils.ENABLE_DEBOUNCE = False
252+
try:
253+
self.client.lsp.send_request(method, params).result(LSP_REQUEST_TIMEOUT)
254+
finally:
255+
hdl_checker.utils.ENABLE_DEBOUNCE = True
273256

274257
self.assertTrue(
275258
self.client_diagnostics, "Expected client to have diagnostics"

hdl_checker/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ def onNewReleaseFound(func):
461461
)
462462

463463

464+
ENABLE_DEBOUNCE = True
465+
464466
# Copied from pyls (see
465467
# https://github.com/palantir/python-language-server/blob/d81c7ba14d54b8e52192b0e00cbb4dacbb6f414d/pyls/_utils.py#L22-L47)
466468
def debounce(interval_s, keyed_by=None):
@@ -477,6 +479,11 @@ def debounced(*args, **kwargs):
477479
else:
478480
key = None
479481

482+
# Could not find a way to disable debouncing whilist testing, so
483+
# we'll use a module var
484+
if not ENABLE_DEBOUNCE:
485+
return func(*args, **kwargs)
486+
480487
def run():
481488
with lock:
482489
del timers[key]

0 commit comments

Comments
 (0)