Пример #1
0
    def wrapper(qtbot_module, request):
        # Activate pycodestyle and pydocstyle
        conf = dict(LanguageServerProvider.CONF_DEFAULTS)
        conf['pycodestyle'] = True
        conf['pydocstyle'] = True
        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
        with qtbot_module.waitSignal(
                provider.sig_language_completions_available,
                timeout=30000) as block:
            provider.start_completion_services_for_language('python')

        capabilities, _ = block.args
        assert all(
            [option in SERVER_CAPABILITES for option in capabilities.keys()])

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

        request.addfinalizer(teardown)
        return provider
Пример #2
0
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
Пример #3
0
def fallback_completions(qtbot_module, request):
    fallback = FallbackProvider(None, {})
    completions = CompletionManagerMock(None)

    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
Пример #4
0
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
Пример #5
0
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)

    snippets.sig_response_ready.connect(completions.handle_response)
    return snippets, completions