diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lint_tests/test_lint_changelog.py | 39 | ||||
-rw-r--r-- | tests/lint_tests/test_lint_dctrl.py | 160 | ||||
-rw-r--r-- | tests/lint_tests/test_lint_dtctrl.py | 74 | ||||
-rw-r--r-- | tests/test_style.py | 4 |
4 files changed, 273 insertions, 4 deletions
diff --git a/tests/lint_tests/test_lint_changelog.py b/tests/lint_tests/test_lint_changelog.py index 258c2fe..b5ab69e 100644 --- a/tests/lint_tests/test_lint_changelog.py +++ b/tests/lint_tests/test_lint_changelog.py @@ -31,13 +31,13 @@ def test_dctrl_lint(line_linter: LintWrapper) -> None: """\ foo (0.2) unstable; urgency=medium - * Renamed to foo + * Renamed to foo -- Niels Thykier <niels@thykier.net> Mon, 08 Apr 2024 16:00:00 +0000 bar (0.2) unstable; urgency=medium - * Initial release + * Initial release -- Niels Thykier <niels@thykier.net> Mon, 01 Apr 2024 00:00:00 +0000 """ @@ -82,3 +82,38 @@ def test_dctrl_lint(line_linter: LintWrapper) -> None: assert diag.severity == DiagnosticSeverity.Error assert diag.message == msg assert f"{diag.range}" == "0:0-0:3" + + +def test_dctrl_lint_historical(line_linter: LintWrapper) -> None: + nonsense = "very very very very very very very very very very very very very very " + lines = textwrap.dedent( + f"""\ + foo (0.4) unstable; urgency=medium + + * A {nonsense} long line about absolute nothing that should trigger a warning about length. + + -- Niels Thykier <niels@thykier.net> Mon, 08 Apr 2024 16:00:00 +0000 + + foo (0.3) unstable; urgency=medium + + * Another entry that is not too long. + + -- Niels Thykier <niels@thykier.net> Thu, 04 Apr 2024 00:00:00 +0000 + + foo (0.2) unstable; urgency=medium + + * A {nonsense} long line about absolute nothing that should not trigger a warning about length. + + -- Niels Thykier <niels@thykier.net> Mon, 01 Apr 2024 00:00:00 +0000 + """ + ).splitlines(keepends=True) + diagnostics = line_linter(lines) + print(diagnostics) + # This should be problematic though + assert diagnostics and len(diagnostics) == 1 + diag = diagnostics[0] + + msg = "Line exceeds 82 characters" + assert diag.severity == DiagnosticSeverity.Hint + assert diag.message == msg + assert f"{diag.range}" == "2:82-2:153" diff --git a/tests/lint_tests/test_lint_dctrl.py b/tests/lint_tests/test_lint_dctrl.py index 7e9477e..c91d43d 100644 --- a/tests/lint_tests/test_lint_dctrl.py +++ b/tests/lint_tests/test_lint_dctrl.py @@ -470,6 +470,33 @@ def test_dctrl_lint_sv(line_linter: LintWrapper) -> None: assert issue.severity == DiagnosticSeverity.Information +def test_dctrl_lint_sv_udeb_only(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo-udeb + Architecture: all + Package-Type: udeb + Section: debian-installer + Depends: bar, baz + 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 not diagnostics + + def test_dctrl_lint_multiple_vcs(line_linter: LintWrapper) -> None: lines = textwrap.dedent( f"""\ @@ -508,3 +535,136 @@ def test_dctrl_lint_multiple_vcs(line_linter: LintWrapper) -> None: assert second_issue.message == msg assert f"{second_issue.range}" == "7:0-8:0" assert second_issue.severity == DiagnosticSeverity.Warning + + +def test_dctrl_lint_synopsis_empty(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION} + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + Description: + A very interesting description + without a synopsis + . + Just so be clear, this is for a test. + """ + ).splitlines(keepends=True) + + diagnostics = line_linter(lines) + print(diagnostics) + assert diagnostics and len(diagnostics) == 1 + issue = diagnostics[0] + + msg = "Package synopsis is missing" + assert issue.message == msg + assert f"{issue.range}" == "10:0-10:11" + assert issue.severity == DiagnosticSeverity.Warning + + +def test_dctrl_lint_synopsis_basis(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION} + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + Description: The synopsis is not the best because it starts with an article and also the synopsis goes on and on + A very interesting description + with a poor synopsis + . + Just so be clear, this is for a test. + """ + ).splitlines(keepends=True) + + diagnostics = line_linter(lines) + print(diagnostics) + assert diagnostics and len(diagnostics) == 2 + first_issue, second_issue = diagnostics + + msg = "Package synopsis starts with an article (a/an/the)." + assert first_issue.message == msg + assert f"{first_issue.range}" == "10:13-10:16" + assert first_issue.severity == DiagnosticSeverity.Warning + + msg = "Package synopsis is too long." + assert second_issue.message == msg + assert f"{second_issue.range}" == "10:92-10:112" + assert second_issue.severity == DiagnosticSeverity.Warning + + +def test_dctrl_lint_synopsis_template(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION} + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + Description: <insert up to 60 chars description> + A very interesting description + with a poor synopsis + . + Just so be clear, this is for a test. + """ + ).splitlines(keepends=True) + + diagnostics = line_linter(lines) + print(diagnostics) + assert diagnostics and len(diagnostics) == 1 + issue = diagnostics[0] + + msg = "Package synopsis is a placeholder" + assert issue.message == msg + assert f"{issue.range}" == "10:13-10:48" + assert issue.severity == DiagnosticSeverity.Warning + + +def test_dctrl_lint_synopsis_too_short(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + f"""\ + Source: foo + Section: devel + Priority: optional + Standards-Version: {CURRENT_STANDARDS_VERSION} + Maintainer: Jane Developer <jane@example.com> + Build-Depends: debhelper-compat (= 13) + + Package: foo + Architecture: all + Depends: bar, baz + Description: short + A very interesting description + with a poor synopsis + . + Just so be clear, this is for a test. + """ + ).splitlines(keepends=True) + + diagnostics = line_linter(lines) + print(diagnostics) + assert diagnostics and len(diagnostics) == 1 + issue = diagnostics[0] + + msg = "Package synopsis is too short" + assert issue.message == msg + assert f"{issue.range}" == "10:13-10:18" + assert issue.severity == DiagnosticSeverity.Warning diff --git a/tests/lint_tests/test_lint_dtctrl.py b/tests/lint_tests/test_lint_dtctrl.py new file mode 100644 index 0000000..6127dd9 --- /dev/null +++ b/tests/lint_tests/test_lint_dtctrl.py @@ -0,0 +1,74 @@ +import textwrap + +import pytest + +from debputy.lsp.lsp_debian_control_reference_data import CURRENT_STANDARDS_VERSION +from debputy.lsp.lsp_debian_tests_control import _lint_debian_tests_control +from debputy.packages import DctrlParser +from debputy.plugin.api.feature_set import PluginProvidedFeatureSet +from lint_tests.lint_tutil import ( + group_diagnostics_by_severity, + requires_levenshtein, + LintWrapper, +) + +try: + from lsprotocol.types import Diagnostic, DiagnosticSeverity +except ImportError: + pass + + +@pytest.fixture +def line_linter( + debputy_plugin_feature_set: PluginProvidedFeatureSet, + lint_dctrl_parser: DctrlParser, +) -> LintWrapper: + return LintWrapper( + "/nowhere/debian/tests/control", + _lint_debian_tests_control, + debputy_plugin_feature_set, + lint_dctrl_parser, + ) + + +@requires_levenshtein +def test_dtctrl_lint_live_example_silx(line_linter: LintWrapper) -> None: + lines = textwrap.dedent( + """\ + Tests: no-opencl + Depends: + @, + python3-all, + python3-pytest, + python3-pytest-mock, + python3-pytest-xvfb, + xauth, + xvfb, + Restrictions: allow-stderr + + Tests: opencl + Depends: + @, + clinfo, + python3-all, + python3-pytest, + python3-pytest-mock, + python3-pytest-xvfb, + xauth, + xvfb, + Architecture: !i386 + Restrictions: allow-stderr + + Test-Command: xvfb-run -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" sh debian/tests/gui + Depends: + mesa-utils, + silx, + xauth, + xvfb, + Restrictions: allow-stderr + """ + ).splitlines(keepends=True) + + diagnostics = line_linter(lines) + print(diagnostics) + assert not diagnostics diff --git a/tests/test_style.py b/tests/test_style.py index 0e3f5d7..ef6ddc4 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -25,7 +25,7 @@ def test_load_styles() -> None: 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 + assert not nt_style.formatting_deb822_normalize_stanza_order # TODO: Not implemented yet assert not nt_style.formatting_deb822_normalize_field_order @@ -41,7 +41,7 @@ def test_load_named_styles() -> None: 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 + assert not black_style.formatting_deb822_normalize_stanza_order # TODO: Not implemented yet assert not black_style.formatting_deb822_normalize_field_order |