diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 10:38:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 10:38:25 +0000 |
commit | d977ed2a119106100f64a873d99aed238ea6b059 (patch) | |
tree | ad205e51c67f28f4fc0e15af90af9f31ea15c182 /tests | |
parent | Adding upstream version 0.1.30. (diff) | |
download | debputy-d977ed2a119106100f64a873d99aed238ea6b059.tar.xz debputy-d977ed2a119106100f64a873d99aed238ea6b059.zip |
Adding upstream version 0.1.31.upstream/0.1.31
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lint_tests/lint_tutil.py | 2 | ||||
-rw-r--r-- | tests/lsp_tests/test_lsp_dctrl.py | 162 | ||||
-rw-r--r-- | tests/test_style.py | 122 |
3 files changed, 278 insertions, 8 deletions
diff --git a/tests/lint_tests/lint_tutil.py b/tests/lint_tests/lint_tutil.py index 8290712..08120ee 100644 --- a/tests/lint_tests/lint_tutil.py +++ b/tests/lint_tests/lint_tutil.py @@ -52,7 +52,7 @@ class LintWrapper: binary_packages = None dctrl_lines = self.dctrl_lines if dctrl_lines is not None: - source_package, binary_packages = ( + _, source_package, binary_packages = ( self._dctrl_parser.parse_source_debian_control( dctrl_lines, ignore_errors=True ) diff --git a/tests/lsp_tests/test_lsp_dctrl.py b/tests/lsp_tests/test_lsp_dctrl.py index 2bc90ba..e93ba17 100644 --- a/tests/lsp_tests/test_lsp_dctrl.py +++ b/tests/lsp_tests/test_lsp_dctrl.py @@ -1,4 +1,7 @@ import textwrap +from typing import Optional + +import pytest from debputy.lsp.debputy_ls import DebputyLanguageServer @@ -56,6 +59,165 @@ def test_dctrl_complete_field(ls: "DebputyLanguageServer") -> None: assert "Package" not in keywords assert "Source" not in keywords + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + """\ + Source: foo + + Package: foo + <CURSOR> + Architecture: any +""" + ), + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + assert "Multi-Arch" in keywords + # Should be considered present even though it is parsed as two stanzas with a space + assert "Architecture" not in keywords + # Already present or wrong section + assert "Package" not in keywords + assert "Source" not in keywords + + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + """\ + Source: foo + + Package: foo + Sec<CURSOR> + Architecture: any +""" + ), + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + # Included since we rely on client filtering (some clients let "RRR" match "R(ules-)R(equires-)R(oot), etc). + assert "Multi-Arch" in keywords + # Should be considered present even though it is parsed as two stanzas with an error + assert "Architecture" not in keywords + # Already present or wrong section + assert "Package" not in keywords + assert "Source" not in keywords + + +@pytest.mark.parametrize( + "case,is_arch_all", + [ + ("Architecture: any\n<CURSOR>", False), + ("Architecture: any\nM-A<CURSOR>", False), + ("<CURSOR>\nArchitecture: any", False), + ("M-A<CURSOR>\nArchitecture: any", False), + ("Architecture: all\n<CURSOR>", True), + ("Architecture: all\nM-A<CURSOR>", True), + ("<CURSOR>\nArchitecture: all", True), + ("M-A<CURSOR>\nArchitecture: all", True), + # Does not have architecture + ("M-A<CURSOR>", None), + ], +) +def test_dctrl_complete_field_context( + ls: "DebputyLanguageServer", + case: str, + is_arch_all: Optional[bool], +) -> None: + dctrl_uri = "file:///nowhere/debian/control" + + content = textwrap.dedent( + """\ + Source: foo + + Package: foo + {CASE} +""" + ).format(CASE=case) + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + content, + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + # Missing Architecture counts as "arch:all" by the completion logic + if is_arch_all is False: + assert "X-DH-Build-For-Type" in keywords + else: + assert "X-DH-Build-For-Type" not in keywords + + +def test_dctrl_complete_field_value_context(ls: "DebputyLanguageServer") -> None: + dctrl_uri = "file:///nowhere/debian/control" + + content = textwrap.dedent( + """\ + Source: foo + + Package: foo + Architecture: any + Multi-Arch: <CURSOR> +""" + ) + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + content, + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + assert keywords == {"no", "same", "foreign", "allowed"} + + content = textwrap.dedent( + """\ + Source: foo + + Package: foo + Architecture: all + Multi-Arch: <CURSOR> +""" + ) + cursor_pos = put_doc_with_cursor( + ls, + dctrl_uri, + "debian/control", + content, + ) + + matches = _debian_control_completions( + ls, + CompletionParams(TextDocumentIdentifier(dctrl_uri), cursor_pos), + ) + assert isinstance(matches, list) + keywords = {m.label for m in matches} + assert keywords == {"no", "foreign", "allowed"} + def test_dctrl_hover_doc_field(ls: "DebputyLanguageServer") -> None: dctrl_uri = "file:///nowhere/debian/control" diff --git a/tests/test_style.py b/tests/test_style.py index 9ce83bd..cae4510 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -1,7 +1,15 @@ +from typing import Mapping, Any, Optional + import pytest from debian.deb822 import Deb822 - -from debputy.lsp.style_prefs import StylePreferenceTable, determine_effective_style +from debputy.yaml.compat import CommentedMap + +from debputy.lsp.style_prefs import ( + StylePreferenceTable, + determine_effective_style, + EffectivePreference, + _WAS_DEFAULTS, +) from debputy.packages import SourcePackage @@ -63,7 +71,7 @@ def test_compat_styles() -> None: ) src = SourcePackage(fields) - effective_style = determine_effective_style(styles, src) + effective_style = determine_effective_style(styles, src, None) assert effective_style == nt_pref fields["Uploaders"] = ( @@ -71,7 +79,7 @@ def test_compat_styles() -> None: ) src = SourcePackage(fields) - effective_style = determine_effective_style(styles, src) + effective_style = determine_effective_style(styles, src, None) assert effective_style == nt_pref assert effective_style == zeha_pref @@ -80,7 +88,7 @@ def test_compat_styles() -> None: ) src = SourcePackage(fields) - effective_style = determine_effective_style(styles, src) + effective_style = determine_effective_style(styles, src, None) assert effective_style is None @@ -100,7 +108,7 @@ def test_compat_styles_team_maint() -> None: assert "random@example.org" not in styles.maintainer_preferences team_style = styles.maintainer_preferences["team@lists.debian.org"] assert team_style.is_packaging_team - effective_style = determine_effective_style(styles, src) + effective_style = determine_effective_style(styles, src, None) assert effective_style == team_style.as_effective_pref() @@ -117,5 +125,105 @@ def test_x_style() -> None: assert "random@example.org" not in styles.maintainer_preferences assert "black" in styles.named_styles black_style = styles.named_styles["black"] - effective_style = determine_effective_style(styles, src) + effective_style = determine_effective_style(styles, src, None) assert effective_style == black_style + + +def test_was_from_salsa_ci_style() -> None: + styles = StylePreferenceTable.load_styles() + fields = Deb822( + { + "Package": "foo", + "Maintainer": "Random Developer <random@example.org>", + }, + ) + src = SourcePackage(fields) + assert "random@example.org" not in styles.maintainer_preferences + effective_style = determine_effective_style(styles, src, None) + assert effective_style is None + salsa_ci = CommentedMap( + {"variables": CommentedMap({"SALSA_CI_DISABLE_WRAP_AND_SORT": "yes"})} + ) + effective_style = determine_effective_style(styles, src, salsa_ci) + assert effective_style is None + + salsa_ci = CommentedMap( + {"variables": CommentedMap({"SALSA_CI_DISABLE_WRAP_AND_SORT": "no"})} + ) + effective_style = determine_effective_style(styles, src, salsa_ci) + was_style = EffectivePreference(**_WAS_DEFAULTS) + assert effective_style == was_style + + +@pytest.mark.parametrize( + "was_args,style_delta", + [ + ( + "-a", + { + "formatting_deb822_always_wrap": True, + }, + ), + ( + "-sa", + { + "formatting_deb822_always_wrap": True, + "formatting_deb822_short_indent": True, + }, + ), + ( + "-sa --keep-first", + { + "formatting_deb822_always_wrap": True, + "formatting_deb822_short_indent": True, + }, + ), + ( + "-sab --keep-first", + { + "formatting_deb822_always_wrap": True, + "formatting_deb822_short_indent": True, + "formatting_deb822_normalize_stanza_order": True, + }, + ), + ( + "-sab --no-keep-first", + { + "formatting_deb822_always_wrap": True, + "formatting_deb822_short_indent": True, + "formatting_deb822_normalize_stanza_order": False, + }, + ), + ], +) +def test_was_from_salsa_ci_style_args( + was_args: str, style_delta: Optional[Mapping[str, Any]] +) -> None: + styles = StylePreferenceTable.load_styles() + fields = Deb822( + { + "Package": "foo", + "Maintainer": "Random Developer <random@example.org>", + }, + ) + src = SourcePackage(fields) + assert "random@example.org" not in styles.maintainer_preferences + salsa_ci = CommentedMap( + { + "variables": CommentedMap( + { + "SALSA_CI_DISABLE_WRAP_AND_SORT": "no", + "SALSA_CI_WRAP_AND_SORT_ARGS": was_args, + } + ) + } + ) + effective_style = determine_effective_style(styles, src, salsa_ci) + if style_delta is None: + assert effective_style is None + else: + was_style = EffectivePreference(**_WAS_DEFAULTS).replace( + **style_delta, + ) + + assert effective_style == was_style |