def mock_completions_codeeditor(qtbot_module, request): """CodeEditor instance with ability to mock the completions response. Returns a tuple of (editor, mock_response). Tests using this fixture should set `mock_response.side_effect = lambda lang, method, params: {}`. """ # Create a CodeEditor instance editor = codeeditor_factory() qtbot_module.addWidget(editor) editor.show() mock_response = Mock() def perform_request(lang, method, params): resp = mock_response(lang, method, params) print("DEBUG {}".format(resp)) if resp is not None: editor.handle_response(method, resp) editor.sig_perform_completion_request.connect(perform_request) editor.filename = 'test.py' editor.language = 'Python' editor.completions_available = True qtbot_module.wait(2000) def teardown(): editor.hide() editor.completion_widget.hide() request.addfinalizer(teardown) return editor, mock_response
def search_codeeditor(completions_codeeditor, qtbot_module, request): code_editor, _ = completions_codeeditor find_replace = FindReplace(None, enable_replace=True) find_replace.set_editor(code_editor) qtbot_module.addWidget(find_replace) def teardown(): find_replace.hide() request.addfinalizer(teardown) return code_editor, find_replace
def completions_codeeditor(completion_plugin_all_started, qtbot_module, request, capsys, tmp_path): """CodeEditor instance with LSP services activated.""" # Create a CodeEditor instance editor = codeeditor_factory() qtbot_module.addWidget(editor) completion_plugin, capabilities = completion_plugin_all_started completion_plugin.wait_for_ms = 2000 CONF.set('completions', 'enable_code_snippets', False) completion_plugin.after_configuration_update([]) CONF.notify_section_all_observers('completions') # Redirect editor LSP requests to lsp_manager editor.sig_perform_completion_request.connect( completion_plugin.send_request) file_path = tmp_path / 'test.py' file_path.write_text('') editor.filename = str(file_path) editor.language = 'Python' completion_plugin.register_file('python', str(file_path), editor) editor.start_completion_services() editor.register_completion_capabilities(capabilities) with qtbot_module.waitSignal( editor.completions_response_signal, timeout=30000): editor.document_did_open() def teardown(): editor.completion_widget.hide() editor.tooltip_widget.hide() editor.hide() # Capture stderr and assert there are no errors sys_stream = capsys.readouterr() sys_err = sys_stream.err if PY2: sys_err = to_text_string(sys_err).encode('utf-8') assert sys_err == '' request.addfinalizer(teardown) editor.show() return editor, completion_plugin
def snippets_completions(qtbot_module, request): snippets = SnippetsProvider(None, dict(SnippetsProvider.CONF_DEFAULTS)) completions = CompletionManagerMock(None) qtbot_module.addWidget(snippets) qtbot_module.addWidget(completions) with qtbot_module.waitSignal(snippets.sig_provider_ready, timeout=30000): snippets.start() def teardown(): snippets.shutdown() request.addfinalizer(teardown) snippets.sig_response_ready.connect(completions.handle_response) return snippets, completions
def fallback_completions(qtbot_module, request): fallback = FallbackProvider(None, {}) completions = CompletionManagerMock(None) qtbot_module.addWidget(fallback) qtbot_module.addWidget(completions) with qtbot_module.waitSignal(fallback.sig_provider_ready, timeout=30000): fallback.start() def teardown(): fallback.shutdown() request.addfinalizer(teardown) fallback.sig_response_ready.connect(completions.handle_response) return fallback, completions
def kite_codeeditor(qtbot_module, request): """ CodeEditor instance with Kite enabled. NOTE: This fixture only works if used with kite installed. If running in the CI, the installation of Kite could be accomplished by spyder/plugins/completion/kite/utils/tests/test_install.py::test_kite_install Any test running with this fixture should run after the installation test mentioned above. """ main = MainWindowWidgetMock() completions = CompletionManager(main, ['kite']) completions.start() completions.start_client('python') completions.language_status['python']['kite'] = True qtbot_module.addWidget(completions) # Create a CodeEditor instance editor = codeeditor_factory() qtbot_module.addWidget(editor) editor.show() # Redirect editor fallback requests to FallbackActor editor.sig_perform_completion_request.connect(completions.send_request) editor.filename = 'test.py' editor.language = 'Python' editor.completions_available = True qtbot_module.wait(2000) def teardown(): completions.shutdown() editor.hide() editor.completion_widget.hide() request.addfinalizer(teardown) kite = completions.get_client('kite') CONF.set('kite', 'show_installation_dialog', False) CONF.set('kite', 'show_onboarding', False) CONF.set('kite', 'call_to_action', False) kite.update_configuration() return editor, kite