summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:05:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:05:28 +0000
commita4b65820a6d367018519b5acf4b450a103201ea3 (patch)
treee566fc8f1dc451faf91533d546b1c1622d67044a /tests
parentAdding upstream version 0.1.29. (diff)
downloaddebputy-a4b65820a6d367018519b5acf4b450a103201ea3.tar.xz
debputy-a4b65820a6d367018519b5acf4b450a103201ea3.zip
Adding upstream version 0.1.30.upstream/0.1.30
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/lint_tests/conftest.py1
-rw-r--r--tests/lint_tests/lint_tutil.py6
-rw-r--r--tests/lint_tests/test_lint_dctrl.py58
-rw-r--r--tests/lsp_tests/test_debpkg_metadata.py2
-rw-r--r--tests/test_style.py121
5 files changed, 176 insertions, 12 deletions
diff --git a/tests/lint_tests/conftest.py b/tests/lint_tests/conftest.py
index 2c54eb7..bf4b3b0 100644
--- a/tests/lint_tests/conftest.py
+++ b/tests/lint_tests/conftest.py
@@ -3,6 +3,7 @@ from debian.debian_support import DpkgArchTable
from debputy._deb_options_profiles import DebBuildOptionsAndProfiles
from debputy.architecture_support import DpkgArchitectureBuildProcessValuesTable
+from debputy.lsp.style_prefs import StylePreferenceTable
from debputy.packages import DctrlParser
from debputy.util import setup_logging
diff --git a/tests/lint_tests/lint_tutil.py b/tests/lint_tests/lint_tutil.py
index 83b69fd..8290712 100644
--- a/tests/lint_tests/lint_tutil.py
+++ b/tests/lint_tests/lint_tutil.py
@@ -9,6 +9,7 @@ from debputy.linting.lint_util import (
LintStateImpl,
LintState,
)
+from debputy.lsp.style_prefs import StylePreferenceTable, EffectivePreference
from debputy.packages import DctrlParser
from debputy.plugin.api.feature_set import PluginProvidedFeatureSet
@@ -43,6 +44,8 @@ class LintWrapper:
self.dctrl_lines: Optional[List[str]] = None
self.path = path
self._dctrl_parser = dctrl_parser
+ self.lint_style_preference_table = StylePreferenceTable({}, {})
+ self.effective_preference: Optional[EffectivePreference] = None
def __call__(self, lines: List[str]) -> Optional[List["Diagnostic"]]:
source_package = None
@@ -56,10 +59,13 @@ class LintWrapper:
)
state = LintStateImpl(
self._debputy_plugin_feature_set,
+ self.lint_style_preference_table,
self.path,
+ "".join(dctrl_lines) if dctrl_lines is not None else "",
lines,
source_package,
binary_packages,
+ self.effective_preference,
)
return check_diagnostics(self._handler(state))
diff --git a/tests/lint_tests/test_lint_dctrl.py b/tests/lint_tests/test_lint_dctrl.py
index ce34d7c..bcb1613 100644
--- a/tests/lint_tests/test_lint_dctrl.py
+++ b/tests/lint_tests/test_lint_dctrl.py
@@ -18,6 +18,9 @@ except ImportError:
pass
+STANDARDS_VERSION = "4.7.0"
+
+
class DctrlLintWrapper(LintWrapper):
def __call__(self, lines: List[str]) -> Optional[List["Diagnostic"]]:
@@ -93,15 +96,15 @@ def test_dctrl_lint(line_linter: LintWrapper) -> None:
msg = 'The value "base" is not supported in Section.'
assert second_warn.message == msg
- assert f"{second_warn.range}" == "8:9-8:13"
+ assert f"{second_warn.range}" == "7:9-7:13"
@requires_levenshtein
def test_dctrl_lint_typos(line_linter: LintWrapper) -> None:
lines = textwrap.dedent(
- """\
+ f"""\
Source: foo
- Standards-Version: 4.5.2
+ Standards-Version: {STANDARDS_VERSION}
Priority: optional
Section: devel
Maintainer: Jane Developer <jane@example.com>
@@ -132,9 +135,9 @@ def test_dctrl_lint_typos(line_linter: LintWrapper) -> None:
@requires_levenshtein
def test_dctrl_lint_mx_value_with_typo(line_linter: LintWrapper) -> None:
lines = textwrap.dedent(
- """\
+ f"""\
Source: foo
- Standards-Version: 4.5.2
+ Standards-Version: {STANDARDS_VERSION}
Priority: optional
Section: devel
Maintainer: Jane Developer <jane@example.com>
@@ -165,15 +168,15 @@ def test_dctrl_lint_mx_value_with_typo(line_linter: LintWrapper) -> None:
typo_msg = 'It is possible that the value is a typo of "all".'
assert mx_diag.message == mx_msg
assert typo_diag.message == typo_msg
- assert f"{mx_diag.range}" == "10:24-10:28"
- assert f"{typo_diag.range}" == "10:24-10:28"
+ assert f"{mx_diag.range}" == "9:24-9:28"
+ assert f"{typo_diag.range}" == "9:24-9:28"
def test_dctrl_lint_mx_value(line_linter: LintWrapper) -> None:
lines = textwrap.dedent(
- """\
+ f"""\
Source: foo
- Standards-Version: 4.5.2
+ Standards-Version: {STANDARDS_VERSION}
Priority: optional
Section: devel
Maintainer: Jane Developer <jane@example.com>
@@ -200,9 +203,9 @@ def test_dctrl_lint_mx_value(line_linter: LintWrapper) -> None:
assert f"{diag.range}" == "8:14-8:17"
lines = textwrap.dedent(
- """\
+ f"""\
Source: foo
- Standards-Version: 4.5.2
+ Standards-Version: {STANDARDS_VERSION}
Priority: optional
Section: devel
Maintainer: Jane Developer <jane@example.com>
@@ -227,3 +230,36 @@ def test_dctrl_lint_mx_value(line_linter: LintWrapper) -> None:
assert diag.message == msg
assert diag.severity == DiagnosticSeverity.Error
assert f"{diag.range}" == "8:24-8:27"
+
+
+def test_dctrl_lint_dup_sep(line_linter: LintWrapper) -> None:
+ lines = textwrap.dedent(
+ f"""\
+ Source: foo
+ Section: devel
+ Priority: optional
+ Standards-Version: {STANDARDS_VERSION}
+ Maintainer: Jane Developer <jane@example.com>
+ Build-Depends: debhelper-compat (= 13)
+
+ Package: foo
+ Architecture: all
+ Depends: foo,
+ , bar
+ Description: Some very interesting synopsis
+ A very interesting description
+ that spans multiple lines
+ .
+ Just so be clear, this is for a test.
+ """
+ ).splitlines(keepends=True)
+
+ diagnostics = line_linter(lines)
+ print(diagnostics)
+ assert diagnostics and len(diagnostics) == 1
+ error = diagnostics[0]
+
+ msg = "Duplicate separator"
+ assert error.message == msg
+ assert f"{error.range}" == "10:1-10:2"
+ assert error.severity == DiagnosticSeverity.Error
diff --git a/tests/lsp_tests/test_debpkg_metadata.py b/tests/lsp_tests/test_debpkg_metadata.py
index f784b0a..fdb0df8 100644
--- a/tests/lsp_tests/test_debpkg_metadata.py
+++ b/tests/lsp_tests/test_debpkg_metadata.py
@@ -19,7 +19,7 @@ from debputy.lsp.lsp_debian_control_reference_data import package_name_to_sectio
("xxx-l10n-bar", "localization"),
("libfoo4", "libs"),
("unknown", None),
- ]
+ ],
)
def test_package_name_to_section(name: str, guessed_section: Optional[str]) -> None:
assert package_name_to_section(name) == guessed_section
diff --git a/tests/test_style.py b/tests/test_style.py
new file mode 100644
index 0000000..9ce83bd
--- /dev/null
+++ b/tests/test_style.py
@@ -0,0 +1,121 @@
+import pytest
+from debian.deb822 import Deb822
+
+from debputy.lsp.style_prefs import StylePreferenceTable, determine_effective_style
+from debputy.packages import SourcePackage
+
+
+def test_load_styles() -> None:
+ styles = StylePreferenceTable.load_styles()
+ assert "niels@thykier.net" in styles.maintainer_preferences
+ nt_style = styles.maintainer_preferences["niels@thykier.net"]
+ # Note this is data dependent; if it fails because the style changes, update the test
+ assert nt_style.canonical_name == "Niels Thykier"
+ assert not nt_style.is_packaging_team
+ assert nt_style.formatting_deb822_normalize_field_content
+ assert nt_style.formatting_deb822_short_indent
+ assert nt_style.formatting_deb822_always_wrap
+ assert nt_style.formatting_deb822_trailing_separator
+ assert nt_style.formatting_deb822_max_line_length == 79
+ assert nt_style.formatting_deb822_normalize_stanza_order
+
+ # TODO: Not implemented yet
+ assert not nt_style.formatting_deb822_normalize_field_order
+
+
+def test_load_named_styles() -> None:
+ styles = StylePreferenceTable.load_styles()
+ assert "black" in styles.named_styles
+ black_style = styles.named_styles["black"]
+ # Note this is data dependent; if it fails because the style changes, update the test
+ assert black_style.formatting_deb822_normalize_field_content
+ assert black_style.formatting_deb822_short_indent
+ assert black_style.formatting_deb822_always_wrap
+ assert black_style.formatting_deb822_trailing_separator
+ assert black_style.formatting_deb822_max_line_length == 79
+ assert black_style.formatting_deb822_normalize_stanza_order
+
+ # TODO: Not implemented yet
+ assert not black_style.formatting_deb822_normalize_field_order
+
+
+def test_compat_styles() -> None:
+ styles = StylePreferenceTable.load_styles()
+
+ # Data dependent; if it breaks, provide a stubbed style preference table
+ assert "niels@thykier.net" in styles.maintainer_preferences
+ assert "zeha@debian.org" in styles.maintainer_preferences
+ assert "random-package@packages.debian.org" not in styles.maintainer_preferences
+ assert "random@example.org" not in styles.maintainer_preferences
+
+ nt_pref = styles.maintainer_preferences["niels@thykier.net"].as_effective_pref()
+ zeha_pref = styles.maintainer_preferences["zeha@debian.org"].as_effective_pref()
+
+ # Data dependency
+ assert nt_pref == zeha_pref
+
+ fields = Deb822(
+ {
+ "Package": "foo",
+ "Maintainer": "Foo <random-package@packages.debian.org>",
+ "Uploaders": "Niels Thykier <niels@thykier.net>",
+ },
+ )
+ src = SourcePackage(fields)
+
+ effective_style = determine_effective_style(styles, src)
+ assert effective_style == nt_pref
+
+ fields["Uploaders"] = (
+ "Niels Thykier <niels@thykier.net>, Chris Hofstaedtler <zeha@debian.org>"
+ )
+ src = SourcePackage(fields)
+
+ effective_style = determine_effective_style(styles, src)
+ assert effective_style == nt_pref
+ assert effective_style == zeha_pref
+
+ fields["Uploaders"] = (
+ "Niels Thykier <niels@thykier.net>, Chris Hofstaedtler <zeha@debian.org>, Random Developer <random@example.org>"
+ )
+ src = SourcePackage(fields)
+
+ effective_style = determine_effective_style(styles, src)
+ assert effective_style is None
+
+
+@pytest.mark.xfail
+def test_compat_styles_team_maint() -> None:
+ styles = StylePreferenceTable.load_styles()
+ fields = Deb822(
+ {
+ "Package": "foo",
+ # Missing a stubbed definition for `team@lists.debian.org`
+ "Maintainer": "Packaging Team <team@lists.debian.org>",
+ "Uploaders": "Random Developer <random@example.org>",
+ },
+ )
+ src = SourcePackage(fields)
+ assert "team@lists.debian.org" in styles.maintainer_preferences
+ 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)
+ assert effective_style == team_style.as_effective_pref()
+
+
+def test_x_style() -> None:
+ styles = StylePreferenceTable.load_styles()
+ fields = Deb822(
+ {
+ "Package": "foo",
+ "X-Style": "black",
+ "Maintainer": "Random Developer <random@example.org>",
+ },
+ )
+ src = SourcePackage(fields)
+ 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)
+ assert effective_style == black_style