From d49d754e500dbbf879cda516d9e6a29f342d3fa5 Mon Sep 17 00:00:00 2001 From: Toni Date: Tue, 30 Jul 2024 18:59:00 +0200 Subject: [PATCH] fixing ruff --- pylsp/__main__.py | 4 +- pylsp/_utils.py | 4 +- pylsp/plugins/definition.py | 9 +- pylsp/plugins/flake8_lint.py | 7 +- pylsp/plugins/folding.py | 28 ++++-- pylsp/plugins/highlight.py | 4 +- pylsp/plugins/hover.py | 4 +- pylsp/plugins/jedi_completion.py | 16 +++- pylsp/plugins/pylint_lint.py | 8 +- pylsp/plugins/references.py | 4 +- pylsp/plugins/rope_autoimport.py | 12 ++- pylsp/plugins/rope_completion.py | 8 +- pylsp/plugins/signature.py | 7 +- test/fixtures.py | 12 ++- test/plugins/test_autoimport.py | 128 ++++++++++++++++++++++----- test/plugins/test_autopep8_format.py | 26 ++++-- test/plugins/test_completion.py | 96 +++++++++++++++----- test/plugins/test_flake8_lint.py | 20 +++-- test/plugins/test_hover.py | 37 +++++--- test/plugins/test_jedi_rename.py | 16 +++- test/plugins/test_mccabe_lint.py | 4 +- test/plugins/test_pylint_lint.py | 31 +++++-- test/plugins/test_references.py | 4 +- test/plugins/test_signature.py | 12 ++- test/plugins/test_yapf_format.py | 40 +++++++-- test/test_configuration.py | 4 +- test/test_language_server.py | 4 +- test/test_utils.py | 6 +- 28 files changed, 428 insertions(+), 127 deletions(-) diff --git a/pylsp/__main__.py b/pylsp/__main__.py index 9ee8861a..29f2d240 100644 --- a/pylsp/__main__.py +++ b/pylsp/__main__.py @@ -71,7 +71,9 @@ def main() -> None: parser = argparse.ArgumentParser() add_arguments(parser) args = parser.parse_args() - _configure_logger(verbose=args.verbose, log_config=args.log_config, log_file=args.log_file) + _configure_logger( + verbose=args.verbose, log_config=args.log_config, log_file=args.log_file + ) if args.tcp: start_tcp_lang_server( diff --git a/pylsp/_utils.py b/pylsp/_utils.py index a77fffa7..01b130b1 100644 --- a/pylsp/_utils.py +++ b/pylsp/_utils.py @@ -264,7 +264,9 @@ def position_to_jedi_linecolumn(document, position): code_position = { "line": position["line"] + 1, "column": clip_column( - column=position["character"], lines=document.lines, line_number=position["line"] + column=position["character"], + lines=document.lines, + line_number=position["line"], ), } return code_position diff --git a/pylsp/plugins/definition.py b/pylsp/plugins/definition.py index 8b3b1958..950b8381 100644 --- a/pylsp/plugins/definition.py +++ b/pylsp/plugins/definition.py @@ -46,7 +46,9 @@ def pylsp_definitions( config: Config, document: Document, position: Dict[str, int] ) -> List[Dict[str, Any]]: settings = config.plugin_settings("jedi_definition") - code_position = _utils.position_to_jedi_linecolumn(document=document, position=position) + code_position = _utils.position_to_jedi_linecolumn( + document=document, position=position + ) script = document.jedi_script(use_document_path=True) auto_import_modules = jedi.settings.auto_import_modules @@ -57,7 +59,10 @@ def pylsp_definitions( follow_builtin_imports=settings.get("follow_builtin_imports", True), **code_position, ) - definitions = [_resolve_definition(maybe_defn=d, script=script, settings=settings) for d in definitions] + definitions = [ + _resolve_definition(maybe_defn=d, script=script, settings=settings) + for d in definitions + ] finally: jedi.settings.auto_import_modules = auto_import_modules diff --git a/pylsp/plugins/flake8_lint.py b/pylsp/plugins/flake8_lint.py index 95b58961..df154c29 100644 --- a/pylsp/plugins/flake8_lint.py +++ b/pylsp/plugins/flake8_lint.py @@ -98,7 +98,12 @@ def pylsp_lint(workspace, document): # ensure the same source is used for flake8 execution and result parsing; # single source access improves performance as it is only one disk access source = document.source - output = run_flake8(flake8_executable=flake8_executable, args=args, document=document, source=source) + output = run_flake8( + flake8_executable=flake8_executable, + args=args, + document=document, + source=source, + ) return parse_stdout(source=source, stdout=output) diff --git a/pylsp/plugins/folding.py b/pylsp/plugins/folding.py index dd0f1195..361adf65 100644 --- a/pylsp/plugins/folding.py +++ b/pylsp/plugins/folding.py @@ -88,18 +88,28 @@ def __compute_folding_ranges_identation(text): current_level = level elif level < current_level: identation_stack, folding_ranges = __match_identation_stack( - identation_stack=identation_stack, level=level, level_limits=level_limits, folding_ranges=folding_ranges, current_line=current_line + identation_stack=identation_stack, + level=level, + level_limits=level_limits, + folding_ranges=folding_ranges, + current_line=current_line, ) current_level = level else: folding_ranges = __empty_identation_stack( - identation_stack=identation_stack, level_limits=level_limits, current_line=current_line, folding_ranges=folding_ranges + identation_stack=identation_stack, + level_limits=level_limits, + current_line=current_line, + folding_ranges=folding_ranges, ) current_level = 0 if line.strip() != "": current_line = i folding_ranges = __empty_identation_stack( - identation_stack=identation_stack, level_limits=level_limits, current_line=current_line, folding_ranges=folding_ranges + identation_stack=identation_stack, + level_limits=level_limits, + current_line=current_line, + folding_ranges=folding_ranges, ) return dict(folding_ranges) @@ -154,7 +164,9 @@ def __compute_start_end_lines(node, stack): start_line, _ = node.start_pos end_line, _ = node.end_pos modified = False - end_line, from_keyword, node, stack = __handle_flow_nodes(node=node, end_line=end_line, stack=stack) + end_line, from_keyword, node, stack = __handle_flow_nodes( + node=node, end_line=end_line, stack=stack + ) last_leaf = node.get_last_leaf() last_newline = isinstance(last_leaf, tree_nodes.Newline) @@ -194,12 +206,16 @@ def __compute_folding_ranges(tree, lines): padding = [""] * start_line text = "\n".join(padding + lines[start_line:]) + "\n" identation_ranges = __compute_folding_ranges_identation(text) - folding_ranges = __merge_folding_ranges(left=folding_ranges, right=identation_ranges) + folding_ranges = __merge_folding_ranges( + left=folding_ranges, right=identation_ranges + ) break if not isinstance(node, SKIP_NODES): valid = __check_if_node_is_valid(node) if valid: - start_line, end_line, stack = __compute_start_end_lines(node=node, stack=stack) + start_line, end_line, stack = __compute_start_end_lines( + node=node, stack=stack + ) if end_line > start_line: current_end = folding_ranges.get(start_line, -1) folding_ranges[start_line] = max(current_end, end_line) diff --git a/pylsp/plugins/highlight.py b/pylsp/plugins/highlight.py index f1640bd3..b88ffaad 100644 --- a/pylsp/plugins/highlight.py +++ b/pylsp/plugins/highlight.py @@ -10,7 +10,9 @@ @hookimpl def pylsp_document_highlight(document, position): - code_position = _utils.position_to_jedi_linecolumn(document=document, position=position) + code_position = _utils.position_to_jedi_linecolumn( + document=document, position=position + ) usages = document.jedi_script().get_references(**code_position) def is_valid(definition): diff --git a/pylsp/plugins/hover.py b/pylsp/plugins/hover.py index f36b4c0b..192f712c 100644 --- a/pylsp/plugins/hover.py +++ b/pylsp/plugins/hover.py @@ -10,7 +10,9 @@ @hookimpl def pylsp_hover(config, document, position): - code_position = _utils.position_to_jedi_linecolumn(document=document, position=position) + code_position = _utils.position_to_jedi_linecolumn( + document=document, position=position + ) definitions = document.jedi_script(use_document_path=True).infer(**code_position) word = document.word_at_position(position) diff --git a/pylsp/plugins/jedi_completion.py b/pylsp/plugins/jedi_completion.py index 2c9e8bd7..e2f0d5af 100644 --- a/pylsp/plugins/jedi_completion.py +++ b/pylsp/plugins/jedi_completion.py @@ -40,7 +40,9 @@ def pylsp_completions(config, document, position): """Get formatted completions for current code position""" settings = config.plugin_settings("jedi_completion", document_path=document.path) resolve_eagerly = settings.get("eager", False) - code_position = _utils.position_to_jedi_linecolumn(document=document, position=position) + code_position = _utils.position_to_jedi_linecolumn( + document=document, position=position + ) code_position["fuzzy"] = settings.get("fuzzy", False) completions = document.jedi_script(use_document_path=True).complete(**code_position) @@ -67,7 +69,9 @@ def pylsp_completions(config, document, position): SNIPPET_RESOLVER.cached_modules = modules_to_cache_for include_params = ( - snippet_support and should_include_params and use_snippets(document=document, position=position) + snippet_support + and should_include_params + and use_snippets(document=document, position=position) ) include_class_objects = ( snippet_support @@ -152,7 +156,9 @@ def pylsp_completion_item_resolve(config, completion_item, document): if shared_data: completion, data = shared_data - return _resolve_completion(completion=completion, d=data, markup_kind=preferred_markup_kind) + return _resolve_completion( + completion=completion, d=data, markup_kind=preferred_markup_kind + ) return completion_item @@ -237,7 +243,9 @@ def _format_completion( } if resolve: - completion = _resolve_completion(completion=completion, d=d, markup_kind=markup_kind) + completion = _resolve_completion( + completion=completion, d=d, markup_kind=markup_kind + ) # Adjustments for file completions if d.type == "path": diff --git a/pylsp/plugins/pylint_lint.py b/pylsp/plugins/pylint_lint.py index 546dafb4..c6483618 100644 --- a/pylsp/plugins/pylint_lint.py +++ b/pylsp/plugins/pylint_lint.py @@ -223,7 +223,9 @@ def pylsp_lint(config, workspace, document, is_saved): if settings.get("executable") and sys.version_info[0] >= 3: flags = build_args_stdio(settings) pylint_executable = settings.get("executable", "pylint") - return pylint_lint_stdin(pylint_executable=pylint_executable, document=document, flags=flags) + return pylint_lint_stdin( + pylint_executable=pylint_executable, document=document, flags=flags + ) flags = _build_pylint_flags(settings) return PylintLinter.lint(document, is_saved, flags=flags) @@ -260,7 +262,9 @@ def pylint_lint_stdin(pylint_executable, document, flags): :return: linting diagnostics :rtype: list """ - pylint_result = _run_pylint_stdio(pylint_executable=pylint_executable, document=document, flags=flags) + pylint_result = _run_pylint_stdio( + pylint_executable=pylint_executable, document=document, flags=flags + ) return _parse_pylint_stdio_result(document=document, stdout=pylint_result) diff --git a/pylsp/plugins/references.py b/pylsp/plugins/references.py index 91a4e69e..1649ac15 100644 --- a/pylsp/plugins/references.py +++ b/pylsp/plugins/references.py @@ -10,7 +10,9 @@ @hookimpl def pylsp_references(document, position, exclude_declaration): - code_position = _utils.position_to_jedi_linecolumn(document=document, position=position) + code_position = _utils.position_to_jedi_linecolumn( + document=document, position=position + ) usages = document.jedi_script().get_references(**code_position) if exclude_declaration: diff --git a/pylsp/plugins/rope_autoimport.py b/pylsp/plugins/rope_autoimport.py index 14ec0c0e..cc0eafd0 100644 --- a/pylsp/plugins/rope_autoimport.py +++ b/pylsp/plugins/rope_autoimport.py @@ -193,7 +193,10 @@ def _process_statements( edit_range = {"start": start, "end": start} edit = {"range": edit_range, "newText": suggestion.import_statement + "\n"} score = _get_score( - source=suggestion.source, full_statement=suggestion.import_statement, suggested_name=suggestion.name, desired_name=word + source=suggestion.source, + full_statement=suggestion.import_statement, + suggested_name=suggestion.name, + desired_name=word, ) if score > _score_max: continue @@ -258,7 +261,12 @@ def pylsp_completions( suggestions = list(autoimport.search_full(word, ignored_names=ignored_names)) results = sorted( _process_statements( - suggestions=suggestions, doc_uri=document.uri, word=word, autoimport=autoimport, document=document, feature="completions" + suggestions=suggestions, + doc_uri=document.uri, + word=word, + autoimport=autoimport, + document=document, + feature="completions", ), key=lambda statement: statement["sortText"], ) diff --git a/pylsp/plugins/rope_completion.py b/pylsp/plugins/rope_completion.py index 6f3c80e5..8ea04040 100644 --- a/pylsp/plugins/rope_completion.py +++ b/pylsp/plugins/rope_completion.py @@ -74,7 +74,9 @@ def pylsp_completions(config, workspace, document, position): "data": {"doc_uri": document.uri}, } if resolve_eagerly: - item = _resolve_completion(completion=item, data=d, markup_kind=preferred_markup_kind) + item = _resolve_completion( + completion=item, data=d, markup_kind=preferred_markup_kind + ) new_definitions.append(item) # most recently retrieved completion items, used for resolution @@ -105,7 +107,9 @@ def pylsp_completion_item_resolve(config, completion_item, document): if shared_data: completion, data = shared_data - return _resolve_completion(completion=completion, data=data, markup_kind=preferred_markup_kind) + return _resolve_completion( + completion=completion, data=data, markup_kind=preferred_markup_kind + ) return completion_item diff --git a/pylsp/plugins/signature.py b/pylsp/plugins/signature.py index 5395f25e..e192e159 100644 --- a/pylsp/plugins/signature.py +++ b/pylsp/plugins/signature.py @@ -17,7 +17,9 @@ @hookimpl def pylsp_signature_help(config, document, position): - code_position = _utils.position_to_jedi_linecolumn(document=document, position=position) + code_position = _utils.position_to_jedi_linecolumn( + document=document, position=position + ) signatures = document.jedi_script().get_signatures(**code_position) if not signatures: @@ -54,7 +56,8 @@ def pylsp_signature_help(config, document, position): { "label": p.name, "documentation": _utils.format_docstring( - contents=_param_docs(docstring=docstring, param_name=p.name), markup_kind=preferred_markup_kind + contents=_param_docs(docstring=docstring, param_name=p.name), + markup_kind=preferred_markup_kind, ), } for p in s.params diff --git a/test/fixtures.py b/test/fixtures.py index 01b64f27..e1be4ae6 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -115,7 +115,9 @@ class Dispatcher(FakeEditorMethodsMixin, MethodDispatcher): def workspace(tmpdir, endpoint) -> None: """Return a workspace.""" ws = Workspace(root_uri=uris.from_fs_path(str(tmpdir)), endpoint=endpoint) - ws._config = Config(root_uri=ws.root_uri, init_opts={}, process_id=0, capabilities={}) + ws._config = Config( + root_uri=ws.root_uri, init_opts={}, process_id=0, capabilities={} + ) yield ws ws.close() @@ -125,14 +127,18 @@ def workspace_other_root_path(tmpdir, endpoint): """Return a workspace with a root_path other than tmpdir.""" ws_path = str(tmpdir.mkdir("test123").mkdir("test456")) ws = Workspace(root_uri=uris.from_fs_path(ws_path), endpoint=endpoint) - ws._config = Config(root_uri=ws.root_uri, init_opts={}, process_id=0, capabilities={}) + ws._config = Config( + root_uri=ws.root_uri, init_opts={}, process_id=0, capabilities={} + ) return ws @pytest.fixture def config(workspace): """Return a config object.""" - cfg = Config(root_uri=workspace.root_uri, init_opts={}, process_id=0, capabilities={}) + cfg = Config( + root_uri=workspace.root_uri, init_opts={}, process_id=0, capabilities={} + ) cfg._plugin_settings = { "plugins": {"pylint": {"enabled": False, "args": [], "executable": None}} } diff --git a/test/plugins/test_autoimport.py b/test/plugins/test_autoimport.py index ebbb3d36..cd1ead04 100644 --- a/test/plugins/test_autoimport.py +++ b/test/plugins/test_autoimport.py @@ -42,9 +42,12 @@ def contains_autoimport_quickfix(suggestion: Dict[str, Any], module: str) -> boo def autoimport_workspace(tmp_path_factory) -> Workspace: "Special autoimport workspace. Persists across sessions to make in-memory sqlite3 database fast." workspace = Workspace( - root_uri=uris.from_fs_path(str(tmp_path_factory.mktemp("pylsp"))), endpoint=Mock() + root_uri=uris.from_fs_path(str(tmp_path_factory.mktemp("pylsp"))), + endpoint=Mock(), + ) + workspace._config = Config( + root_uri=workspace.root_uri, init_opts={}, process_id=0, capabilities={} ) - workspace._config = Config(root_uri=workspace.root_uri, init_opts={}, process_id=0, capabilities={}) workspace._config.update( { "rope_autoimport": { @@ -67,7 +70,11 @@ def completions(config: Config, autoimport_workspace: Workspace, request) -> Non autoimport_workspace.put_document(DOC_URI, source=document) doc = autoimport_workspace.get_document(DOC_URI) yield pylsp_autoimport_completions( - config=config, workspace=autoimport_workspace, document=doc, position=com_position, ignored_names=None + config=config, + workspace=autoimport_workspace, + document=doc, + position=com_position, + ignored_names=None, ) autoimport_workspace.rm_document(DOC_URI) @@ -89,7 +96,8 @@ def check_dict(query: Dict, results: List[Dict]) -> bool: def test_autoimport_completion(completions) -> None: assert completions assert check_dict( - query={"label": "pathlib", "kind": lsp.CompletionItemKind.Module}, results=completions + query={"label": "pathlib", "kind": lsp.CompletionItemKind.Module}, + results=completions, ) @@ -171,7 +179,11 @@ def test_autoimport_defined_name(config, workspace) -> None: workspace.put_document(DOC_URI, source=document) doc = workspace.get_document(DOC_URI) completions = pylsp_autoimport_completions( - config=config, workspace=workspace, document=doc, position=com_position, ignored_names=None + config=config, + workspace=workspace, + document=doc, + position=com_position, + ignored_names=None, ) workspace.rm_document(DOC_URI) assert not check_dict(query={"label": "List"}, results=completions) @@ -196,24 +208,50 @@ def test_from(self) -> None: def test_sort_sources() -> None: - result1 = _get_score(source=1, full_statement="import pathlib", suggested_name="pathlib", desired_name="pathli") - result2 = _get_score(source=2, full_statement="import pathlib", suggested_name="pathlib", desired_name="pathli") + result1 = _get_score( + source=1, + full_statement="import pathlib", + suggested_name="pathlib", + desired_name="pathli", + ) + result2 = _get_score( + source=2, + full_statement="import pathlib", + suggested_name="pathlib", + desired_name="pathli", + ) assert result1 < result2 def test_sort_statements() -> None: result1 = _get_score( - source=2, full_statement="from importlib_metadata import pathlib", suggested_name="pathlib", desired_name="pathli" + source=2, + full_statement="from importlib_metadata import pathlib", + suggested_name="pathlib", + desired_name="pathli", + ) + result2 = _get_score( + source=2, + full_statement="import pathlib", + suggested_name="pathlib", + desired_name="pathli", ) - result2 = _get_score(source=2, full_statement="import pathlib", suggested_name="pathlib", desired_name="pathli") assert result1 > result2 def test_sort_both() -> None: result1 = _get_score( - source=3, full_statement="from importlib_metadata import pathlib", suggested_name="pathlib", desired_name="pathli" + source=3, + full_statement="from importlib_metadata import pathlib", + suggested_name="pathlib", + desired_name="pathli", + ) + result2 = _get_score( + source=2, + full_statement="import pathlib", + suggested_name="pathlib", + desired_name="pathli", ) - result2 = _get_score(source=2, full_statement="import pathlib", suggested_name="pathlib", desired_name="pathli") assert result1 > result2 @@ -302,7 +340,9 @@ def test_autoimport_code_actions_and_completions_for_notebook_document( # already imported in the second cell. # 4. We receive an autoimport suggestion for "sys" because it's not already imported. # 5. If diagnostics doesn't contain "undefined name ...", we send empty quick fix suggestions. - send_notebook_did_open(client=client, cells=["os", "import os\nos", "os", "sys"]) + send_notebook_did_open( + client=client, cells=["os", "import os\nos", "os", "sys"] + ) wait_for_condition(lambda: mock_notify.call_count >= 4) # We received diagnostics messages for every cell assert all( @@ -318,29 +358,69 @@ def test_autoimport_code_actions_and_completions_for_notebook_document( wait_for_condition(lambda: not cache.is_blocked()) # 1. - quick_fixes = server.code_actions("cell_1_uri", {}, make_context(module_name="os", line=0, character_start=0, character_end=2)) - assert any(s for s in quick_fixes if contains_autoimport_quickfix(suggestion=s, module="os")) + quick_fixes = server.code_actions( + "cell_1_uri", + {}, + make_context(module_name="os", line=0, character_start=0, character_end=2), + ) + assert any( + s + for s in quick_fixes + if contains_autoimport_quickfix(suggestion=s, module="os") + ) - completions = server.completions("cell_1_uri", position(line=0, character=2)).get("items") - assert any(s for s in completions if contains_autoimport_completion(suggestion=s, module="os")) + completions = server.completions("cell_1_uri", position(line=0, character=2)).get( + "items" + ) + assert any( + s + for s in completions + if contains_autoimport_completion(suggestion=s, module="os") + ) # 2. # We don't test code actions here as in this case, there would be no code actions sent bc # there wouldn't be a diagnostics message. - completions = server.completions("cell_2_uri", position(line=1, character=2)).get("items") - assert not any(s for s in completions if contains_autoimport_completion(suggestion=s, module="os")) + completions = server.completions("cell_2_uri", position(line=1, character=2)).get( + "items" + ) + assert not any( + s + for s in completions + if contains_autoimport_completion(suggestion=s, module="os") + ) # 3. # Same as in 2. - completions = server.completions("cell_3_uri", position(line=0, character=2)).get("items") - assert not any(s for s in completions if contains_autoimport_completion(suggestion=s, module="os")) + completions = server.completions("cell_3_uri", position(line=0, character=2)).get( + "items" + ) + assert not any( + s + for s in completions + if contains_autoimport_completion(suggestion=s, module="os") + ) # 4. - quick_fixes = server.code_actions("cell_4_uri", {}, make_context(module_name="sys", line=0, character_start=0, character_end=3)) - assert any(s for s in quick_fixes if contains_autoimport_quickfix(suggestion=s, module="sys")) + quick_fixes = server.code_actions( + "cell_4_uri", + {}, + make_context(module_name="sys", line=0, character_start=0, character_end=3), + ) + assert any( + s + for s in quick_fixes + if contains_autoimport_quickfix(suggestion=s, module="sys") + ) - completions = server.completions("cell_4_uri", position(line=0, character=3)).get("items") - assert any(s for s in completions if contains_autoimport_completion(suggestion=s, module="sys")) + completions = server.completions("cell_4_uri", position(line=0, character=3)).get( + "items" + ) + assert any( + s + for s in completions + if contains_autoimport_completion(suggestion=s, module="sys") + ) # 5. context = {"diagnostics": [{"message": "A random message"}]} diff --git a/test/plugins/test_autopep8_format.py b/test/plugins/test_autopep8_format.py index 852370d4..6c34ca81 100644 --- a/test/plugins/test_autopep8_format.py +++ b/test/plugins/test_autopep8_format.py @@ -41,7 +41,9 @@ def func(): def test_format(config, workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) - res = pylsp_format_document(config=config, workspace=workspace, document=doc, options=None) + res = pylsp_format_document( + config=config, workspace=workspace, document=doc, options=None + ) assert len(res) == 1 assert res[0]["newText"] == "a = 123\n\n\ndef func():\n pass\n" @@ -53,7 +55,9 @@ def test_range_format(config, workspace) -> None: "start": {"line": 0, "character": 0}, "end": {"line": 2, "character": 0}, } - res = pylsp_format_range(config=config, workspace=workspace, document=doc, range=def_range, options=None) + res = pylsp_format_range( + config=config, workspace=workspace, document=doc, range=def_range, options=None + ) assert len(res) == 1 @@ -64,12 +68,16 @@ def test_range_format(config, workspace) -> None: def test_no_change(config, workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=GOOD_DOC) - assert not pylsp_format_document(config=config, workspace=workspace, document=doc, options=None) + assert not pylsp_format_document( + config=config, workspace=workspace, document=doc, options=None + ) def test_hanging_indentation(config, workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=INDENTED_DOC) - res = pylsp_format_document(config=config, workspace=workspace, document=doc, options=None) + res = pylsp_format_document( + config=config, workspace=workspace, document=doc, options=None + ) assert len(res) == 1 assert res[0]["newText"] == CORRECT_INDENTED_DOC @@ -77,8 +85,14 @@ def test_hanging_indentation(config, workspace) -> None: @pytest.mark.parametrize("newline", ["\r\n", "\r"]) def test_line_endings(config, workspace, newline) -> None: - doc = Document(uri=DOC_URI, workspace=workspace, source=f"import os;import sys{2 * newline}dict(a=1)") - res = pylsp_format_document(config=config, workspace=workspace, document=doc, options=None) + doc = Document( + uri=DOC_URI, + workspace=workspace, + source=f"import os;import sys{2 * newline}dict(a=1)", + ) + res = pylsp_format_document( + config=config, workspace=workspace, document=doc, options=None + ) assert ( res[0]["newText"] diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index 05a5608a..5b8e78cb 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -54,7 +54,9 @@ def documented_hello(): def test_rope_import_completion(config, workspace) -> None: com_position = {"line": 0, "character": 7} doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) - items = pylsp_rope_completions(config=config, workspace=workspace, document=doc, position=com_position) + items = pylsp_rope_completions( + config=config, workspace=workspace, document=doc, position=com_position + ) assert items is None @@ -142,7 +144,9 @@ def test_jedi_completion(config, workspace) -> None: assert "isfile(path)" in labels # Test we don't throw with big character - pylsp_jedi_completions(config=config, document=doc, position={"line": 1, "character": 1000}) + pylsp_jedi_completions( + config=config, document=doc, position={"line": 1, "character": 1000} + ) def test_jedi_completion_item_resolve(config, workspace) -> None: @@ -150,7 +154,9 @@ def test_jedi_completion_item_resolve(config, workspace) -> None: com_position = {"line": 8, "character": 0} doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) config.update({"plugins": {"jedi_completion": {"resolve_at_most": math.inf}}}) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) items = {c["label"]: c for c in completions} @@ -185,7 +191,9 @@ def test_jedi_completion_with_fuzzy_enabled(config, workspace) -> None: assert items[0]["label"] == expected # Test we don't throw with big character - pylsp_jedi_completions(config=config, document=doc, position={"line": 1, "character": 1000}) + pylsp_jedi_completions( + config=config, document=doc, position={"line": 1, "character": 1000} + ) def test_jedi_completion_resolve_at_most(config, workspace) -> None: @@ -211,7 +219,9 @@ def test_rope_completion(config, workspace) -> None: com_position = {"line": 1, "character": 15} workspace.put_document(DOC_URI, source=DOC) doc = workspace.get_document(DOC_URI) - items = pylsp_rope_completions(config=config, workspace=workspace, document=doc, position=com_position) + items = pylsp_rope_completions( + config=config, workspace=workspace, document=doc, position=com_position + ) assert items assert items[0]["label"] == "isabs" @@ -222,7 +232,9 @@ def test_jedi_completion_ordering(config, workspace) -> None: com_position = {"line": 8, "character": 0} doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) config.update({"plugins": {"jedi_completion": {"resolve_at_most": math.inf}}}) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) items = {c["label"]: c["sortText"] for c in completions} @@ -234,7 +246,9 @@ def test_jedi_property_completion(config, workspace) -> None: # Over the 'w' in 'print Hello().world' com_position = {"line": 18, "character": 15} doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) items = {c["label"]: c["sortText"] for c in completions} @@ -252,7 +266,9 @@ def test_jedi_method_completion(config, workspace) -> None: } config.update({"plugins": {"jedi_completion": {"include_params": True}}}) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) everyone_method = [ completion for completion in completions @@ -266,7 +282,9 @@ def test_jedi_method_completion(config, workspace) -> None: # Disable param snippets config.update({"plugins": {"jedi_completion": {"include_params": False}}}) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) everyone_method = [ completion for completion in completions @@ -286,7 +304,9 @@ def test_pyqt_completion(config, workspace) -> None: doc_pyqt = "from PyQt5.QtWidgets import QA" com_position = {"line": 0, "character": len(doc_pyqt)} doc = Document(uri=DOC_URI, workspace=workspace, source=doc_pyqt) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) assert completions is not None @@ -329,11 +349,15 @@ def test_snippets_completion(config, workspace) -> None: "completion": {"completionItem": {"snippetSupport": True}} } config.update({"plugins": {"jedi_completion": {"include_params": True}}}) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) assert completions[0]["insertText"] == "defaultdict" com_position = {"line": 1, "character": len(doc_snippets)} - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) assert completions[0]["insertText"] == "defaultdict($0)" assert completions[0]["insertTextFormat"] == lsp.InsertTextFormat.Snippet @@ -348,7 +372,9 @@ def test_snippets_completion_at_most(config, workspace) -> None: config.update({"plugins": {"jedi_completion": {"resolve_at_most": 0}}}) com_position = {"line": 1, "character": len(doc_snippets)} - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) assert completions[0]["insertText"] == "defaultdict" assert not completions[0].get("insertTextFormat", None) @@ -370,7 +396,9 @@ def test_completion_with_class_objects(config, workspace) -> None: } } ) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) assert len(completions) == 2 assert completions[0]["label"] == "FOOBAR" @@ -397,7 +425,9 @@ def test_completion_with_function_objects(config, workspace) -> None: } } ) - completions = pylsp_jedi_completions(config=config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=com_position + ) assert len(completions) == 2 assert completions[0]["label"] == "foobar()" @@ -415,7 +445,9 @@ def test_snippet_parsing(config, workspace) -> None: "completion": {"completionItem": {"snippetSupport": True}} } config.update({"plugins": {"jedi_completion": {"include_params": True}}}) - completions = pylsp_jedi_completions(config=config, document=doc, position=completion_position) + completions = pylsp_jedi_completions( + config=config, document=doc, position=completion_position + ) out = "divmod(${1:x}, ${2:y})$0" if JEDI_VERSION == "0.18.0": @@ -494,7 +526,9 @@ def spam(): # After 'foo.s' without extra paths com_position = {"line": 1, "character": 5} - completions = pylsp_jedi_completions(config=doc._config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=doc._config, document=doc, position=com_position + ) assert completions is None # Update config extra paths @@ -503,7 +537,9 @@ def spam(): # After 'foo.s' with extra paths com_position = {"line": 1, "character": 5} - completions = pylsp_jedi_completions(config=doc._config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=doc._config, document=doc, position=com_position + ) assert completions[0]["label"] == "spam()" @@ -523,7 +559,9 @@ def test_jedi_completion_environment(workspace) -> None: settings = {"pylsp": {"plugins": {"jedi": {"environment": None}}}} doc.update_config(settings) - completions = pylsp_jedi_completions(config=doc._config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=doc._config, document=doc, position=com_position + ) assert completions is None # Update config extra environment @@ -532,10 +570,14 @@ def test_jedi_completion_environment(workspace) -> None: doc.update_config(settings) # After 'import logh' with new environment - completions = pylsp_jedi_completions(config=doc._config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=doc._config, document=doc, position=com_position + ) assert completions[0]["label"] == "loghub" - resolved = pylsp_jedi_completion_item_resolve(config=doc._config, completion_item=completions[0], document=doc) + resolved = pylsp_jedi_completion_item_resolve( + config=doc._config, completion_item=completions[0], document=doc + ) assert "changelog generator" in resolved["documentation"]["value"].lower() @@ -558,7 +600,9 @@ def foo(): doc = Document(uri=doc_uri, workspace=workspace_other_root_path, source=doc_content) com_position = {"line": 1, "character": 10} - completions = pylsp_jedi_completions(config=doc._config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=doc._config, document=doc, position=com_position + ) assert completions[0]["label"] == "foo()" @@ -576,7 +620,9 @@ def test_file_completions(workspace, tmpdir) -> None: # Request for completions com_position = {"line": 0, "character": 1} - completions = pylsp_jedi_completions(config=doc._config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=doc._config, document=doc, position=com_position + ) # Check completions assert len(completions) == 2 @@ -591,7 +637,9 @@ def test_file_completions(workspace, tmpdir) -> None: "textDocument": {"completion": {"completionItem": {"snippetSupport": True}}} } doc._config.capabilities.update(support_snippet) - completions = pylsp_jedi_completions(config=doc._config, document=doc, position=com_position) + completions = pylsp_jedi_completions( + config=doc._config, document=doc, position=com_position + ) assert completions[0]["insertText"] == ( ("bar" + "\\\\") if os.name == "nt" else ("bar" + "\\/") ) diff --git a/test/plugins/test_flake8_lint.py b/test/plugins/test_flake8_lint.py index 0005eec4..66cb180d 100644 --- a/test/plugins/test_flake8_lint.py +++ b/test/plugins/test_flake8_lint.py @@ -93,7 +93,9 @@ def test_flake8_respecting_configuration(workspace) -> None: workspace.put_document(made[rel]["uri"], contents) made[rel]["document"] = workspace._docs[made[rel]["uri"]] - diags = flake8_lint.pylsp_lint(workspace=workspace, document=made["src/a.py"]["document"]) + diags = flake8_lint.pylsp_lint( + workspace=workspace, document=made["src/a.py"]["document"] + ) assert diags == [ { "source": "flake8", @@ -108,7 +110,9 @@ def test_flake8_respecting_configuration(workspace) -> None: }, ] - diags = flake8_lint.pylsp_lint(workspace=workspace, document=made["src/b.py"]["document"]) + diags = flake8_lint.pylsp_lint( + workspace=workspace, document=made["src/b.py"]["document"] + ) assert diags == [ { "source": "flake8", @@ -182,7 +186,9 @@ def test_flake8_multiline(workspace) -> None: doc_uri = uris.from_fs_path(os.path.join(workspace.root_path, "blah/__init__.py")) workspace.put_document(doc_uri, doc_str) - flake8_settings = get_flake8_cfg_settings(workspace=workspace, config_str=config_str) + flake8_settings = get_flake8_cfg_settings( + workspace=workspace, config_str=config_str + ) assert "exclude" in flake8_settings assert len(flake8_settings["exclude"]) == 2 @@ -224,7 +230,9 @@ def test_flake8_per_file_ignores(workspace) -> None: doc_uri = uris.from_fs_path(os.path.join(workspace.root_path, "blah/__init__.py")) workspace.put_document(doc_uri, doc_str) - flake8_settings = get_flake8_cfg_settings(workspace=workspace, config_str=config_str) + flake8_settings = get_flake8_cfg_settings( + workspace=workspace, config_str=config_str + ) assert "perFileIgnores" in flake8_settings assert len(flake8_settings["perFileIgnores"]) == 2 @@ -248,7 +256,9 @@ def test_per_file_ignores_alternative_syntax(workspace) -> None: doc_uri = uris.from_fs_path(os.path.join(workspace.root_path, "blah/__init__.py")) workspace.put_document(doc_uri, doc_str) - flake8_settings = get_flake8_cfg_settings(workspace=workspace, config_str=config_str) + flake8_settings = get_flake8_cfg_settings( + workspace=workspace, config_str=config_str + ) assert "perFileIgnores" in flake8_settings assert len(flake8_settings["perFileIgnores"]) == 2 diff --git a/test/plugins/test_hover.py b/test/plugins/test_hover.py index d69cd37f..2b41606a 100644 --- a/test/plugins/test_hover.py +++ b/test/plugins/test_hover.py @@ -38,24 +38,35 @@ def test_numpy_hover(workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=NUMPY_DOC) contents = "" - assert contents in pylsp_hover(config=doc._config, document=doc, position=no_hov_position)["contents"] + assert ( + contents + in pylsp_hover(config=doc._config, document=doc, position=no_hov_position)[ + "contents" + ] + ) contents = "NumPy\n=====\n\nProvides\n" assert ( contents - in pylsp_hover(config=doc._config, document=doc, position=numpy_hov_position_1)["contents"]["value"] + in pylsp_hover(config=doc._config, document=doc, position=numpy_hov_position_1)[ + "contents" + ]["value"] ) contents = "NumPy\n=====\n\nProvides\n" assert ( contents - in pylsp_hover(config=doc._config, document=doc, position=numpy_hov_position_2)["contents"]["value"] + in pylsp_hover(config=doc._config, document=doc, position=numpy_hov_position_2)[ + "contents" + ]["value"] ) contents = "NumPy\n=====\n\nProvides\n" assert ( contents - in pylsp_hover(config=doc._config, document=doc, position=numpy_hov_position_3)["contents"]["value"] + in pylsp_hover(config=doc._config, document=doc, position=numpy_hov_position_3)[ + "contents" + ]["value"] ) # https://github.com/davidhalter/jedi/issues/1746 @@ -65,9 +76,9 @@ def test_numpy_hover(workspace) -> None: contents = "Trigonometric sine, element-wise.\n\n" assert ( contents - in pylsp_hover(config=doc._config, document=doc, position=numpy_sin_hov_position)["contents"][ - "value" - ] + in pylsp_hover( + config=doc._config, document=doc, position=numpy_sin_hov_position + )["contents"]["value"] ) @@ -81,9 +92,13 @@ def test_hover(workspace) -> None: contents = {"kind": "markdown", "value": "```python\nmain()\n```\n\n\nhello world"} - assert {"contents": contents} == pylsp_hover(config=doc._config, document=doc, position=hov_position) + assert {"contents": contents} == pylsp_hover( + config=doc._config, document=doc, position=hov_position + ) - assert {"contents": ""} == pylsp_hover(config=doc._config, document=doc, position=no_hov_position) + assert {"contents": ""} == pylsp_hover( + config=doc._config, document=doc, position=no_hov_position + ) def test_document_path_hover(workspace_other_root_path, tmpdir) -> None: @@ -106,6 +121,8 @@ def foo(): doc = Document(uri=doc_uri, workspace=workspace_other_root_path, source=doc_content) cursor_pos = {"line": 1, "character": 3} - contents = pylsp_hover(config=doc._config, document=doc, position=cursor_pos)["contents"] + contents = pylsp_hover(config=doc._config, document=doc, position=cursor_pos)[ + "contents" + ] assert "A docstring for foo." in contents["value"] diff --git a/test/plugins/test_jedi_rename.py b/test/plugins/test_jedi_rename.py index e6af6b80..63d73626 100644 --- a/test/plugins/test_jedi_rename.py +++ b/test/plugins/test_jedi_rename.py @@ -39,7 +39,13 @@ def test_jedi_rename(tmp_workspace, config) -> None: DOC_URI = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC_NAME)) doc = Document(uri=DOC_URI, workspace=tmp_workspace) - result = pylsp_rename(config=config, workspace=tmp_workspace, document=doc, position=position, new_name="ShouldBeRenamed") + result = pylsp_rename( + config=config, + workspace=tmp_workspace, + document=doc, + position=position, + new_name="ShouldBeRenamed", + ) assert len(result.keys()) == 1 changes = result.get("documentChanges") @@ -86,7 +92,13 @@ def test_jedi_rename(tmp_workspace, config) -> None: DOC_URI = uris.from_fs_path(os.path.join(tmp_workspace.root_path, DOC_NAME_SIMPLE)) doc = Document(uri=DOC_URI, workspace=tmp_workspace) - result = pylsp_rename(config=config, workspace=tmp_workspace, document=doc, position=position, new_name="bar") + result = pylsp_rename( + config=config, + workspace=tmp_workspace, + document=doc, + position=position, + new_name="bar", + ) assert len(result.keys()) == 1 changes = result.get("documentChanges") diff --git a/test/plugins/test_mccabe_lint.py b/test/plugins/test_mccabe_lint.py index f90d1e91..60704a49 100644 --- a/test/plugins/test_mccabe_lint.py +++ b/test/plugins/test_mccabe_lint.py @@ -36,4 +36,6 @@ def test_mccabe(config, workspace) -> None: def test_mccabe_syntax_error(config, workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=DOC_SYNTAX_ERR) - assert mccabe_lint.pylsp_lint(config=config, workspace=workspace, document=doc) is None + assert ( + mccabe_lint.pylsp_lint(config=config, workspace=workspace, document=doc) is None + ) diff --git a/test/plugins/test_pylint_lint.py b/test/plugins/test_pylint_lint.py index f91d4d50..64ff997c 100644 --- a/test/plugins/test_pylint_lint.py +++ b/test/plugins/test_pylint_lint.py @@ -43,7 +43,9 @@ def write_temp_doc(document, contents) -> None: def test_pylint(config, workspace) -> None: with temp_document(doc_text=DOC, workspace=workspace) as doc: - diags = pylint_lint.pylsp_lint(config=config, workspace=workspace, document=doc, is_saved=True) + diags = pylint_lint.pylsp_lint( + config=config, workspace=workspace, document=doc, is_saved=True + ) msg = "[unused-import] Unused import sys" unused_import = [d for d in diags if d["message"] == msg][0] @@ -54,7 +56,9 @@ def test_pylint(config, workspace) -> None: # test running pylint in stdin config.plugin_settings("pylint")["executable"] = "pylint" - diags = pylint_lint.pylsp_lint(config=config, workspace=workspace, document=doc, is_saved=True) + diags = pylint_lint.pylsp_lint( + config=config, workspace=workspace, document=doc, is_saved=True + ) msg = "Unused import sys (unused-import)" unused_import = [d for d in diags if d["message"] == msg][0] @@ -68,7 +72,9 @@ def test_pylint(config, workspace) -> None: def test_syntax_error_pylint(config, workspace) -> None: with temp_document(doc_text=DOC_SYNTAX_ERR, workspace=workspace) as doc: - diag = pylint_lint.pylsp_lint(config=config, workspace=workspace, document=doc, is_saved=True)[0] + diag = pylint_lint.pylsp_lint( + config=config, workspace=workspace, document=doc, is_saved=True + )[0] assert diag["message"].startswith("[syntax-error]") assert diag["message"].count("expected ':'") or diag["message"].count( @@ -81,7 +87,9 @@ def test_syntax_error_pylint(config, workspace) -> None: # test running pylint in stdin config.plugin_settings("pylint")["executable"] = "pylint" - diag = pylint_lint.pylsp_lint(config=config, workspace=workspace, document=doc, is_saved=True)[0] + diag = pylint_lint.pylsp_lint( + config=config, workspace=workspace, document=doc, is_saved=True + )[0] assert diag["message"].count("expected ':'") or diag["message"].count( "invalid syntax" @@ -95,9 +103,14 @@ def test_lint_free_pylint(config, workspace) -> None: # Can't use temp_document because it might give us a file that doesn't # match pylint's naming requirements. We should be keeping this file clean # though, so it works for a test of an empty lint. - ws = Workspace(root_uri=str(Path(__file__).absolute().parents[2]), endpoint=workspace._endpoint) + ws = Workspace( + root_uri=str(Path(__file__).absolute().parents[2]), endpoint=workspace._endpoint + ) assert not pylint_lint.pylsp_lint( - config=config, workspace=ws, document=Document(uri=uris.from_fs_path(__file__), workspace=ws), is_saved=True + config=config, + workspace=ws, + document=Document(uri=uris.from_fs_path(__file__), workspace=ws), + is_saved=True, ) @@ -132,11 +145,13 @@ def test_lint_caching(workspace) -> None: def test_per_file_caching(config, workspace) -> None: # Ensure that diagnostics are cached per-file. with temp_document(doc_text=DOC, workspace=workspace) as doc: - assert pylint_lint.pylsp_lint(config=config, workspace=workspace, document=doc, is_saved=True) + assert pylint_lint.pylsp_lint( + config=config, workspace=workspace, document=doc, is_saved=True + ) assert not pylint_lint.pylsp_lint( config=config, workspace=workspace, document=Document(uri=uris.from_fs_path(__file__), workspace=workspace), - is_saved=False + is_saved=False, ) diff --git a/test/plugins/test_references.py b/test/plugins/test_references.py index 68160878..ac979be5 100644 --- a/test/plugins/test_references.py +++ b/test/plugins/test_references.py @@ -47,7 +47,9 @@ def test_references(tmp_workspace) -> None: assert len(refs) == 3 # Briefly check excluding the definitions (also excludes imports, only counts uses) - no_def_refs = pylsp_references(document=doc1, position=position, exclude_declaration=True) + no_def_refs = pylsp_references( + document=doc1, position=position, exclude_declaration=True + ) assert len(no_def_refs) == 1 # Make sure our definition is correctly located diff --git a/test/plugins/test_signature.py b/test/plugins/test_signature.py index c4296da6..f1915468 100644 --- a/test/plugins/test_signature.py +++ b/test/plugins/test_signature.py @@ -47,7 +47,9 @@ def test_no_signature(workspace) -> None: sig_position = {"line": 9, "character": 0} doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) - sigs = signature.pylsp_signature_help(config=doc._config, document=doc, position=sig_position)["signatures"] + sigs = signature.pylsp_signature_help( + config=doc._config, document=doc, position=sig_position + )["signatures"] assert not sigs @@ -56,7 +58,9 @@ def test_signature(workspace) -> None: sig_position = {"line": 10, "character": 5} doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) - sig_info = signature.pylsp_signature_help(config=doc._config, document=doc, position=sig_position) + sig_info = signature.pylsp_signature_help( + config=doc._config, document=doc, position=sig_position + ) sigs = sig_info["signatures"] assert len(sigs) == 1 @@ -75,7 +79,9 @@ def test_multi_line_signature(workspace) -> None: sig_position = {"line": 17, "character": 5} doc = Document(uri=DOC_URI, workspace=workspace, source=MULTI_LINE_DOC) - sig_info = signature.pylsp_signature_help(config=doc._config, document=doc, position=sig_position) + sig_info = signature.pylsp_signature_help( + config=doc._config, document=doc, position=sig_position + ) sigs = sig_info["signatures"] assert len(sigs) == 1 diff --git a/test/plugins/test_yapf_format.py b/test/plugins/test_yapf_format.py index a0e0f181..00fcbfa0 100644 --- a/test/plugins/test_yapf_format.py +++ b/test/plugins/test_yapf_format.py @@ -31,7 +31,10 @@ def test_format(workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=DOC) res = pylsp_format_document(workspace=workspace, document=doc, options=None) - assert apply_text_edits(doc=doc, text_edits=res) == "A = ['h', 'w', 'a']\n\nB = ['h', 'w']\n" + assert ( + apply_text_edits(doc=doc, text_edits=res) + == "A = ['h', 'w', 'a']\n\nB = ['h', 'w']\n" + ) def test_range_format(workspace) -> None: @@ -44,7 +47,10 @@ def test_range_format(workspace) -> None: res = pylsp_format_range(document=doc, range=def_range, options=None) # Make sure B is still badly formatted - assert apply_text_edits(doc=doc, text_edits=res) == "A = ['h', 'w', 'a']\n\nB = ['h',\n\n\n'w']\n" + assert ( + apply_text_edits(doc=doc, text_edits=res) + == "A = ['h', 'w', 'a']\n\nB = ['h',\n\n\n'w']\n" + ) def test_no_change(workspace) -> None: @@ -70,7 +76,11 @@ def test_config_file(tmpdir, workspace) -> None: @pytest.mark.parametrize("newline", ["\r\n"]) def test_line_endings(workspace, newline) -> None: - doc = Document(uri=DOC_URI, workspace=workspace, source=f"import os;import sys{2 * newline}dict(a=1)") + doc = Document( + uri=DOC_URI, + workspace=workspace, + source=f"import os;import sys{2 * newline}dict(a=1)", + ) res = pylsp_format_document(workspace=workspace, document=doc, options=None) assert ( @@ -81,23 +91,35 @@ def test_line_endings(workspace, newline) -> None: def test_format_with_tab_size_option(workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=FOUR_SPACE_DOC) - res = pylsp_format_document(workspace=workspace, document=doc, options={"tabSize": "8"}) + res = pylsp_format_document( + workspace=workspace, document=doc, options={"tabSize": "8"} + ) - assert apply_text_edits(doc=doc, text_edits=res) == FOUR_SPACE_DOC.replace(" ", " ") + assert apply_text_edits(doc=doc, text_edits=res) == FOUR_SPACE_DOC.replace( + " ", " " + ) def test_format_with_insert_spaces_option(workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=FOUR_SPACE_DOC) - res = pylsp_format_document(workspace=workspace, document=doc, options={"insertSpaces": False}) + res = pylsp_format_document( + workspace=workspace, document=doc, options={"insertSpaces": False} + ) - assert apply_text_edits(doc=doc, text_edits=res) == FOUR_SPACE_DOC.replace(" ", "\t") + assert apply_text_edits(doc=doc, text_edits=res) == FOUR_SPACE_DOC.replace( + " ", "\t" + ) def test_format_with_yapf_specific_option(workspace) -> None: doc = Document(uri=DOC_URI, workspace=workspace, source=FOUR_SPACE_DOC) - res = pylsp_format_document(workspace=workspace, document=doc, options={"USE_TABS": True}) + res = pylsp_format_document( + workspace=workspace, document=doc, options={"USE_TABS": True} + ) - assert apply_text_edits(doc=doc, text_edits=res) == FOUR_SPACE_DOC.replace(" ", "\t") + assert apply_text_edits(doc=doc, text_edits=res) == FOUR_SPACE_DOC.replace( + " ", "\t" + ) def test_format_returns_text_edit_per_line(workspace) -> None: diff --git a/test/test_configuration.py b/test/test_configuration.py index 9be5d543..e8450601 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -22,7 +22,9 @@ @pytest.mark.skipif(IS_WIN, reason="Flaky on Windows") def test_set_flake8_using_init_opts(client_server_pair) -> None: client, server = client_server_pair - send_initialize_request(client=client, initialization_options=INITIALIZATION_OPTIONS) + send_initialize_request( + client=client, initialization_options=INITIALIZATION_OPTIONS + ) for key, value in INITIALIZATION_OPTIONS["pylsp"]["plugins"].items(): assert server.workspace._config.settings().get("plugins").get(key).get( "enabled" diff --git a/test/test_language_server.py b/test/test_language_server.py index 56cb96f7..fb35c654 100644 --- a/test/test_language_server.py +++ b/test/test_language_server.py @@ -21,7 +21,9 @@ def client_exited_server() -> None: """A fixture that sets up a client/server pair that support checking parent process aliveness and assert the server has already exited """ - client_server_pair_obj = ClientServerPair(start_server_in_process=True, check_parent_process=True) + client_server_pair_obj = ClientServerPair( + start_server_in_process=True, check_parent_process=True + ) yield client_server_pair_obj diff --git a/test/test_utils.py b/test/test_utils.py index 90ebe9f9..913efb59 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -192,9 +192,9 @@ def test_find_parents(tmpdir) -> None: path = subsubdir.ensure("path.py") test_cfg = tmpdir.ensure("test.cfg") - assert _utils.find_parents(root=tmpdir.strpath, path=path.strpath, names=["test.cfg"]) == [ - test_cfg.strpath - ] + assert _utils.find_parents( + root=tmpdir.strpath, path=path.strpath, names=["test.cfg"] + ) == [test_cfg.strpath] def test_merge_dicts() -> None: