diff --git a/craft_application/_config.py b/craft_application/_config.py index c9619e12..ad21a1c6 100644 --- a/craft_application/_config.py +++ b/craft_application/_config.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Configuration model for craft applications.""" + from __future__ import annotations import craft_cli diff --git a/craft_application/application.py b/craft_application/application.py index e2842018..e63e0668 100644 --- a/craft_application/application.py +++ b/craft_application/application.py @@ -596,9 +596,7 @@ def _pre_run(self, dispatcher: craft_cli.Dispatcher) -> None: self._enable_fetch_service = True self._fetch_service_policy = fetch_service_policy - def get_arg_or_config( - self, parsed_args: argparse.Namespace, item: str - ) -> Any: # noqa: ANN401 + def get_arg_or_config(self, parsed_args: argparse.Namespace, item: str) -> Any: # noqa: ANN401 """Get a configuration option that could be overridden by a command argument. :param parsed_args: The argparse Namespace to check. diff --git a/craft_application/commands/base.py b/craft_application/commands/base.py index 33056c05..1814d3f5 100644 --- a/craft_application/commands/base.py +++ b/craft_application/commands/base.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Base command for craft-application commands.""" + from __future__ import annotations import abc @@ -185,13 +186,17 @@ def fill_parser(self, parser: argparse.ArgumentParser) -> None: @abc.abstractmethod def _run( - self: Self, parsed_args: argparse.Namespace, **kwargs: Any # noqa: ANN401 + self: Self, + parsed_args: argparse.Namespace, + **kwargs: Any, # noqa: ANN401 ) -> int | None: """Run the real run method for an ExtensibleCommand.""" @final def run( - self: Self, parsed_args: argparse.Namespace, **kwargs: Any # noqa: ANN401 + self: Self, + parsed_args: argparse.Namespace, + **kwargs: Any, # noqa: ANN401 ) -> Optional[int]: # noqa: UP007 """Run any prologue callbacks, the main command, and any epilogue callbacks.""" result = None diff --git a/craft_application/commands/lifecycle.py b/craft_application/commands/lifecycle.py index 367a5563..82985767 100644 --- a/craft_application/commands/lifecycle.py +++ b/craft_application/commands/lifecycle.py @@ -12,6 +12,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Basic lifecycle commands for a Craft Application.""" + from __future__ import annotations import argparse diff --git a/craft_application/commands/other.py b/craft_application/commands/other.py index 25963089..38b6de59 100644 --- a/craft_application/commands/other.py +++ b/craft_application/commands/other.py @@ -12,6 +12,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Miscellaneous commands in the 'Other' command group.""" + from __future__ import annotations from typing import TYPE_CHECKING @@ -46,7 +47,8 @@ class VersionCommand(base.AppCommand): common = True def run( - self, parsed_args: argparse.Namespace # noqa: ARG002 (Unused method argument) + self, + parsed_args: argparse.Namespace, # noqa: ARG002 (Unused method argument) ) -> None: """Run the command.""" emit.message(f"{self._app.name} {self._app.version}") diff --git a/craft_application/errors.py b/craft_application/errors.py index a0635730..37060e59 100644 --- a/craft_application/errors.py +++ b/craft_application/errors.py @@ -17,6 +17,7 @@ All errors inherit from craft_cli.CraftError. """ + from __future__ import annotations import os diff --git a/craft_application/fetch.py b/craft_application/fetch.py index c37fcfac..730f0373 100644 --- a/craft_application/fetch.py +++ b/craft_application/fetch.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Utilities to interact with the fetch-service.""" + import contextlib import io import logging @@ -335,7 +336,6 @@ def _get_service_base_dir() -> pathlib.Path: def _install_certificate(instance: craft_providers.Executor) -> None: - logger.info("Installing certificate") # Push the local certificate cert, _key = _obtain_certificate() diff --git a/craft_application/grammar.py b/craft_application/grammar.py index bdd0d7c7..4df049d8 100644 --- a/craft_application/grammar.py +++ b/craft_application/grammar.py @@ -72,7 +72,8 @@ def process_part( # all keys in the dictionary must be a string for item in unprocessed_grammar: # type: ignore[reportUnknownVariableType] if isinstance(item, dict) and any( - not isinstance(key, str) for key in item # type: ignore[reportUnknownVariableType] + not isinstance(key, str) + for key in item # type: ignore[reportUnknownVariableType] ): continue diff --git a/craft_application/launchpad/models/base.py b/craft_application/launchpad/models/base.py index e63945d3..1c61d40e 100644 --- a/craft_application/launchpad/models/base.py +++ b/craft_application/launchpad/models/base.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Base LaunchpadObject.""" + # This file relies heavily on dynamic features from launchpadlib that cause pyright # to complain a lot. As such, we're disabling several pyright checkers for this file # since in this case they generate more noise than utility. @@ -73,9 +74,7 @@ class LaunchpadObject: def __init__(self, lp: Launchpad, lp_obj: Entry) -> None: self._lp = lp - if not isinstance( - lp_obj, Entry - ): # pyright: ignore[reportUnnecessaryIsInstance] + if not isinstance(lp_obj, Entry): # pyright: ignore[reportUnnecessaryIsInstance] raise TypeError( f"Cannot use type {lp_obj.__class__.__name__} for launchpad entries." ) diff --git a/craft_application/launchpad/models/build.py b/craft_application/launchpad/models/build.py index 9eee7b7f..5a0ab361 100644 --- a/craft_application/launchpad/models/build.py +++ b/craft_application/launchpad/models/build.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Launchpad builds.""" + # This file relies heavily on dynamic features from launchpadlib that cause pyright # to complain a lot. As such, we're disabling several pyright checkers for this file # since in this case they generate more noise than utility. diff --git a/craft_application/launchpad/models/code.py b/craft_application/launchpad/models/code.py index c903a253..94c62b11 100644 --- a/craft_application/launchpad/models/code.py +++ b/craft_application/launchpad/models/code.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Source code repositories.""" + # This file relies heavily on dynamic features from launchpadlib that cause pyright # to complain a lot. As such, we're disabling several pyright checkers for this file # since in this case they generate more noise than utility. diff --git a/craft_application/launchpad/models/distro.py b/craft_application/launchpad/models/distro.py index e96a3af0..b4060943 100644 --- a/craft_application/launchpad/models/distro.py +++ b/craft_application/launchpad/models/distro.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Launchpad distro_series.""" + import enum # This file relies heavily on dynamic features from launchpadlib that cause pyright diff --git a/craft_application/launchpad/util.py b/craft_application/launchpad/util.py index cf34a87e..33890ea4 100644 --- a/craft_application/launchpad/util.py +++ b/craft_application/launchpad/util.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Utility functions.""" + import enum import inspect import sys diff --git a/craft_application/models/base.py b/craft_application/models/base.py index cd261f77..457c6a85 100644 --- a/craft_application/models/base.py +++ b/craft_application/models/base.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Base pydantic model for *craft applications.""" + from __future__ import annotations import pathlib diff --git a/craft_application/models/grammar.py b/craft_application/models/grammar.py index 794d0f8f..9338e153 100644 --- a/craft_application/models/grammar.py +++ b/craft_application/models/grammar.py @@ -15,6 +15,7 @@ # with this program. If not, see . """Grammar-aware project for *craft applications.""" + from typing import Any import pydantic diff --git a/craft_application/models/manifest.py b/craft_application/models/manifest.py index 5aa01bfa..f60c10ee 100644 --- a/craft_application/models/manifest.py +++ b/craft_application/models/manifest.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Models representing manifests for projects and fetch-service assets.""" + import hashlib import pathlib from datetime import datetime, timezone diff --git a/craft_application/models/metadata.py b/craft_application/models/metadata.py index 8a01f7b0..fa466e82 100644 --- a/craft_application/models/metadata.py +++ b/craft_application/models/metadata.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Base project metadata model.""" + import pydantic from craft_application.models import base diff --git a/craft_application/models/project.py b/craft_application/models/project.py index b7b92286..a59b7226 100644 --- a/craft_application/models/project.py +++ b/craft_application/models/project.py @@ -17,6 +17,7 @@ This defines the structure of the input file (e.g. snapcraft.yaml) """ + import abc import dataclasses import warnings diff --git a/craft_application/remote/utils.py b/craft_application/remote/utils.py index 30fa66b8..54522aaa 100644 --- a/craft_application/remote/utils.py +++ b/craft_application/remote/utils.py @@ -13,6 +13,7 @@ # along with this program. If not, see . """Remote build utilities.""" + from __future__ import annotations import shutil @@ -109,7 +110,9 @@ def rmtree(directory: Path) -> None: def _remove_readonly( - func: Callable[..., Any], filepath: str, _: Any # noqa: ANN401 + func: Callable[..., Any], + filepath: str, + _: Any, # noqa: ANN401 ) -> None: """Shutil onerror function to make read-only files writable. diff --git a/craft_application/secrets.py b/craft_application/secrets.py index c45ccf0e..aa8d0fd7 100644 --- a/craft_application/secrets.py +++ b/craft_application/secrets.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Handling of build-time secrets.""" + from __future__ import annotations import base64 @@ -149,7 +150,8 @@ def _check_for_secrets(data: Any) -> None: # noqa: ANN401 (using Any on purpose def _check_str( - value: Any, field_name: str # noqa: ANN401 (using Any on purpose) + value: Any, # noqa: ANN401 + field_name: str, ) -> None: if isinstance(value, str) and (match := SECRET_REGEX.search(value)): raise errors.SecretsFieldError( diff --git a/craft_application/services/base.py b/craft_application/services/base.py index 41da4ea3..b9dace95 100644 --- a/craft_application/services/base.py +++ b/craft_application/services/base.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Abstract base service class.""" + from __future__ import annotations import abc diff --git a/craft_application/services/config.py b/craft_application/services/config.py index 6b8c4e48..0329f92d 100644 --- a/craft_application/services/config.py +++ b/craft_application/services/config.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Configuration service.""" + from __future__ import annotations import abc diff --git a/craft_application/services/fetch.py b/craft_application/services/fetch.py index 161f5fc7..f50edda4 100644 --- a/craft_application/services/fetch.py +++ b/craft_application/services/fetch.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Service class to communicate with the fetch-service.""" + from __future__ import annotations import json diff --git a/craft_application/services/init.py b/craft_application/services/init.py index dfdd5eae..13cb0c19 100644 --- a/craft_application/services/init.py +++ b/craft_application/services/init.py @@ -15,6 +15,7 @@ # along with this program. If not, see . """Service for initializing a project.""" + from __future__ import annotations import os diff --git a/craft_application/services/lifecycle.py b/craft_application/services/lifecycle.py index 50024c1c..2d1273a6 100644 --- a/craft_application/services/lifecycle.py +++ b/craft_application/services/lifecycle.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """craft-parts lifecycle integration.""" + from __future__ import annotations import contextlib diff --git a/craft_application/services/package.py b/craft_application/services/package.py index c5748955..d7b5f3d9 100644 --- a/craft_application/services/package.py +++ b/craft_application/services/package.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Service class for lifecycle commands.""" + from __future__ import annotations import abc diff --git a/craft_application/services/provider.py b/craft_application/services/provider.py index efadd82f..b83118f2 100644 --- a/craft_application/services/provider.py +++ b/craft_application/services/provider.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Service class for craft-providers.""" + from __future__ import annotations import contextlib diff --git a/craft_application/services/remotebuild.py b/craft_application/services/remotebuild.py index e7645ac8..1fcc1ab3 100644 --- a/craft_application/services/remotebuild.py +++ b/craft_application/services/remotebuild.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Service class for remote build commands.""" + from __future__ import annotations import contextlib diff --git a/craft_application/services/request.py b/craft_application/services/request.py index 75fee724..f21bf44d 100644 --- a/craft_application/services/request.py +++ b/craft_application/services/request.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Service class for network requests.""" + from __future__ import annotations import pathlib diff --git a/craft_application/services/service_factory.py b/craft_application/services/service_factory.py index 715d6ac4..8045d47f 100644 --- a/craft_application/services/service_factory.py +++ b/craft_application/services/service_factory.py @@ -12,6 +12,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Factory class for lazy-loading service classes.""" + from __future__ import annotations import dataclasses diff --git a/craft_application/util/callbacks.py b/craft_application/util/callbacks.py index 75054406..ecf63dca 100644 --- a/craft_application/util/callbacks.py +++ b/craft_application/util/callbacks.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Utilities related to callbacks.""" + from __future__ import annotations from collections.abc import Callable, Iterable diff --git a/craft_application/util/error_formatting.py b/craft_application/util/error_formatting.py index c6fdbf5b..1aa7acd3 100644 --- a/craft_application/util/error_formatting.py +++ b/craft_application/util/error_formatting.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Helper utilities for formatting error messages.""" + from __future__ import annotations from collections.abc import Iterable diff --git a/craft_application/util/logging.py b/craft_application/util/logging.py index 2a24b88f..2f4cfbd4 100644 --- a/craft_application/util/logging.py +++ b/craft_application/util/logging.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Logging helpers.""" + import logging diff --git a/craft_application/util/paths.py b/craft_application/util/paths.py index fd1800e6..649f5ad7 100644 --- a/craft_application/util/paths.py +++ b/craft_application/util/paths.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Utility functions and helpers related to path handling.""" + from __future__ import annotations import pathlib diff --git a/craft_application/util/platforms.py b/craft_application/util/platforms.py index b08a8a27..17cf3617 100644 --- a/craft_application/util/platforms.py +++ b/craft_application/util/platforms.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """OS and architecture helpers for craft applications.""" + from __future__ import annotations import functools diff --git a/craft_application/util/snap_config.py b/craft_application/util/snap_config.py index 98cb50d9..a3c0b9ec 100644 --- a/craft_application/util/snap_config.py +++ b/craft_application/util/snap_config.py @@ -15,6 +15,7 @@ # along with this program. If not, see . """Snap config file definitions and helpers.""" + import os from typing import Any, Literal diff --git a/craft_application/util/system.py b/craft_application/util/system.py index f59d89ed..debe9697 100644 --- a/craft_application/util/system.py +++ b/craft_application/util/system.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """System-level util functions.""" + from __future__ import annotations import os diff --git a/craft_application/util/yaml.py b/craft_application/util/yaml.py index 4a7f18e8..d88ab898 100644 --- a/craft_application/util/yaml.py +++ b/craft_application/util/yaml.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """YAML helpers for craft applications.""" + from __future__ import annotations import contextlib @@ -113,7 +114,9 @@ def safe_yaml_load(stream: TextIO) -> Any: # noqa: ANN401 - The YAML could be a @overload def dump_yaml( - data: Any, stream: TextIO, **kwargs: Any # noqa: ANN401 # Any gets passed to pyyaml + data: Any, # noqa: ANN401 + stream: TextIO, + **kwargs: Any, # noqa: ANN401 # Any gets passed to pyyaml ) -> None: ... # pragma: no cover diff --git a/tests/conftest.py b/tests/conftest.py index bed92b32..e3323551 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Shared data for all craft-application tests.""" + from __future__ import annotations import os @@ -72,7 +73,6 @@ def test_with_build_secrets(...) class FakeConfigModel(craft_application.ConfigModel): - my_str: str my_int: int my_bool: bool diff --git a/tests/integration/commands/test_init.py b/tests/integration/commands/test_init.py index 111502ba..5f9edecb 100644 --- a/tests/integration/commands/test_init.py +++ b/tests/integration/commands/test_init.py @@ -15,6 +15,7 @@ # with this program. If not, see . """Tests for init command.""" + import os import pathlib import textwrap diff --git a/tests/integration/services/test_fetch.py b/tests/integration/services/test_fetch.py index 2750b465..59532954 100644 --- a/tests/integration/services/test_fetch.py +++ b/tests/integration/services/test_fetch.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for FetchService.""" + import contextlib import io import json diff --git a/tests/integration/services/test_init.py b/tests/integration/services/test_init.py index 6ed4d72b..0cc43c3f 100644 --- a/tests/integration/services/test_init.py +++ b/tests/integration/services/test_init.py @@ -91,9 +91,7 @@ def get_testcraft_yaml(*, version: str = "git") -> str: source: . platforms: amd64: - """.replace( - "<>", version - ) + """.replace("<>", version) ) diff --git a/tests/integration/services/test_lifecycle.py b/tests/integration/services/test_lifecycle.py index 8c4e2bad..a0ac2a79 100644 --- a/tests/integration/services/test_lifecycle.py +++ b/tests/integration/services/test_lifecycle.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Integration tests for parts lifecycle.""" + import os import textwrap diff --git a/tests/integration/services/test_provider.py b/tests/integration/services/test_provider.py index 3e51a492..31151308 100644 --- a/tests/integration/services/test_provider.py +++ b/tests/integration/services/test_provider.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Integration tests for provider service.""" + import contextlib import subprocess diff --git a/tests/integration/services/test_request.py b/tests/integration/services/test_request.py index e7b7e74b..860799e4 100644 --- a/tests/integration/services/test_request.py +++ b/tests/integration/services/test_request.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Integration tests for the Request service.""" + import hashlib from unittest.mock import call diff --git a/tests/integration/services/test_service_factory.py b/tests/integration/services/test_service_factory.py index 4b50d071..06c7a34a 100644 --- a/tests/integration/services/test_service_factory.py +++ b/tests/integration/services/test_service_factory.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Integration tests for ServiceFactory.""" + import pytest from craft_application import services diff --git a/tests/integration/test_version.py b/tests/integration/test_version.py index b4a33a5b..fb38519a 100644 --- a/tests/integration/test_version.py +++ b/tests/integration/test_version.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . """Starcraft versioning tests.""" + import re import subprocess diff --git a/tests/unit/commands/test_base.py b/tests/unit/commands/test_base.py index 5a0aea65..dd160486 100644 --- a/tests/unit/commands/test_base.py +++ b/tests/unit/commands/test_base.py @@ -12,6 +12,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for AppCommand.""" + from __future__ import annotations import argparse @@ -100,7 +101,9 @@ def get_run_count(self) -> dict[str, int]: return {"fake": self.__run_count} def _run( - self, parsed_args: argparse.Namespace, **kwargs # noqa: ARG002 + self, + parsed_args: argparse.Namespace, # noqa: ARG002 + **kwargs, # noqa: ARG002 ) -> int | None: self.__run_count += 1 return self.__run_count @@ -123,7 +126,9 @@ def get_run_count(self) -> dict[str, int]: return counts def _run( - self, parsed_args: argparse.Namespace, **kwargs # noqa: ARG002 + self, + parsed_args: argparse.Namespace, + **kwargs, # noqa: ARG002 ) -> int | None: self.__run_count += 1 return super()._run(parsed_args) diff --git a/tests/unit/commands/test_lifecycle.py b/tests/unit/commands/test_lifecycle.py index b4b0960b..16d6c7ef 100644 --- a/tests/unit/commands/test_lifecycle.py +++ b/tests/unit/commands/test_lifecycle.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Tests for lifecycle commands.""" + import argparse import pathlib import subprocess diff --git a/tests/unit/commands/test_other.py b/tests/unit/commands/test_other.py index 95a40b5c..d8a936ff 100644 --- a/tests/unit/commands/test_other.py +++ b/tests/unit/commands/test_other.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Tests for other commands.""" + import argparse import pytest diff --git a/tests/unit/launchpad/models/test_base.py b/tests/unit/launchpad/models/test_base.py index 19c5f93f..8733b04a 100644 --- a/tests/unit/launchpad/models/test_base.py +++ b/tests/unit/launchpad/models/test_base.py @@ -117,9 +117,7 @@ def test_getattr_with_callable_annotation(fake_launchpad, mock_lplib_entry): mock_annotation = mock.Mock() class AnnotationsObject(FakeLaunchpadObject): - some_attribute_right_here: ( - mock_annotation # pyright: ignore[reportInvalidTypeForm] - ) + some_attribute_right_here: mock_annotation # pyright: ignore[reportInvalidTypeForm] test_obj = AnnotationsObject(fake_launchpad, mock_lplib_entry) diff --git a/tests/unit/launchpad/test_launchpad.py b/tests/unit/launchpad/test_launchpad.py index 768171d3..fac901ed 100644 --- a/tests/unit/launchpad/test_launchpad.py +++ b/tests/unit/launchpad/test_launchpad.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Unit tests for main Launchpad client.""" + from __future__ import annotations import enum diff --git a/tests/unit/launchpad/test_util.py b/tests/unit/launchpad/test_util.py index 5ebb4189..d93c3180 100644 --- a/tests/unit/launchpad/test_util.py +++ b/tests/unit/launchpad/test_util.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for utility functions.""" + from unittest import mock import pytest diff --git a/tests/unit/models/test_base.py b/tests/unit/models/test_base.py index da7067c6..c3b732f9 100644 --- a/tests/unit/models/test_base.py +++ b/tests/unit/models/test_base.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for CraftBaseModel""" + from pathlib import Path import pydantic @@ -24,7 +25,6 @@ class MyBaseModel(models.CraftBaseModel): - value1: int value2: str @@ -62,7 +62,6 @@ def test_model_reference_slug_errors(): class CoerceModel(models.CraftBaseModel): - stringy: str diff --git a/tests/unit/models/test_project.py b/tests/unit/models/test_project.py index c49e8d5d..aec66482 100644 --- a/tests/unit/models/test_project.py +++ b/tests/unit/models/test_project.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for BaseProject""" + import copy import pathlib import re diff --git a/tests/unit/services/conftest.py b/tests/unit/services/conftest.py index 61eedf5c..9e5a209b 100644 --- a/tests/unit/services/conftest.py +++ b/tests/unit/services/conftest.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Configuration for craft-application unit tests.""" + from __future__ import annotations from collections.abc import Callable diff --git a/tests/unit/services/test_config.py b/tests/unit/services/test_config.py index 2eb78196..f773335a 100644 --- a/tests/unit/services/test_config.py +++ b/tests/unit/services/test_config.py @@ -177,7 +177,10 @@ def test_snap_config_handler_not_snap(mocker, default_app_metadata): ) def test_snap_config_handler(snap_config_handler, item: str, content: str): snap_item = item.replace("_", "-") - with pytest_subprocess.FakeProcess.context() as fp, pytest.MonkeyPatch.context() as mp: + with ( + pytest_subprocess.FakeProcess.context() as fp, + pytest.MonkeyPatch.context() as mp, + ): mp.setattr("snaphelpers._ctl.Popen", subprocess.Popen) fp.register( ["/usr/bin/snapctl", "get", "-d", snap_item], diff --git a/tests/unit/services/test_fetch.py b/tests/unit/services/test_fetch.py index 9e9ee727..9ab5432c 100644 --- a/tests/unit/services/test_fetch.py +++ b/tests/unit/services/test_fetch.py @@ -22,6 +22,7 @@ As such, this module mostly unit-tests error paths coming from wrong usage of the FetchService class. """ + import contextlib import json import pathlib diff --git a/tests/unit/services/test_lifecycle.py b/tests/unit/services/test_lifecycle.py index 5dcb6c15..14bcb809 100644 --- a/tests/unit/services/test_lifecycle.py +++ b/tests/unit/services/test_lifecycle.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Unit tests for parts lifecycle.""" + from __future__ import annotations import dataclasses diff --git a/tests/unit/services/test_package.py b/tests/unit/services/test_package.py index 0e48bc66..fdd84b86 100644 --- a/tests/unit/services/test_package.py +++ b/tests/unit/services/test_package.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for PackageService.""" + from __future__ import annotations import dataclasses diff --git a/tests/unit/services/test_provider.py b/tests/unit/services/test_provider.py index 0d113009..1755ee08 100644 --- a/tests/unit/services/test_provider.py +++ b/tests/unit/services/test_provider.py @@ -634,10 +634,13 @@ def test_instance_fetch_logs_error( # Setup the build instance and pretend the command inside it finished with error. provider_service = setup_fetch_logs_provider(should_have_logfile=True) - with pytest.raises(RuntimeError), provider_service.instance( - build_info=_get_build_info(), - work_dir=pathlib.Path(), - ) as mock_instance: + with ( + pytest.raises(RuntimeError), + provider_service.instance( + build_info=_get_build_info(), + work_dir=pathlib.Path(), + ) as mock_instance, + ): raise RuntimeError("Faking an error in the build instance!") # Now check that the logs from the build instance were collected. diff --git a/tests/unit/services/test_remotebuild.py b/tests/unit/services/test_remotebuild.py index fc5037c5..747bbdc1 100644 --- a/tests/unit/services/test_remotebuild.py +++ b/tests/unit/services/test_remotebuild.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for the remote build service.""" + import datetime import pathlib from unittest import mock diff --git a/tests/unit/services/test_repositories.py b/tests/unit/services/test_repositories.py index 4e1bb46c..e8543ea9 100644 --- a/tests/unit/services/test_repositories.py +++ b/tests/unit/services/test_repositories.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for PackageService.""" + from __future__ import annotations from pathlib import Path diff --git a/tests/unit/services/test_request.py b/tests/unit/services/test_request.py index 9ab2ed70..4fa11f11 100644 --- a/tests/unit/services/test_request.py +++ b/tests/unit/services/test_request.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Unit tests for the Request service.""" + from unittest.mock import call import craft_cli.pytest_plugin diff --git a/tests/unit/services/test_service_factory.py b/tests/unit/services/test_service_factory.py index 7dcf4f0a..f60787d6 100644 --- a/tests/unit/services/test_service_factory.py +++ b/tests/unit/services/test_service_factory.py @@ -12,6 +12,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Tests for ServiceFactory""" + from __future__ import annotations from unittest import mock diff --git a/tests/unit/test_application.py b/tests/unit/test_application.py index 02dfae78..395ec63f 100644 --- a/tests/unit/test_application.py +++ b/tests/unit/test_application.py @@ -2196,13 +2196,11 @@ def test_clean_platform(monkeypatch, tmp_path, app_metadata, fake_services, mock class AppConfigCommand(AppCommand): - name: str = "app-config" help_msg: str = "Help text" overview: str = "Overview" def fill_parser(self, parser: argparse.ArgumentParser) -> None: - name = self._app.name parser.add_argument( "app-name", diff --git a/tests/unit/test_application_fetch.py b/tests/unit/test_application_fetch.py index 3487d0ec..f0977837 100644 --- a/tests/unit/test_application_fetch.py +++ b/tests/unit/test_application_fetch.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Unit tests for the interaction between the Application and the FetchService.""" + from typing import Any from unittest import mock diff --git a/tests/unit/test_errors.py b/tests/unit/test_errors.py index 830efd5d..f3f21416 100644 --- a/tests/unit/test_errors.py +++ b/tests/unit/test_errors.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program. If not, see . """Tests for error classes.""" + import textwrap import craft_parts diff --git a/tests/unit/test_fetch.py b/tests/unit/test_fetch.py index 92583464..a4c5462a 100644 --- a/tests/unit/test_fetch.py +++ b/tests/unit/test_fetch.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for fetch-service-related functions.""" + import re import subprocess from pathlib import Path diff --git a/tests/unit/test_grammar.py b/tests/unit/test_grammar.py index 70afa30f..07055ac9 100644 --- a/tests/unit/test_grammar.py +++ b/tests/unit/test_grammar.py @@ -15,7 +15,6 @@ # with this program. If not, see . """Unit tests for craft-application grammar process.""" - import pydantic import pytest from craft_application.models.grammar import ( diff --git a/tests/unit/util/test_docs.py b/tests/unit/util/test_docs.py index b6a15b78..0c63adc9 100644 --- a/tests/unit/util/test_docs.py +++ b/tests/unit/util/test_docs.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for documentation functions.""" + import pytest from craft_application.util import docs diff --git a/tests/unit/util/test_error_formatting.py b/tests/unit/util/test_error_formatting.py index daf1d58d..9989e12c 100644 --- a/tests/unit/util/test_error_formatting.py +++ b/tests/unit/util/test_error_formatting.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for error formatting.""" + import textwrap import pytest @@ -112,7 +113,8 @@ def test_format_pydantic_error_normalization(): ] result = format_pydantic_errors( - errors, file_name="this.yaml" # pyright: ignore[reportArgumentType] + errors, + file_name="this.yaml", # pyright: ignore[reportArgumentType] ) expected = textwrap.dedent( """ diff --git a/tests/unit/util/test_paths.py b/tests/unit/util/test_paths.py index 5dacf838..3a8778a8 100644 --- a/tests/unit/util/test_paths.py +++ b/tests/unit/util/test_paths.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for internal path utilities.""" + import pathlib import pytest diff --git a/tests/unit/util/test_retry.py b/tests/unit/util/test_retry.py index e8e05daa..17ede13d 100644 --- a/tests/unit/util/test_retry.py +++ b/tests/unit/util/test_retry.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for retry().""" + import time from unittest.mock import call diff --git a/tests/unit/util/test_system.py b/tests/unit/util/test_system.py index 343394d3..5cf1915a 100644 --- a/tests/unit/util/test_system.py +++ b/tests/unit/util/test_system.py @@ -163,7 +163,6 @@ def test_get_parallel_build_count(monkeypatch, mocker, env_dict, cpu_count, expe ], ) def test_get_parallel_build_count_error(monkeypatch, mocker, env_dict, cpu_count): - mocker.patch("os.cpu_count", return_value=cpu_count) for env_dict_key, env_dict_value in env_dict.items(): monkeypatch.setenv(env_dict_key, env_dict_value) diff --git a/tests/unit/util/test_yaml.py b/tests/unit/util/test_yaml.py index a717d8ab..832a33ad 100644 --- a/tests/unit/util/test_yaml.py +++ b/tests/unit/util/test_yaml.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . """Tests for internal model utilities.""" + import io import pathlib