diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-25 02:59:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-25 02:59:47 +0000 |
commit | 03a1bd448be99d872d663a57a1cf4492882e090d (patch) | |
tree | c3d23691aa4dfdba89856bde05707a9a8e16abab /tests | |
parent | Adding upstream version 0.1.28. (diff) | |
download | debputy-03a1bd448be99d872d663a57a1cf4492882e090d.tar.xz debputy-03a1bd448be99d872d663a57a1cf4492882e090d.zip |
Adding upstream version 0.1.29.upstream/0.1.29
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lint_tests/test_lint_changelog.py | 12 | ||||
-rw-r--r-- | tests/lint_tests/test_lint_dctrl.py | 1 | ||||
-rw-r--r-- | tests/lint_tests/test_lint_debputy.py | 187 | ||||
-rw-r--r-- | tests/lsp_tests/lsp_tutil.py | 92 | ||||
-rw-r--r-- | tests/lsp_tests/test_debpkg_metadata.py | 25 | ||||
-rw-r--r-- | tests/lsp_tests/test_lsp_dctrl.py | 70 | ||||
-rw-r--r-- | tests/lsp_tests/test_lsp_debputy_manifest_hover.py | 21 | ||||
-rw-r--r-- | tests/plugin_tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/plugin_tests/conftest.py | 3 | ||||
-rw-r--r-- | tests/plugin_tests/numpy3_test.py | 3 | ||||
-rw-r--r-- | tests/plugin_tests/perl-openssl_test.py | 3 | ||||
-rw-r--r-- | tests/test_alternatives.py | 2 | ||||
-rw-r--r-- | tests/test_deb_packaging_support.py | 4 | ||||
-rw-r--r-- | tests/test_debputy_plugin.py | 20 | ||||
-rw-r--r-- | tests/test_declarative_parser.py | 11 | ||||
-rw-r--r-- | tests/test_fs_metadata.py | 12 | ||||
-rw-r--r-- | tests/test_interpreter.py | 6 | ||||
-rw-r--r-- | tests/test_migrations.py | 6 | ||||
-rw-r--r-- | tests/test_packager_provided_files.py | 12 | ||||
-rw-r--r-- | tests/test_plugin_tester.py | 9 |
20 files changed, 259 insertions, 240 deletions
diff --git a/tests/lint_tests/test_lint_changelog.py b/tests/lint_tests/test_lint_changelog.py index 25dac0e..258c2fe 100644 --- a/tests/lint_tests/test_lint_changelog.py +++ b/tests/lint_tests/test_lint_changelog.py @@ -1,17 +1,11 @@ import textwrap -from typing import List, Optional import pytest from debputy.lsp.lsp_debian_changelog import _lint_debian_changelog -from debputy.lsp.lsp_debian_control import _lint_debian_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, -) +from lint_tests.lint_tutil import LintWrapper try: from lsprotocol.types import Diagnostic, DiagnosticSeverity @@ -60,7 +54,7 @@ def test_dctrl_lint(line_linter: LintWrapper) -> None: Package: something-else """ - ) + ).splitlines(keepends=True) diagnostics = line_linter(lines) print(diagnostics) @@ -73,7 +67,7 @@ def test_dctrl_lint(line_linter: LintWrapper) -> None: Package: something-else """ - ) + ).splitlines(keepends=True) diagnostics = line_linter(lines) print(diagnostics) diff --git a/tests/lint_tests/test_lint_dctrl.py b/tests/lint_tests/test_lint_dctrl.py index e9a5756..ce34d7c 100644 --- a/tests/lint_tests/test_lint_dctrl.py +++ b/tests/lint_tests/test_lint_dctrl.py @@ -153,6 +153,7 @@ def test_dctrl_lint_mx_value_with_typo(line_linter: LintWrapper) -> None: diagnostics = line_linter(lines) print(diagnostics) + assert diagnostics is not None assert len(diagnostics) == 2 by_severity = group_diagnostics_by_severity(diagnostics) assert DiagnosticSeverity.Error in by_severity diff --git a/tests/lint_tests/test_lint_debputy.py b/tests/lint_tests/test_lint_debputy.py index 9c30392..8e405f8 100644 --- a/tests/lint_tests/test_lint_debputy.py +++ b/tests/lint_tests/test_lint_debputy.py @@ -1,187 +1,4 @@ -from typing import List, Optional, Callable - -import pytest - -from debputy.packages import DctrlParser -from debputy.plugin.api.feature_set import PluginProvidedFeatureSet -from lint_tests.lint_tutil import ( - 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/debputy.manifest", - _lint_debian_debputy_manifest, - debputy_plugin_feature_set, - lint_dctrl_parser, - ) - - -def test_debputy_lint_unknown_keys(line_linter: LintWrapper) -> None: - lines = textwrap.dedent( - """\ - manifest-version: 0.1 - installations: - - install-something: - sources: - - abc - - def - - install-docs: - source: foo - puff: true # Unknown keyword (assuming install-docs) - when: - negated: cross-compiling - - install-docs: - source: bar - when: ross-compiling # Typo of "cross-compiling"; FIXME not caught - packages: - foo: - blah: qwe # Unknown keyword - """ - ).splitlines(keepends=True) - - diagnostics = line_linter(lines) - by_severity = group_diagnostics_by_severity(diagnostics) - # This example triggers errors only - assert DiagnosticSeverity.Error in by_severity - - assert DiagnosticSeverity.Warning not in by_severity - assert DiagnosticSeverity.Hint not in by_severity - assert DiagnosticSeverity.Information not in by_severity - - errors = by_severity[DiagnosticSeverity.Error] - print(errors) - assert len(errors) == 4 - - first_error, second_error, third_error, fourth_error = errors - - msg = 'Unknown or unsupported key "install-something".' - assert first_error.message == msg - assert f"{first_error.range}" == "2:2-2:19" - - msg = 'Unknown or unsupported key "puff".' - assert second_error.message == msg - assert f"{second_error.range}" == "8:4-8:8" - - msg = 'Unknown or unsupported key "negated".' - assert third_error.message == msg - assert f"{third_error.range}" == "10:6-10:13" - - msg = 'Unknown or unsupported key "blah".' - assert fourth_error.message == msg - assert f"{fourth_error.range}" == "16:4-16:8" - - -@requires_levenshtein -def test_debputy_lint_unknown_keys_spelling(line_linter: LintWrapper) -> None: - lines = textwrap.dedent( - """\ - manifest-version: 0.1 - installations: - - install-dcoss: # typo - sources: - - abc - - def - puff: true # Unknown keyword (assuming install-docs) - when: - nut: cross-compiling # Typo of "not" - - install-docs: - source: bar - when: ross-compiling # Typo of "cross-compiling"; FIXME not caught - """ - ).splitlines(keepends=True) - - diagnostics = line_linter(lines) - by_severity = group_diagnostics_by_severity(diagnostics) - # This example triggers errors only - assert DiagnosticSeverity.Error in by_severity - - assert DiagnosticSeverity.Warning not in by_severity - assert DiagnosticSeverity.Hint not in by_severity - assert DiagnosticSeverity.Information not in by_severity - - errors = by_severity[DiagnosticSeverity.Error] - print(errors) - assert len(errors) == 3 - - first_error, second_error, third_error = errors - - msg = 'Unknown or unsupported key "install-dcoss". It looks like a typo of "install-docs".' - assert first_error.message == msg - assert f"{first_error.range}" == "2:2-2:15" - - msg = 'Unknown or unsupported key "puff".' - assert second_error.message == msg - assert f"{second_error.range}" == "6:4-6:8" - - msg = 'Unknown or unsupported key "nut". It looks like a typo of "not".' - assert third_error.message == msg - assert f"{third_error.range}" == "8:6-8:9" - - -def test_debputy_lint_conflicting_keys(line_linter: LintWrapper) -> None: - lines = textwrap.dedent( - """\ - manifest-version: 0.1 - installations: - - install-docs: - sources: - - foo - - bar - as: baz # Conflicts with "sources" (#85) - - install: - source: foo - sources: # Conflicts with "source" (#85) - - bar - - baz - """ - ).splitlines(keepends=True) - - diagnostics = line_linter(lines) - by_severity = group_diagnostics_by_severity(diagnostics) - # This example triggers errors only - assert DiagnosticSeverity.Error in by_severity - - assert DiagnosticSeverity.Warning not in by_severity - assert DiagnosticSeverity.Hint not in by_severity - assert DiagnosticSeverity.Information not in by_severity - - errors = by_severity[DiagnosticSeverity.Error] - print(errors) - assert len(errors) == 4 - - first_error, second_error, third_error, fourth_error = errors - - msg = 'The "sources" cannot be used with "as".' - assert first_error.message == msg - assert f"{first_error.range}" == "3:4-3:11" - - msg = 'The "as" cannot be used with "sources".' - assert second_error.message == msg - assert f"{second_error.range}" == "6:4-6:6" - - msg = 'The "source" cannot be used with "sources".' - assert third_error.message == msg - assert f"{third_error.range}" == "8:4-8:10" - - msg = 'The "sources" cannot be used with "source".' - assert fourth_error.message == msg - assert f"{fourth_error.range}" == "9:4-9:11" - - import textwrap -from typing import List, Optional, Callable import pytest @@ -189,9 +6,9 @@ from debputy.lsp.lsp_debian_debputy_manifest import _lint_debian_debputy_manifes 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, + group_diagnostics_by_severity, ) try: @@ -199,8 +16,6 @@ try: except ImportError: pass -TestLintWrapper = Callable[[List[str]], Optional[List["Diagnostic"]]] - @pytest.fixture def line_linter( diff --git a/tests/lsp_tests/lsp_tutil.py b/tests/lsp_tests/lsp_tutil.py index 0843f79..bc0fa91 100644 --- a/tests/lsp_tests/lsp_tutil.py +++ b/tests/lsp_tests/lsp_tutil.py @@ -1,16 +1,52 @@ -from typing import Tuple, Union +import dataclasses +from typing import Tuple, Union, FrozenSet, Optional, List + +from debputy.lsp.lsp_features import SEMANTIC_TOKENS_LEGEND +from debputy.util import grouper try: - from pygls.server import LanguageServer from lsprotocol.types import ( TextDocumentItem, Position, + Range, + SemanticTokens, ) from debputy.lsp.debputy_ls import DebputyLanguageServer except ImportError: pass +@dataclasses.dataclass(slots=True, frozen=True) +class ResolvedSemanticToken: + range: "Range" + token_name: str + modifiers: FrozenSet[str] = frozenset() + + +def resolved_semantic_token( + line_no: int, + col_start: int, + token_len: int, + token_type: str, + *, + token_modifiers: FrozenSet[str] = frozenset(), +) -> ResolvedSemanticToken: + return ResolvedSemanticToken( + Range( + Position( + line_no, + col_start, + ), + Position( + line_no, + col_start + token_len, + ), + ), + token_type, + token_modifiers, + ) + + def _locate_cursor(text: str) -> Tuple[str, "Position"]: lines = text.splitlines(keepends=True) for line_no in range(len(lines)): @@ -27,12 +63,27 @@ def _locate_cursor(text: str) -> Tuple[str, "Position"]: def put_doc_with_cursor( - ls: Union["LanguageServer", "DebputyLanguageServer"], + ls: "DebputyLanguageServer", uri: str, language_id: str, content: str, ) -> "Position": cleaned_content, cursor_pos = _locate_cursor(content) + put_doc_no_cursor( + ls, + uri, + language_id, + cleaned_content, + ) + return cursor_pos + + +def put_doc_no_cursor( + ls: "DebputyLanguageServer", + uri: str, + language_id: str, + content: str, +) -> None: doc_version = 1 existing = ls.workspace.text_documents.get(uri) if existing is not None: @@ -42,7 +93,38 @@ def put_doc_with_cursor( uri, language_id, doc_version, - cleaned_content, + content, ) ) - return cursor_pos + + +def resolve_semantic_tokens( + token_result: Optional["SemanticTokens"], +) -> Optional[List[ResolvedSemanticToken]]: + if token_result is None: + return None + assert (len(token_result.data) % 5) == 0 + current_line = 0 + current_col = 0 + resolved_tokens = [] + token_types = SEMANTIC_TOKENS_LEGEND.token_types + for token_data in grouper(token_result.data, 5, incomplete="strict"): + line_delta, col_start_delta, token_len, token_code, modifier_codes = token_data + if line_delta: + current_col = 0 + current_line += line_delta + current_col += col_start_delta + assert ( + not modifier_codes + ), "TODO: Modifiers not supported (no modifiers defined)" + + resolved_tokens.append( + resolved_semantic_token( + current_line, + current_col, + token_len, + token_types[token_code], + ), + ) + + return resolved_tokens diff --git a/tests/lsp_tests/test_debpkg_metadata.py b/tests/lsp_tests/test_debpkg_metadata.py new file mode 100644 index 0000000..f784b0a --- /dev/null +++ b/tests/lsp_tests/test_debpkg_metadata.py @@ -0,0 +1,25 @@ +from typing import Optional + +import pytest + +from debputy.lsp.lsp_debian_control_reference_data import package_name_to_section + + +@pytest.mark.parametrize( + "name,guessed_section", + [ + ("foo-udeb", "debian-installer"), + ("python-foo", "python"), + ("python-foo-doc", "doc"), + ("libfoo-dev", "libdevel"), + ("php-foo", "php"), + ("libpam-foo", "admin"), + ("fonts-foo", "fonts"), + ("xxx-l10n", "localization"), + ("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/lsp_tests/test_lsp_dctrl.py b/tests/lsp_tests/test_lsp_dctrl.py index 122b929..2bc90ba 100644 --- a/tests/lsp_tests/test_lsp_dctrl.py +++ b/tests/lsp_tests/test_lsp_dctrl.py @@ -1,25 +1,34 @@ import textwrap +from debputy.lsp.debputy_ls import DebputyLanguageServer + try: from lsprotocol.types import ( CompletionParams, TextDocumentIdentifier, HoverParams, MarkupContent, + SemanticTokensParams, ) from debputy.lsp.lsp_debian_control import ( _debian_control_completions, _debian_control_hover, + _debian_control_semantic_tokens_full, ) from pygls.server import LanguageServer except ImportError: pass -from lsp_tests.lsp_tutil import put_doc_with_cursor +from lsp_tests.lsp_tutil import ( + put_doc_with_cursor, + put_doc_no_cursor, + resolve_semantic_tokens, + resolved_semantic_token, +) -def test_dctrl_complete_field(ls: "LanguageServer") -> None: +def test_dctrl_complete_field(ls: "DebputyLanguageServer") -> None: dctrl_uri = "file:///nowhere/debian/control" cursor_pos = put_doc_with_cursor( @@ -48,7 +57,7 @@ def test_dctrl_complete_field(ls: "LanguageServer") -> None: assert "Source" not in keywords -def test_dctrl_hover_doc_field(ls: "LanguageServer") -> None: +def test_dctrl_hover_doc_field(ls: "DebputyLanguageServer") -> None: dctrl_uri = "file:///nowhere/debian/control" cursor_pos = put_doc_with_cursor( ls, @@ -72,7 +81,7 @@ def test_dctrl_hover_doc_field(ls: "LanguageServer") -> None: assert "Determines which architecture" in hover_doc.contents.value -def test_dctrl_hover_doc_synopsis(ls: "LanguageServer") -> None: +def test_dctrl_hover_doc_synopsis(ls: "DebputyLanguageServer") -> None: dctrl_uri = "file:///nowhere/debian/control" cursor_pos = put_doc_with_cursor( ls, @@ -98,7 +107,7 @@ def test_dctrl_hover_doc_synopsis(ls: "LanguageServer") -> None: assert "super charged tool with batteries included" in hover_doc.contents.value -def test_dctrl_hover_doc_substvars(ls: "LanguageServer") -> None: +def test_dctrl_hover_doc_substvars(ls: "DebputyLanguageServer") -> None: dctrl_uri = "file:///nowhere/debian/control" matching_cases = [ "bar (= <CURSOR>${binary:Version})", @@ -158,3 +167,54 @@ def test_dctrl_hover_doc_substvars(ls: "LanguageServer") -> None: 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}`") + + +def test_dctrl_semantic_tokens(ls: "DebputyLanguageServer") -> None: + dctrl_uri = "file:///nowhere/debian/control" + put_doc_no_cursor( + ls, + dctrl_uri, + "debian/control", + textwrap.dedent( + """\ + # Some leading comment + + Source: foo + + # Comment between stanzas + + Package: foo + # Comment before Architecture + Architecture: any + Depends: + # Comment about bar + bar (>= 1.0), + baz [linux-any] <!pkg.foo.bootstrap> + Description: super charged tool with batteries included + Unknown-Field: Some value + # Comment in that field + that we do not know about. +""" + ), + ) + + semantic_tokens = _debian_control_semantic_tokens_full( + ls, + SemanticTokensParams(TextDocumentIdentifier(dctrl_uri)), + ) + resolved_semantic_tokens = resolve_semantic_tokens(semantic_tokens) + assert resolved_semantic_tokens is not None + assert resolved_semantic_tokens == [ + resolved_semantic_token(0, 0, len("# Some leading comment"), "comment"), + resolved_semantic_token(2, 0, len("Source"), "keyword"), + resolved_semantic_token(4, 0, len("# Comment between stanzas"), "comment"), + resolved_semantic_token(6, 0, len("Package"), "keyword"), + resolved_semantic_token(7, 0, len("# Comment before Architecture"), "comment"), + resolved_semantic_token(8, 0, len("Architecture"), "keyword"), + resolved_semantic_token(8, len("Architecture: "), len("any"), "enumMember"), + resolved_semantic_token(9, 0, len("Depends"), "keyword"), + resolved_semantic_token(10, 0, len("# Comment about bar"), "comment"), + resolved_semantic_token(13, 0, len("Description"), "keyword"), + resolved_semantic_token(14, 0, len("Unknown-Field"), "keyword"), + # TODO: resolved_semantic_token(15, 0, len("# Comment in that field"), "comment"), + ] diff --git a/tests/lsp_tests/test_lsp_debputy_manifest_hover.py b/tests/lsp_tests/test_lsp_debputy_manifest_hover.py index c66db80..54c6b6a 100644 --- a/tests/lsp_tests/test_lsp_debputy_manifest_hover.py +++ b/tests/lsp_tests/test_lsp_debputy_manifest_hover.py @@ -2,6 +2,7 @@ import textwrap import pytest +from debputy.lsp.debputy_ls import DebputyLanguageServer from lsp_tests.lsp_tutil import put_doc_with_cursor try: @@ -25,7 +26,7 @@ except ImportError: HAS_PYGLS = False -def test_basic_debputy_hover_tlk(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_tlk(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -52,7 +53,7 @@ def test_basic_debputy_hover_tlk(ls: "LanguageServer") -> None: assert hover_doc.contents.value.startswith("Installations") -def test_basic_debputy_hover_install_docs_key(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_install_docs_key(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -79,7 +80,7 @@ def test_basic_debputy_hover_install_docs_key(ls: "LanguageServer") -> None: assert hover_doc.contents.value.startswith("Install documentation (`install-docs`)") -def test_basic_debputy_hover_install_docs_sources(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_install_docs_sources(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -106,7 +107,7 @@ def test_basic_debputy_hover_install_docs_sources(ls: "LanguageServer") -> None: assert hover_doc.contents.value.startswith("# Attribute `sources`") -def test_basic_debputy_hover_install_docs_when(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_install_docs_when(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -134,7 +135,7 @@ def test_basic_debputy_hover_install_docs_when(ls: "LanguageServer") -> None: assert hover_doc.contents.value.startswith("# Attribute `when`") -def test_basic_debputy_hover_install_docs_str_cond(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_install_docs_str_cond(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -165,7 +166,7 @@ def test_basic_debputy_hover_install_docs_str_cond(ls: "LanguageServer") -> None def test_basic_debputy_hover_install_docs_mapping_cond_key( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( @@ -197,7 +198,7 @@ def test_basic_debputy_hover_install_docs_mapping_cond_key( @pytest.mark.xfail def test_basic_debputy_hover_install_docs_mapping_cond_str_value( - ls: "LanguageServer", + ls: "DebputyLanguageServer", ) -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( @@ -230,7 +231,7 @@ def test_basic_debputy_hover_install_docs_mapping_cond_str_value( ) -def test_basic_debputy_hover_binary_version(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_binary_version(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -256,7 +257,7 @@ def test_basic_debputy_hover_binary_version(ls: "LanguageServer") -> None: ) -def test_basic_debputy_hover_services(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_services(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, @@ -283,7 +284,7 @@ def test_basic_debputy_hover_services(ls: "LanguageServer") -> None: ) -def test_basic_debputy_hover_services_service(ls: "LanguageServer") -> None: +def test_basic_debputy_hover_services_service(ls: "DebputyLanguageServer") -> None: debputy_manifest_uri = "file:///nowhere/debian/debputy.manifest" cursor_pos = put_doc_with_cursor( ls, diff --git a/tests/plugin_tests/__init__.py b/tests/plugin_tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/plugin_tests/__init__.py diff --git a/tests/plugin_tests/conftest.py b/tests/plugin_tests/conftest.py index f2a8aea..6b28755 100644 --- a/tests/plugin_tests/conftest.py +++ b/tests/plugin_tests/conftest.py @@ -1,10 +1,11 @@ import os +from typing import Iterator import pytest @pytest.fixture(autouse=True) -def workaround_debputys_own_test_suite() -> None: +def workaround_debputys_own_test_suite() -> Iterator[None]: # This fixture is only required as long as the tests are run inside `debputy`'s # own test suite. If you copy out a plugin + tests, you should *not* need this # fixture. diff --git a/tests/plugin_tests/numpy3_test.py b/tests/plugin_tests/numpy3_test.py index 9b252fb..62fbd77 100644 --- a/tests/plugin_tests/numpy3_test.py +++ b/tests/plugin_tests/numpy3_test.py @@ -1,4 +1,5 @@ import os +from typing import Iterator import pytest @@ -12,7 +13,7 @@ DATA_FILE = os.path.join(os.path.dirname(__file__), "numpy3_test.data") @pytest.fixture(scope="session") -def numpy3_stub_data_file() -> None: +def numpy3_stub_data_file() -> Iterator[None]: os.environ["_NUMPY_TEST_PATH"] = DATA_FILE yield try: diff --git a/tests/plugin_tests/perl-openssl_test.py b/tests/plugin_tests/perl-openssl_test.py index 37f2ba1..27d680d 100644 --- a/tests/plugin_tests/perl-openssl_test.py +++ b/tests/plugin_tests/perl-openssl_test.py @@ -1,5 +1,6 @@ import stat import os +from typing import Iterator import pytest @@ -13,7 +14,7 @@ STUB_CMD = os.path.join(os.path.dirname(__file__), "perl-ssl_test.sh") @pytest.fixture(scope="session") -def perl_ssl_stub_cmd() -> None: +def perl_ssl_stub_cmd() -> Iterator[None]: os.environ["_PERL_SSL_DEFAULTS_TEST_PATH"] = STUB_CMD mode = stat.S_IMODE(os.stat(STUB_CMD).st_mode) if (mode & 0o500) != 0o500: diff --git a/tests/test_alternatives.py b/tests/test_alternatives.py index 2a42d69..c395dab 100644 --- a/tests/test_alternatives.py +++ b/tests/test_alternatives.py @@ -79,6 +79,8 @@ def test_alternatives( prerm = maintscript_snippets["prerm"].generate_snippet(reverse=True) postinst = maintscript_snippets["postinst"].generate_snippet(reverse=True) + assert prerm is not None + assert postinst is not None assert "--remove x-terminal-emulator /usr/bin/xterm" in prerm assert ( "--install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/bin/xterm 20" diff --git a/tests/test_deb_packaging_support.py b/tests/test_deb_packaging_support.py index d47526d..e4e13da 100644 --- a/tests/test_deb_packaging_support.py +++ b/tests/test_deb_packaging_support.py @@ -203,9 +203,9 @@ def test_upstream_changelog_salsa_issue_49( ) -> None: # https://salsa.debian.org/debian/debputy/-/issues/49 dctrl = package_single_foo_arch_all_cxt_amd64["foo"] - doc_dir = f"./usr/share/doc/{dctrl.name}" + doc_dir_path = f"./usr/share/doc/{dctrl.name}" data_fs_root = build_virtual_fs( - [virtual_path_def(f"{doc_dir}", link_target="foo-data")], read_write_fs=True + [virtual_path_def(doc_dir_path, link_target="foo-data")], read_write_fs=True ) source_fs_root = build_virtual_fs( [virtual_path_def("changelog", materialized_content="Wrong file!")] diff --git a/tests/test_debputy_plugin.py b/tests/test_debputy_plugin.py index a5d7758..dc60597 100644 --- a/tests/test_debputy_plugin.py +++ b/tests/test_debputy_plugin.py @@ -1,6 +1,6 @@ import os import textwrap -from typing import Sequence +from typing import Sequence, Any, List, Optional import pytest @@ -643,6 +643,8 @@ def test_system_service_detection() -> None: systemd_service_system_dir = f"{systemd_service_root_dir}/system" systemd_service_user_dir = f"{systemd_service_root_dir}/user" + services: List[DetectedService[Optional[object]]] + services, _ = plugin.run_service_detection_and_integrations( "systemd", build_virtual_file_system([]) ) @@ -704,7 +706,9 @@ def test_system_service_detection() -> None: assert foo_service.enable_by_default assert foo_service.start_by_default assert foo_service.default_upgrade_rule == "restart" - assert foo_service.service_context.had_install_section + foo_service_context = foo_service.service_context + assert isinstance(foo_service_context, SystemdServiceContext) + assert foo_service_context.had_install_section bar_timer = _extract_service(services, "bar.timer") assert set(bar_timer.names) == {"bar.timer"} @@ -713,7 +717,9 @@ def test_system_service_detection() -> None: assert not bar_timer.enable_by_default assert bar_timer.start_by_default assert bar_timer.default_upgrade_rule == "restart" - assert not bar_timer.service_context.had_install_section + bar_service_context = bar_timer.service_context + assert isinstance(bar_service_context, SystemdServiceContext) + assert not bar_service_context.had_install_section snippets = metadata.maintscripts() assert len(snippets) == 4 @@ -742,6 +748,8 @@ def test_sysv_service_detection() -> None: ) init_dir = "etc/init.d" + services: List[DetectedService[Optional[object]]] + services, _ = plugin.run_service_detection_and_integrations( "sysvinit", build_virtual_file_system([]) ) @@ -1135,9 +1143,9 @@ def test_pam_auth_update() -> None: assert postinst.registration_method == "on_configure" assert "pam-auth-update --package" in postinst.plugin_provided_script - prerms = prerms[0] - assert prerms.registration_method == "on_before_removal" - assert "pam-auth-update --package --remove foo-pam" in prerms.plugin_provided_script + prerm = prerms[0] + assert prerm.registration_method == "on_before_removal" + assert "pam-auth-update --package --remove foo-pam" in prerm.plugin_provided_script def test_auto_depends_solink() -> None: diff --git a/tests/test_declarative_parser.py b/tests/test_declarative_parser.py index 94341ea..26291dd 100644 --- a/tests/test_declarative_parser.py +++ b/tests/test_declarative_parser.py @@ -1,4 +1,11 @@ -from typing import List, TypedDict, NotRequired, Annotated, Union, Mapping +from typing import ( + List, + TypedDict, + NotRequired, + Annotated, + Union, + Mapping, +) import pytest @@ -25,7 +32,7 @@ class TFinalEntity(DebputyParsedContent): class TSourceEntity(TypedDict): sources: NotRequired[List[str]] - source: Annotated[NotRequired[str], DebputyParseHint.target_attribute("sources")] + source: NotRequired[Annotated[str, DebputyParseHint.target_attribute("sources")]] as_: NotRequired[ Annotated[ str, diff --git a/tests/test_fs_metadata.py b/tests/test_fs_metadata.py index 14a397f..f32afb0 100644 --- a/tests/test_fs_metadata.py +++ b/tests/test_fs_metadata.py @@ -1,11 +1,13 @@ import dataclasses import textwrap -from typing import Tuple, List, Optional, Union +from typing import Tuple, List, Optional, Union, Sequence import pytest from debputy.filesystem_scan import PathDef, build_virtual_fs -from debputy.highlevel_manifest_parser import YAMLManifestParser +from debputy.highlevel_manifest_parser import ( + YAMLManifestParser, +) from debputy.intermediate_manifest import PathType, IntermediateManifest, TarMember from debputy.plugin.api import virtual_path_def from debputy.plugin.api.test_api import build_virtual_file_system @@ -57,7 +59,7 @@ def _has_fs_path(tm: TarMember) -> bool: def verify_paths( intermediate_manifest: IntermediateManifest, - expected_results: List[Tuple[Union[str, PathDef], Expected]], + expected_results: Sequence[Tuple[Union[str, PathDef], Expected]], ) -> None: result = {tm.member_path: tm for tm in intermediate_manifest} expected_table = { @@ -89,7 +91,9 @@ def verify_paths( assert tm.member_path in expected_table -def test_mtime_clamp_and_builtin_dir_mode(manifest_parser_pkg_foo): +def test_mtime_clamp_and_builtin_dir_mode( + manifest_parser_pkg_foo: YAMLManifestParser, +) -> None: manifest = manifest_parser_pkg_foo.build_manifest() claim_mtime_to = 255 path_defs: List[Tuple[PathDef, Expected]] = [ diff --git a/tests/test_interpreter.py b/tests/test_interpreter.py index 6cbfd44..154ee4a 100644 --- a/tests/test_interpreter.py +++ b/tests/test_interpreter.py @@ -82,7 +82,7 @@ def test_interpreter_detection( ) -> None: interpreter = extract_shebang_interpreter(raw_shebang) # The `and ...` part is just to get the raw line in the error message - assert interpreter is not None or raw_shebang == b"" + assert interpreter is not None assert interpreter.original_command == original_command assert interpreter.command_full_basename == command_full_basename @@ -147,11 +147,11 @@ def test_interpreter_rewrite(empty_manifest: HighLevelManifest) -> None: foo = fs_root.lookup("usr/bin/foo") foo_sh = fs_root.lookup("usr/bin/foo.sh") - assert foo.is_file + assert foo is not None and foo.is_file with foo.open() as fd: assert fd.read() == "random data" - assert foo_sh.is_file + assert foo_sh is not None and foo_sh.is_file with foo_sh.open() as fd: expected = textwrap.dedent( """\ diff --git a/tests/test_migrations.py b/tests/test_migrations.py index cbf3f79..9d43549 100644 --- a/tests/test_migrations.py +++ b/tests/test_migrations.py @@ -119,8 +119,10 @@ def _assert_unsupported_feature( def _write_manifest(manifest: HighLevelManifest) -> str: + mutable_manifest = manifest.mutable_manifest + assert mutable_manifest is not None with io.StringIO() as fd: - manifest.mutable_manifest.write_to(fd) + mutable_manifest.write_to(fd) return fd.getvalue() @@ -134,7 +136,7 @@ def _verify_migrator_generates_parsable_manifest( expected_warnings: Optional[List[str]] = None, expected_renamed_paths: Optional[List[Tuple[str, str]]] = None, expected_removals: Optional[List[str]] = None, - required_plugins: Optional[Sequence[str]] = tuple(), + required_plugins: Sequence[str] = tuple(), dh_config_mode: Optional[int] = None, ) -> None: # No file, no changes diff --git a/tests/test_packager_provided_files.py b/tests/test_packager_provided_files.py index 149564d..b0e075f 100644 --- a/tests/test_packager_provided_files.py +++ b/tests/test_packager_provided_files.py @@ -1,5 +1,5 @@ import random -from typing import cast +from typing import cast, TYPE_CHECKING import pytest @@ -10,9 +10,17 @@ from debputy.plugin.api.test_api import ( InitializedPluginUnderTest, build_virtual_file_system, ) -from debputy.plugin.api.test_api.test_impl import initialize_plugin_under_test_preloaded +from debputy.plugin.api.test_api.test_impl import ( + initialize_plugin_under_test_preloaded, +) from tutil import faked_binary_package, binary_package_table +if TYPE_CHECKING: + from debputy.plugin.api.test_api.test_impl import InitializedPluginUnderTestImpl + + # Irrelevant, but makes the import not "unused" for things that does not parse `cast("...", ...)` expressions + assert InitializedPluginUnderTestImpl is not None + def ppf_test_plugin(api: DebputyPluginInitializer) -> None: api.packager_provided_file( diff --git a/tests/test_plugin_tester.py b/tests/test_plugin_tester.py index 8078a02..b41f8a3 100644 --- a/tests/test_plugin_tester.py +++ b/tests/test_plugin_tester.py @@ -1,6 +1,6 @@ import json import os.path -from typing import List, Tuple, Type, cast +from typing import List, Tuple, Type, cast, TYPE_CHECKING import pytest @@ -25,6 +25,13 @@ from debputy.plugin.api.test_api.test_impl import ( initialize_plugin_under_test_from_inline_json, ) +if TYPE_CHECKING: + from debputy.plugin.api import PluginInitializationEntryPoint + + # Irrelevant, but makes the import not "unused" for things that does not parse `cast("...", ...)` expressions + assert PluginInitializationEntryPoint is not None + + CUSTOM_PLUGIN_JSON_FILE = os.path.join( os.path.dirname(__file__), "data", "custom-plugin.json.in" ) |