Skip to content

Commit

Permalink
CI/Completion: Fix instrospection testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dalthviz committed May 1, 2024
1 parent 8ff1d87 commit e8a7c37
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 61 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ on:
- '**.bat'
- '**.py'
- '**.sh'
- '!installers*/**'
- '!.github/workflows/installer*.yml'
- '!installers-conda/**'
- '!.github/workflows/installers-conda.yml'
- '!.github/workflows/build-subrepos.yml'

pull_request:
branches:
Expand All @@ -30,8 +31,9 @@ on:
- '**.bat'
- '**.py'
- '**.sh'
- '!installers*/**'
- '!.github/workflows/installer*.yml'
- '!installers-conda/**'
- '!.github/workflows/installers-conda.yml'
- '!.github/workflows/build-subrepos.yml'

workflow_dispatch:

Expand All @@ -53,7 +55,7 @@ jobs:
PYTHON_VERSION: ${{ matrix.PYTHON_VERSION }}
RUN_SLOW: ${{ matrix.TEST_TYPE == 'slow' }}
USE_CONDA: ${{ matrix.INSTALL_TYPE == 'conda' }}
USE_GDB: 'true'
USE_GDB: 'false'
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -138,17 +140,21 @@ jobs:
- name: Run tests with gdb
if: env.USE_GDB == 'true'
shell: bash -l {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: xvfb-run --auto-servernum gdb -return-child-result -batch -ex r -ex py-bt --args python runtests.py -s
- name: Run tests
shell: bash -l {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
rm -f pytest_log.txt # Must remove any log file from a previous run
.github/scripts/run_tests.sh || \
.github/scripts/run_tests.sh || \
.github/scripts/run_tests.sh || \
.github/scripts/run_tests.sh
- name: Coverage
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
verbose: true
11 changes: 6 additions & 5 deletions spyder/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,13 @@ def main_window(request, tmpdir, qtbot):
use_introspection = request.node.get_closest_marker('use_introspection')

if use_introspection:
os.environ['SPY_TEST_USE_INTROSPECTION'] = 'True'
CONF.set('completions', ('enabled_providers', 'lsp'), True)
CONF.set('completions', ('enabled_providers', 'fallback'), True)
CONF.set('completions', ('enabled_providers', 'snippets'), True)
else:
try:
os.environ.pop('SPY_TEST_USE_INTROSPECTION')
except KeyError:
pass
CONF.set('completions', ('enabled_providers', 'lsp'), False)
CONF.set('completions', ('enabled_providers', 'fallback'), False)
CONF.set('completions', ('enabled_providers', 'snippets'), False)

# Only use single_instance mode for tests that require it
single_instance = request.node.get_closest_marker('single_instance')
Expand Down
13 changes: 4 additions & 9 deletions spyder/plugins/completion/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,6 @@ def get_icon(cls):
def on_initialize(self):
self.sig_interpreter_changed.connect(self.update_completion_status)

# Do not start providers on tests unless necessary
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
# Prevent providers from receiving configuration updates
for provider_name in self.providers:
provider_info = self.providers[provider_name]
CONF.unobserve_configuration(provider_info['instance'])
return

self.start_all_providers()

@on_plugin_available(plugin=Plugins.Preferences)
Expand Down Expand Up @@ -379,6 +370,8 @@ def can_close(self) -> bool:
provider = provider_info['instance']
provider_can_close = provider.can_close()
can_close |= provider_can_close
else:
can_close |= True
return can_close

def on_close(self, cancelable=False) -> bool:
Expand All @@ -392,6 +385,8 @@ def on_close(self, cancelable=False) -> bool:
can_close |= provider_can_close
if provider_can_close:
provider.shutdown()
else:
can_close |= True
return can_close

def after_configuration_update(self, options: List[Union[tuple, str]]):
Expand Down
1 change: 1 addition & 0 deletions spyder/plugins/completion/providers/fallback/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def stop(self):
with QMutexLocker(self.mutex):
logger.debug("Fallback plugin stopping...")
self.thread.quit()
self.thread.wait()

def start(self):
"""Start thread."""
Expand Down
26 changes: 1 addition & 25 deletions spyder/plugins/completion/providers/languageserver/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,13 +463,6 @@ def start_completion_services_for_language(self, language):
language_client = self.clients[language]

queue = self.register_queue[language]

# Don't start LSP services when testing unless we demand
# them.
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return started

started = language_client['status'] == self.RUNNING

if language not in self.clients_hearbeat:
Expand Down Expand Up @@ -567,41 +560,24 @@ def file_opened_closed_or_updated(self, filename: str, language: str):
@on_conf_change
def update_configuration(self, config):
self.config = config
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return
self.update_lsp_configuration()

@on_conf_change(section='outline_explorer',
option=['group_cells', 'show_comments'])
def on_pyls_spyder_configuration_change(self, option, value):
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return
self.update_lsp_configuration()

@on_conf_change(section='completions', option='enable_code_snippets')
def on_code_snippets_enabled_disabled(self, value):
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return
self.update_lsp_configuration()

@on_conf_change(section='pythonpath_manager', option='spyder_pythonpath')
def on_pythonpath_option_update(self, value):
# This is only useful to run some self-contained tests
if (
running_under_pytest()
and os.environ.get('SPY_TEST_USE_INTROSPECTION')
):
self.update_lsp_configuration(python_only=True)
self.update_lsp_configuration(python_only=True)

@on_conf_change(section='main_interpreter',
option=['default', 'custom_interpreter'])
def on_main_interpreter_change(self, option, value):
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return
self.update_lsp_configuration()

def update_lsp_configuration(self, python_only=False):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

import os
from unittest.mock import Mock, MagicMock

from qtpy.QtCore import QObject, Signal, Slot
Expand Down Expand Up @@ -45,7 +44,6 @@ def wrapper(qtbot_module, request):
conf['stdio'] = is_stdio

# Create the manager
os.environ['SPY_TEST_USE_INTROSPECTION'] = 'True'
provider = LanguageServerProvider(CompletionPluginMock(conf), conf)

# Wait for the client to be started
Expand All @@ -60,7 +58,6 @@ def wrapper(qtbot_module, request):

def teardown():
provider.shutdown()
os.environ['SPY_TEST_USE_INTROSPECTION'] = 'False'

request.addfinalizer(teardown)
return provider
Expand Down
4 changes: 0 additions & 4 deletions spyder/plugins/completion/providers/snippets/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ def send_request(self, language, req_type, req, req_id=None):

@on_conf_change
def update_snippets(self, snippets):
if running_under_pytest():
if not os.environ.get('SPY_TEST_USE_INTROSPECTION'):
return

self.config = snippets
snippet_info = {}
for language in SUPPORTED_LANGUAGES_PY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

# Standard library imports
import os

# Testing imports
import pytest
from qtpy.QtCore import QObject, Signal
Expand All @@ -27,16 +24,13 @@ def handle_response(self, client, req_id, response):

@pytest.fixture(scope='module')
def snippets_completions(qtbot_module, request):
os.environ['SPY_TEST_USE_INTROSPECTION'] = 'True'

snippets = SnippetsProvider(None, dict(SnippetsProvider.CONF_DEFAULTS))
completions = CompletionManagerMock(None)

with qtbot_module.waitSignal(snippets.sig_provider_ready, timeout=30000):
snippets.start()

def teardown():
os.environ.pop('SPY_TEST_USE_INTROSPECTION')
snippets.shutdown()

request.addfinalizer(teardown)
Expand Down
3 changes: 0 additions & 3 deletions spyder/plugins/completion/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# (see spyder/__init__.py for details)

# Standard library imports
import os
from unittest.mock import Mock, MagicMock

# Third party imports
Expand Down Expand Up @@ -88,7 +87,6 @@ def completion_plugin_all_started(request, qtbot_module,

completion_plugin = completion_plugin_all

os.environ['SPY_TEST_USE_INTROSPECTION'] = 'True'
completion_plugin.wait_for_ms = 20000
completion_plugin.start_all_providers()

Expand All @@ -111,7 +109,6 @@ def wait_until_all_started():
capabilities, _ = blocker.args

def teardown():
os.environ['SPY_TEST_USE_INTROSPECTION'] = 'False'
completion_plugin.stop_all_providers()

request.addfinalizer(teardown)
Expand Down

0 comments on commit e8a7c37

Please sign in to comment.