diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 20:18:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 20:18:22 +0000 |
commit | 1e5c28f36b0fd2d5ac1683c88d48e3d7c243e993 (patch) | |
tree | a81bb3938f710a181cb8cbb1ded2684711fab802 /tests/lsp_tests | |
parent | Adding upstream version 0.1.27.1. (diff) | |
download | debputy-1e5c28f36b0fd2d5ac1683c88d48e3d7c243e993.tar.xz debputy-1e5c28f36b0fd2d5ac1683c88d48e3d7c243e993.zip |
Adding upstream version 0.1.28.upstream/0.1.28
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/lsp_tests')
-rw-r--r-- | tests/lsp_tests/conftest.py | 36 | ||||
-rw-r--r-- | tests/lsp_tests/lsp_tutil.py | 5 | ||||
-rw-r--r-- | tests/lsp_tests/test_lsp_dctrl.py | 88 | ||||
-rw-r--r-- | tests/lsp_tests/test_lsp_debputy_manifest_completer.py | 21 |
4 files changed, 130 insertions, 20 deletions
diff --git a/tests/lsp_tests/conftest.py b/tests/lsp_tests/conftest.py index ec12e9a..e995d88 100644 --- a/tests/lsp_tests/conftest.py +++ b/tests/lsp_tests/conftest.py @@ -1,5 +1,9 @@ import pytest +from debian.debian_support import DpkgArchTable +from debputy._deb_options_profiles import DebBuildOptionsAndProfiles +from debputy.architecture_support import DpkgArchitectureBuildProcessValuesTable +from debputy.packages import DctrlParser from debputy.plugin.api.feature_set import PluginProvidedFeatureSet from debputy.util import setup_logging @@ -17,7 +21,7 @@ try: HoverParams, MarkupContent, ) - from debputy.lsp.lsp_features import lsp_set_plugin_features + from debputy.lsp.debputy_ls import DebputyLanguageServer HAS_PYGLS = True except ImportError: @@ -29,13 +33,31 @@ def enable_logging() -> None: setup_logging(log_only_to_stderr=True, reconfigure_logging=True) +@pytest.fixture +def lsp_dctrl_parser( + dpkg_arch_query: DpkgArchTable, + amd64_dpkg_architecture_variables: DpkgArchitectureBuildProcessValuesTable, + no_profiles_or_build_options: DebBuildOptionsAndProfiles, +) -> DctrlParser: + return DctrlParser( + frozenset(), + frozenset(), + True, + True, + amd64_dpkg_architecture_variables, + dpkg_arch_query, + no_profiles_or_build_options, + ) + + @pytest.fixture() def ls( debputy_plugin_feature_set: PluginProvidedFeatureSet, -) -> "LanguageServer": + lsp_dctrl_parser: DctrlParser, +) -> "DebputyLanguageServer": if not HAS_PYGLS: pytest.skip("Missing pygls") - ls = LanguageServer("debputy", "v<test>") + ls = DebputyLanguageServer("debputy", "v<test>") ls.lsp.lsp_initialize( InitializeParams( ClientCapabilities( @@ -45,8 +67,6 @@ def ls( ) ) ) - lsp_set_plugin_features(debputy_plugin_feature_set) - try: - yield ls - finally: - lsp_set_plugin_features(None) + ls.plugin_feature_set = debputy_plugin_feature_set + ls.dctrl_parser = lsp_dctrl_parser + return ls diff --git a/tests/lsp_tests/lsp_tutil.py b/tests/lsp_tests/lsp_tutil.py index 2873f72..0843f79 100644 --- a/tests/lsp_tests/lsp_tutil.py +++ b/tests/lsp_tests/lsp_tutil.py @@ -1,4 +1,4 @@ -from typing import Tuple +from typing import Tuple, Union try: from pygls.server import LanguageServer @@ -6,6 +6,7 @@ try: TextDocumentItem, Position, ) + from debputy.lsp.debputy_ls import DebputyLanguageServer except ImportError: pass @@ -26,7 +27,7 @@ def _locate_cursor(text: str) -> Tuple[str, "Position"]: def put_doc_with_cursor( - ls: "LanguageServer", + ls: Union["LanguageServer", "DebputyLanguageServer"], uri: str, language_id: str, content: str, diff --git a/tests/lsp_tests/test_lsp_dctrl.py b/tests/lsp_tests/test_lsp_dctrl.py index d258e8f..122b929 100644 --- a/tests/lsp_tests/test_lsp_dctrl.py +++ b/tests/lsp_tests/test_lsp_dctrl.py @@ -70,3 +70,91 @@ def test_dctrl_hover_doc_field(ls: "LanguageServer") -> None: ) assert hover_doc is not None and isinstance(hover_doc.contents, MarkupContent) assert "Determines which architecture" in hover_doc.contents.value + + +def test_dctrl_hover_doc_synopsis(ls: "LanguageServer") -> None: + dctrl_uri = "file:///nowhere/debian/control" + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + """\ + Source: foo + + Package: foo + Architecture: any + Description: super charged<CURSOR> tool with batteries included +""" + ), + ) + + hover_doc = _debian_control_hover( + ls, + HoverParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert hover_doc is not None and isinstance(hover_doc.contents, MarkupContent) + assert hover_doc.contents.value.startswith("# Package synopsis") + assert "super charged tool with batteries included" in hover_doc.contents.value + + +def test_dctrl_hover_doc_substvars(ls: "LanguageServer") -> None: + dctrl_uri = "file:///nowhere/debian/control" + matching_cases = [ + "bar (= <CURSOR>${binary:Version})", + "bar (= $<CURSOR>{binary:Version})", + "bar (= ${binary:Version<CURSOR>})", + ] + for variant in matching_cases: + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + f"""\ + Source: foo + + Package: foo + Architecture: any + Depends: bar (= {variant}) + Description: super charged tool with batteries included + """ + ), + ) + + hover_doc = _debian_control_hover( + ls, + HoverParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert hover_doc is not None and isinstance(hover_doc.contents, MarkupContent) + assert hover_doc.contents.value.startswith("# Substvar `${binary:Version}`") + + non_matching_cases = [ + "bar (=<CURSOR> ${binary:Version})", + "bar (= ${binary:Version}<CURSOR>)", + ] + for variant in non_matching_cases: + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + f"""\ + Source: foo + + Package: foo + Architecture: any + Depends: bar (= {variant}) + Description: super charged tool with batteries included + """ + ), + ) + + hover_doc = _debian_control_hover( + ls, + HoverParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + provided_doc = "" + if hover_doc is not None and isinstance(hover_doc.contents, MarkupContent): + provided_doc = hover_doc.contents.value + assert not provided_doc.startswith("# Substvar `${binary:Version}`") diff --git a/tests/lsp_tests/test_lsp_debputy_manifest_completer.py b/tests/lsp_tests/test_lsp_debputy_manifest_completer.py index c72e791..196df2e 100644 --- a/tests/lsp_tests/test_lsp_debputy_manifest_completer.py +++ b/tests/lsp_tests/test_lsp_debputy_manifest_completer.py @@ -1,7 +1,5 @@ import textwrap -import pytest - from lsp_tests.lsp_tutil import put_doc_with_cursor try: @@ -19,13 +17,14 @@ try: MarkupContent, ) from debputy.lsp.lsp_debian_debputy_manifest import debputy_manifest_completer + from debputy.lsp.debputy_ls import DebputyLanguageServer HAS_PYGLS = True except ImportError: HAS_PYGLS = False -def test_basic_debputy_completer_empty(ls: "LanguageServer") -> None: +def test_basic_debputy_completer_empty(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -187,7 +186,9 @@ def test_basic_debputy_completer_empty(ls: "LanguageServer") -> None: assert "packages:" not in keywords -def test_basic_debputy_completer_manifest_variable_value(ls: "LanguageServer") -> None: +def test_basic_debputy_completer_manifest_variable_value( + ls: "DebputyLanguageServer", +) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -229,7 +230,7 @@ def test_basic_debputy_completer_manifest_variable_value(ls: "LanguageServer") - def test_basic_debputy_completer_install_rule_dispatch_key( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( @@ -280,7 +281,7 @@ def test_basic_debputy_completer_install_rule_dispatch_key( def test_basic_debputy_completer_install_rule_install_keys( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( @@ -339,7 +340,7 @@ def test_basic_debputy_completer_install_rule_install_keys( def test_basic_debputy_completer_packages_foo( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" @@ -368,7 +369,7 @@ def test_basic_debputy_completer_packages_foo( def test_basic_debputy_completer_packages_foo_xfail( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( @@ -396,7 +397,7 @@ def test_basic_debputy_completer_packages_foo_xfail( def test_basic_debputy_completer_services_service_scope_values( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" @@ -497,7 +498,7 @@ def test_basic_debputy_completer_services_service_scope_values( def test_basic_debputy_completer_manifest_conditions( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" |