From f6faa1840945425840a585dee36acd3d251fa887 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 13 Aug 2024 20:53:56 +0200 Subject: [PATCH] Bump pre-commit ruff to 0.5.7 and reformat (#5242) It seems that the codebase is not formatted with the latest ruff version. This PR reformats the codebase with ruff 0.5.7. --- .pre-commit-config.yaml | 2 +- pyproject.toml | 16 +- setup.py | 1 + supervisor/__main__.py | 1 + supervisor/addons/addon.py | 1 + supervisor/addons/build.py | 1 + supervisor/addons/const.py | 1 + supervisor/addons/data.py | 1 + supervisor/addons/manager.py | 1 + supervisor/addons/model.py | 1 + supervisor/addons/options.py | 1 + supervisor/addons/utils.py | 1 + supervisor/addons/validate.py | 1 + supervisor/api/audio.py | 1 + supervisor/api/auth.py | 1 + supervisor/api/backups.py | 7 +- supervisor/api/cli.py | 1 + supervisor/api/discovery.py | 1 + supervisor/api/dns.py | 1 + supervisor/api/docker.py | 1 + supervisor/api/hardware.py | 1 + supervisor/api/ingress.py | 1 + supervisor/api/jobs.py | 1 + supervisor/api/multicast.py | 1 + supervisor/api/network.py | 1 + supervisor/api/observer.py | 1 + supervisor/api/os.py | 1 + supervisor/api/proxy.py | 1 + supervisor/api/resolution.py | 1 + supervisor/api/root.py | 1 + supervisor/api/security.py | 1 + supervisor/api/store.py | 1 + supervisor/api/supervisor.py | 1 + supervisor/api/utils.py | 1 + supervisor/arch.py | 1 + supervisor/auth.py | 1 + supervisor/backups/backup.py | 1 + supervisor/backups/const.py | 1 + supervisor/backups/utils.py | 1 + supervisor/backups/validate.py | 1 + supervisor/bootstrap.py | 2 + supervisor/bus.py | 1 + supervisor/config.py | 1 + supervisor/const.py | 1 + supervisor/core.py | 1 + supervisor/coresys.py | 1 + supervisor/dbus/agent/__init__.py | 1 + supervisor/dbus/agent/apparmor.py | 1 + supervisor/dbus/agent/boards/__init__.py | 1 + supervisor/dbus/agent/datadisk.py | 1 + supervisor/dbus/const.py | 1 + supervisor/dbus/hostname.py | 1 + supervisor/dbus/interface.py | 1 + supervisor/dbus/logind.py | 1 + supervisor/dbus/manager.py | 1 + supervisor/dbus/network/__init__.py | 1 + supervisor/dbus/network/configuration.py | 1 + supervisor/dbus/network/dns.py | 1 + supervisor/dbus/network/setting/__init__.py | 1 + supervisor/dbus/network/setting/generate.py | 1 + supervisor/dbus/network/settings.py | 1 + supervisor/dbus/network/wireless.py | 1 + supervisor/dbus/resolved.py | 1 + supervisor/dbus/timedate.py | 1 + supervisor/dbus/udisks2/__init__.py | 1 + supervisor/dbus/udisks2/block.py | 1 + supervisor/discovery/__init__.py | 1 + supervisor/docker/addon.py | 1 + supervisor/docker/audio.py | 1 + supervisor/docker/cli.py | 1 + supervisor/docker/const.py | 1 + supervisor/docker/dns.py | 1 + supervisor/docker/homeassistant.py | 1 + supervisor/docker/interface.py | 1 + supervisor/docker/manager.py | 1 + supervisor/docker/multicast.py | 1 + supervisor/docker/network.py | 1 + supervisor/docker/observer.py | 1 + supervisor/docker/stats.py | 1 + supervisor/docker/supervisor.py | 1 + supervisor/hardware/const.py | 1 + supervisor/hardware/data.py | 1 + supervisor/hardware/disk.py | 1 + supervisor/hardware/helper.py | 1 + supervisor/hardware/manager.py | 1 + supervisor/hardware/monitor.py | 1 + supervisor/hardware/policy.py | 1 + supervisor/homeassistant/api.py | 1 + supervisor/homeassistant/const.py | 1 + supervisor/homeassistant/core.py | 1 + supervisor/homeassistant/secrets.py | 1 + supervisor/homeassistant/validate.py | 1 + supervisor/homeassistant/websocket.py | 1 + supervisor/host/apparmor.py | 1 + supervisor/host/const.py | 1 + supervisor/host/control.py | 1 + supervisor/host/info.py | 1 + supervisor/host/logs.py | 1 + supervisor/host/manager.py | 1 + supervisor/host/network.py | 1 + supervisor/host/services.py | 1 + supervisor/host/sound.py | 1 + supervisor/ingress.py | 1 + supervisor/jobs/const.py | 1 + supervisor/jobs/decorator.py | 1 + supervisor/misc/filter.py | 1 + supervisor/misc/scheduler.py | 1 + supervisor/misc/tasks.py | 1 + supervisor/plugins/base.py | 1 + supervisor/plugins/const.py | 1 + supervisor/plugins/manager.py | 1 + supervisor/resolution/check.py | 1 + supervisor/resolution/checks/addon_pwned.py | 1 + supervisor/resolution/checks/backups.py | 1 + supervisor/resolution/checks/base.py | 1 + supervisor/resolution/checks/core_security.py | 1 + supervisor/resolution/checks/dns_server.py | 1 + .../resolution/checks/dns_server_ipv6.py | 1 + supervisor/resolution/checks/free_space.py | 1 + .../checks/network_interface_ipv4.py | 1 + .../resolution/checks/supervisor_trust.py | 1 + supervisor/resolution/const.py | 1 + supervisor/resolution/data.py | 1 + supervisor/resolution/evaluate.py | 1 + supervisor/resolution/evaluations/apparmor.py | 1 + supervisor/resolution/evaluations/base.py | 1 + supervisor/resolution/evaluations/cgroup.py | 1 + .../resolution/evaluations/container.py | 1 + .../evaluations/docker_configuration.py | 1 + supervisor/resolution/evaluations/lxc.py | 1 + .../resolution/evaluations/restart_policy.py | 1 + .../resolution/evaluations/source_mods.py | 1 + supervisor/resolution/fixup.py | 1 + .../resolution/fixups/addon_execute_remove.py | 1 + supervisor/resolution/fixups/base.py | 1 + .../resolution/fixups/store_execute_reload.py | 1 + .../resolution/fixups/store_execute_remove.py | 1 + .../resolution/fixups/store_execute_reset.py | 1 + .../fixups/system_clear_full_backup.py | 1 + .../fixups/system_create_full_backup.py | 1 + .../fixups/system_execute_integrity.py | 1 + .../fixups/system_execute_reboot.py | 1 + supervisor/resolution/module.py | 1 + supervisor/resolution/notify.py | 1 + supervisor/resolution/validate.py | 1 + supervisor/security/const.py | 1 + supervisor/security/module.py | 1 + supervisor/services/__init__.py | 1 + supervisor/services/data.py | 1 + supervisor/services/interface.py | 1 + supervisor/services/modules/mqtt.py | 1 + supervisor/services/modules/mysql.py | 1 + supervisor/services/validate.py | 1 + supervisor/store/__init__.py | 1 + supervisor/store/const.py | 1 + supervisor/store/data.py | 1 + supervisor/store/git.py | 1 + supervisor/store/utils.py | 1 + supervisor/supervisor.py | 1 + supervisor/updater.py | 1 + supervisor/utils/__init__.py | 1 + supervisor/utils/apparmor.py | 1 + supervisor/utils/codenotary.py | 1 + supervisor/utils/common.py | 1 + supervisor/utils/dbus.py | 1 + supervisor/utils/dt.py | 1 + supervisor/utils/json.py | 1 + supervisor/utils/log_format.py | 1 + supervisor/utils/logging.py | 1 + supervisor/utils/pwned.py | 1 + supervisor/utils/systemd_journal.py | 1 + supervisor/utils/whoami.py | 1 + supervisor/utils/yaml.py | 1 + supervisor/validate.py | 1 + tests/addons/test_addon.py | 140 +++++++++----- tests/addons/test_build.py | 56 ++++-- tests/addons/test_config.py | 7 +- tests/addons/test_manager.py | 67 ++++--- tests/addons/test_options.py | 1 + tests/api/__init__.py | 1 + tests/api/test_discovery.py | 11 +- tests/api/test_dns.py | 1 + tests/api/test_docker.py | 1 + tests/api/test_hardware.py | 1 + tests/api/test_network.py | 8 +- tests/api/test_resolution.py | 1 + tests/api/test_root.py | 1 + tests/api/test_store.py | 14 +- tests/api/test_supervisor.py | 16 +- tests/conftest.py | 105 +++++----- tests/dbus/agent/boards/test_board.py | 1 + tests/dbus/agent/boards/test_green.py | 9 +- tests/dbus/agent/boards/test_yellow.py | 9 +- tests/dbus/agent/test_agent.py | 1 + tests/dbus/agent/test_apparmor.py | 1 + tests/dbus/agent/test_cgroup.py | 1 + tests/dbus/test_hostname.py | 1 + tests/dbus/test_interface.py | 5 +- tests/dbus/test_login.py | 1 + tests/dbus/test_rauc.py | 1 + tests/dbus/test_systemd.py | 1 + tests/dbus/test_timedate.py | 1 + tests/dbus_service_mocks/systemd.py | 6 +- tests/docker/__init__.py | 1 + tests/docker/test_addon.py | 34 ++-- tests/docker/test_credentials.py | 1 + tests/docker/test_homeassistant.py | 15 +- tests/docker/test_interface.py | 62 +++--- tests/docker/test_monitor.py | 44 +++-- tests/docker/test_stats.py | 1 + tests/hardware/test_data.py | 1 + tests/hardware/test_disk.py | 1 + tests/hardware/test_helper.py | 1 + tests/hardware/test_module.py | 1 + tests/hardware/test_policy.py | 1 + tests/homeassistant/test_core.py | 179 +++++++++++------- .../test_home_assistant_watchdog.py | 69 ++++--- tests/homeassistant/test_module.py | 4 +- tests/homeassistant/test_websocket.py | 1 + tests/host/test_apparmor_control.py | 7 +- tests/host/test_connectivity.py | 1 + tests/host/test_info.py | 1 + tests/host/test_logs.py | 7 +- tests/host/test_manager.py | 7 +- tests/host/test_network.py | 1 + tests/jobs/test_job_decorator.py | 21 +- tests/misc/test_filter_data.py | 1 + tests/misc/test_sanitise_url.py | 1 + tests/misc/test_scheduler.py | 1 + tests/misc/test_tasks.py | 49 ++--- tests/mounts/test_mount.py | 1 + tests/os/test_data_disk.py | 5 +- tests/os/test_manager.py | 14 +- tests/plugins/test_audio.py | 17 +- tests/plugins/test_dns.py | 53 ++++-- tests/plugins/test_plugin_manager.py | 18 +- tests/resolution/check/test_check.py | 16 +- .../check/test_check_addon_pwned.py | 1 + tests/resolution/check/test_check_backups.py | 1 + .../check/test_check_core_security.py | 1 + .../test_check_detached_addon_missing.py | 1 + .../test_check_detached_addon_removed.py | 1 + .../check/test_check_disabled_data_disk.py | 1 + .../check/test_check_dns_server_failure.py | 8 +- .../check/test_check_dns_server_ipv6_error.py | 10 +- .../resolution/check/test_check_free_space.py | 1 + .../check/test_check_multiple_data_disks.py | 1 + .../test_check_network_interface_ipv4.py | 1 + .../check/test_check_supervisor_trust.py | 1 + .../evaluation/test_connectivity_check.py | 1 + .../evaluation/test_evaluate_apparmor.py | 1 + .../evaluation/test_evaluate_cgroup.py | 1 + .../evaluation/test_evaluate_container.py | 1 + .../evaluation/test_evaluate_content_trust.py | 1 + .../evaluation/test_evaluate_dbus.py | 1 + .../evaluation/test_evaluate_dns_server.py | 1 + .../test_evaluate_docker_configuration.py | 1 + .../test_evaluate_docker_version.py | 1 + .../test_evaluate_job_conditions.py | 1 + .../evaluation/test_evaluate_lxc.py | 1 + .../test_evaluate_network_manager.py | 1 + .../test_evaluate_operating_system.py | 1 + .../evaluation/test_evaluate_os_agent.py | 1 + .../evaluation/test_evaluate_privileged.py | 1 + .../evaluation/test_evaluate_source_mods.py | 1 + .../evaluation/test_evaluate_systemd.py | 1 + .../test_evaluate_systemd_journal.py | 1 + .../resolution/evaluation/test_evaluation.py | 80 ++++---- .../fixup/test_addon_execute_rebuild.py | 7 +- .../fixup/test_addon_execute_remove.py | 1 + .../fixup/test_core_execute_rebuild.py | 7 +- tests/resolution/fixup/test_fixup.py | 1 + .../fixup/test_store_execute_reload.py | 1 + .../fixup/test_store_execute_remove.py | 1 + .../fixup/test_store_execute_reset.py | 1 + .../fixup/test_system_clear_full_backup.py | 1 + .../fixup/test_system_create_full_backup.py | 1 + .../fixup/test_system_execute_integrity.py | 1 + .../fixup/test_system_execute_rebuild.py | 12 +- .../fixup/test_system_rename_data_disk.py | 1 + tests/resolution/test_check.py | 5 +- tests/resolution/test_resolution_manager.py | 1 + tests/security/test_module.py | 12 +- tests/store/test_custom_repository.py | 108 +++++++---- tests/store/test_reading_addons.py | 1 + tests/store/test_repository_git.py | 20 +- tests/store/test_store_manager.py | 100 +++++----- tests/store/test_translation_load.py | 1 + tests/store/test_validate.py | 1 + tests/test_arch.py | 1 + tests/test_auth.py | 1 + tests/test_core.py | 22 ++- tests/test_ingress.py | 1 + tests/test_main.py | 1 + tests/test_supervisor.py | 23 ++- tests/test_updater.py | 1 + tests/utils/test_check_port.py | 1 + tests/utils/test_codenotary.py | 1 + tests/utils/test_common.py | 1 + tests/utils/test_json.py | 1 + tests/utils/test_log_format.py | 1 + tests/utils/test_logging.py | 20 +- tests/utils/test_remove_folder.py | 1 + tests/utils/test_systemd_journal.py | 1 + 304 files changed, 1173 insertions(+), 617 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b59bc244f97..f963fe64b9e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.1 + rev: v0.5.7 hooks: - id: ruff args: diff --git a/pyproject.toml b/pyproject.toml index cb888684c49..ec6b7142a46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -228,7 +228,7 @@ filterwarnings = [ ] [tool.ruff] -select = [ +lint.select = [ "B002", # Python does not support the unary prefix increment "B007", # Loop control variable {name} not used within loop body "B014", # Exception handler with duplicate exception @@ -291,7 +291,7 @@ select = [ "W", # pycodestyle ] -ignore = [ +lint.ignore = [ "D202", # No blank lines allowed after function docstring "D203", # 1 blank line required before class docstring "D213", # Multi-line docstring summary should start at the second line @@ -338,16 +338,16 @@ ignore = [ "PLE0605", ] -[tool.ruff.flake8-import-conventions.extend-aliases] +[tool.ruff.lint.flake8-import-conventions.extend-aliases] voluptuous = "vol" -[tool.ruff.flake8-pytest-style] +[tool.ruff.lint.flake8-pytest-style] fixture-parentheses = false -[tool.ruff.flake8-tidy-imports.banned-api] +[tool.ruff.lint.flake8-tidy-imports.banned-api] "pytz".msg = "use zoneinfo instead" -[tool.ruff.isort] +[tool.ruff.lint.isort] force-sort-within-sections = true section-order = [ "future", @@ -361,10 +361,10 @@ known-first-party = ["supervisor", "tests"] combine-as-imports = true split-on-trailing-comma = false -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] # DBus Service Mocks must use typing and names understood by dbus-fast "tests/dbus_service_mocks/*.py" = ["F722", "F821", "N815"] -[tool.ruff.mccabe] +[tool.ruff.lint.mccabe] max-complexity = 25 diff --git a/setup.py b/setup.py index a5df554feeb..cc2dc8f8e67 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ """Home Assistant Supervisor setup.""" + from pathlib import Path import re diff --git a/supervisor/__main__.py b/supervisor/__main__.py index e5c4fbc1e93..bb3bc042cf8 100644 --- a/supervisor/__main__.py +++ b/supervisor/__main__.py @@ -1,4 +1,5 @@ """Main file for Supervisor.""" + import asyncio from concurrent.futures import ThreadPoolExecutor import logging diff --git a/supervisor/addons/addon.py b/supervisor/addons/addon.py index a8f5514cd12..dc9b92ae12c 100644 --- a/supervisor/addons/addon.py +++ b/supervisor/addons/addon.py @@ -1,4 +1,5 @@ """Init file for Supervisor add-ons.""" + import asyncio from collections.abc import Awaitable from contextlib import suppress diff --git a/supervisor/addons/build.py b/supervisor/addons/build.py index 838051f4cb5..dbf4899e7fc 100644 --- a/supervisor/addons/build.py +++ b/supervisor/addons/build.py @@ -1,4 +1,5 @@ """Supervisor add-on build environment.""" + from __future__ import annotations from functools import cached_property diff --git a/supervisor/addons/const.py b/supervisor/addons/const.py index f81488c4217..f96fd33cfa1 100644 --- a/supervisor/addons/const.py +++ b/supervisor/addons/const.py @@ -1,4 +1,5 @@ """Add-on static data.""" + from datetime import timedelta from enum import StrEnum diff --git a/supervisor/addons/data.py b/supervisor/addons/data.py index 47c7002bc3a..1419bfef6f8 100644 --- a/supervisor/addons/data.py +++ b/supervisor/addons/data.py @@ -1,4 +1,5 @@ """Init file for Supervisor add-on data.""" + from copy import deepcopy from typing import Any diff --git a/supervisor/addons/manager.py b/supervisor/addons/manager.py index 218a3818383..6e228ddfae6 100644 --- a/supervisor/addons/manager.py +++ b/supervisor/addons/manager.py @@ -1,4 +1,5 @@ """Supervisor add-on manager.""" + import asyncio from collections.abc import Awaitable from contextlib import suppress diff --git a/supervisor/addons/model.py b/supervisor/addons/model.py index ba3107bdb90..2d400c00c29 100644 --- a/supervisor/addons/model.py +++ b/supervisor/addons/model.py @@ -1,4 +1,5 @@ """Init file for Supervisor add-ons.""" + from abc import ABC, abstractmethod from collections import defaultdict from collections.abc import Awaitable, Callable diff --git a/supervisor/addons/options.py b/supervisor/addons/options.py index 5837cbb9b8c..be27ecc47fb 100644 --- a/supervisor/addons/options.py +++ b/supervisor/addons/options.py @@ -1,4 +1,5 @@ """Add-on Options / UI rendering.""" + import hashlib import logging from pathlib import Path diff --git a/supervisor/addons/utils.py b/supervisor/addons/utils.py index a68382b78ec..0c8d98f3be5 100644 --- a/supervisor/addons/utils.py +++ b/supervisor/addons/utils.py @@ -1,4 +1,5 @@ """Util add-ons functions.""" + from __future__ import annotations import asyncio diff --git a/supervisor/addons/validate.py b/supervisor/addons/validate.py index fdf5f8c0514..c096860e8bf 100644 --- a/supervisor/addons/validate.py +++ b/supervisor/addons/validate.py @@ -1,4 +1,5 @@ """Validate add-ons options schema.""" + import logging import re import secrets diff --git a/supervisor/api/audio.py b/supervisor/api/audio.py index f629c886772..6f42dd4758b 100644 --- a/supervisor/api/audio.py +++ b/supervisor/api/audio.py @@ -1,4 +1,5 @@ """Init file for Supervisor Audio RESTful API.""" + import asyncio from collections.abc import Awaitable from dataclasses import asdict diff --git a/supervisor/api/auth.py b/supervisor/api/auth.py index 43852c9fde6..cd8dfaf3d92 100644 --- a/supervisor/api/auth.py +++ b/supervisor/api/auth.py @@ -1,4 +1,5 @@ """Init file for Supervisor auth/SSO RESTful API.""" + import asyncio import logging from typing import Any diff --git a/supervisor/api/backups.py b/supervisor/api/backups.py index 288284394af..5f420326df8 100644 --- a/supervisor/api/backups.py +++ b/supervisor/api/backups.py @@ -1,4 +1,5 @@ """Backups RESTful API.""" + import asyncio from collections.abc import Callable import errno @@ -342,9 +343,9 @@ async def download(self, request): _LOGGER.info("Downloading backup %s", backup.slug) response = web.FileResponse(backup.tarfile) response.content_type = CONTENT_TYPE_TAR - response.headers[ - CONTENT_DISPOSITION - ] = f"attachment; filename={RE_SLUGIFY_NAME.sub('_', backup.name)}.tar" + response.headers[CONTENT_DISPOSITION] = ( + f"attachment; filename={RE_SLUGIFY_NAME.sub('_', backup.name)}.tar" + ) return response @api_process diff --git a/supervisor/api/cli.py b/supervisor/api/cli.py index ebaf287d73d..cd3a0e418d8 100644 --- a/supervisor/api/cli.py +++ b/supervisor/api/cli.py @@ -1,4 +1,5 @@ """Init file for Supervisor HA cli RESTful API.""" + import asyncio import logging from typing import Any diff --git a/supervisor/api/discovery.py b/supervisor/api/discovery.py index 5069839130d..26cbc9bd68c 100644 --- a/supervisor/api/discovery.py +++ b/supervisor/api/discovery.py @@ -1,4 +1,5 @@ """Init file for Supervisor network RESTful API.""" + import logging import voluptuous as vol diff --git a/supervisor/api/dns.py b/supervisor/api/dns.py index b97df30e243..4aa99022884 100644 --- a/supervisor/api/dns.py +++ b/supervisor/api/dns.py @@ -1,4 +1,5 @@ """Init file for Supervisor DNS RESTful API.""" + import asyncio from collections.abc import Awaitable import logging diff --git a/supervisor/api/docker.py b/supervisor/api/docker.py index a696c8e9540..642ad1e468b 100644 --- a/supervisor/api/docker.py +++ b/supervisor/api/docker.py @@ -1,4 +1,5 @@ """Init file for Supervisor Home Assistant RESTful API.""" + import logging from typing import Any diff --git a/supervisor/api/hardware.py b/supervisor/api/hardware.py index d87da136783..0a416034052 100644 --- a/supervisor/api/hardware.py +++ b/supervisor/api/hardware.py @@ -1,4 +1,5 @@ """Init file for Supervisor hardware RESTful API.""" + import logging from typing import Any diff --git a/supervisor/api/ingress.py b/supervisor/api/ingress.py index 8ef2a8d5526..d9574ace37a 100644 --- a/supervisor/api/ingress.py +++ b/supervisor/api/ingress.py @@ -1,4 +1,5 @@ """Supervisor Add-on ingress service.""" + import asyncio from ipaddress import ip_address import logging diff --git a/supervisor/api/jobs.py b/supervisor/api/jobs.py index c87b3ad8574..0b95397515d 100644 --- a/supervisor/api/jobs.py +++ b/supervisor/api/jobs.py @@ -1,4 +1,5 @@ """Init file for Supervisor Jobs RESTful API.""" + import logging from typing import Any diff --git a/supervisor/api/multicast.py b/supervisor/api/multicast.py index 0742dea1a42..4e25d51ea46 100644 --- a/supervisor/api/multicast.py +++ b/supervisor/api/multicast.py @@ -1,4 +1,5 @@ """Init file for Supervisor Multicast RESTful API.""" + import asyncio from collections.abc import Awaitable import logging diff --git a/supervisor/api/network.py b/supervisor/api/network.py index fa0a56fe59a..b3c903f4a9f 100644 --- a/supervisor/api/network.py +++ b/supervisor/api/network.py @@ -1,4 +1,5 @@ """REST API for network.""" + import asyncio from collections.abc import Awaitable from dataclasses import replace diff --git a/supervisor/api/observer.py b/supervisor/api/observer.py index c350098be10..4064f1f248b 100644 --- a/supervisor/api/observer.py +++ b/supervisor/api/observer.py @@ -1,4 +1,5 @@ """Init file for Supervisor Observer RESTful API.""" + import asyncio import logging from typing import Any diff --git a/supervisor/api/os.py b/supervisor/api/os.py index 49908638e78..28a589cbb21 100644 --- a/supervisor/api/os.py +++ b/supervisor/api/os.py @@ -1,4 +1,5 @@ """Init file for Supervisor HassOS RESTful API.""" + import asyncio from collections.abc import Awaitable import logging diff --git a/supervisor/api/proxy.py b/supervisor/api/proxy.py index 9550b8debc2..3e63c333d12 100644 --- a/supervisor/api/proxy.py +++ b/supervisor/api/proxy.py @@ -1,4 +1,5 @@ """Utils for Home Assistant Proxy.""" + import asyncio from contextlib import asynccontextmanager import logging diff --git a/supervisor/api/resolution.py b/supervisor/api/resolution.py index 72efd69973c..8968b44c796 100644 --- a/supervisor/api/resolution.py +++ b/supervisor/api/resolution.py @@ -1,4 +1,5 @@ """Handle REST API for resoulution.""" + import asyncio from collections.abc import Awaitable from typing import Any diff --git a/supervisor/api/root.py b/supervisor/api/root.py index 35594a0dda6..6c74d7bdcba 100644 --- a/supervisor/api/root.py +++ b/supervisor/api/root.py @@ -1,4 +1,5 @@ """Init file for Supervisor Root RESTful API.""" + import asyncio import logging from typing import Any diff --git a/supervisor/api/security.py b/supervisor/api/security.py index ec7bebc25d7..d0e416aa866 100644 --- a/supervisor/api/security.py +++ b/supervisor/api/security.py @@ -1,4 +1,5 @@ """Init file for Supervisor Security RESTful API.""" + import asyncio import logging from typing import Any diff --git a/supervisor/api/store.py b/supervisor/api/store.py index 14897452bb6..4dc4e2747bf 100644 --- a/supervisor/api/store.py +++ b/supervisor/api/store.py @@ -1,4 +1,5 @@ """Init file for Supervisor Home Assistant RESTful API.""" + import asyncio from collections.abc import Awaitable from typing import Any diff --git a/supervisor/api/supervisor.py b/supervisor/api/supervisor.py index 26232506db6..bbe5f91840c 100644 --- a/supervisor/api/supervisor.py +++ b/supervisor/api/supervisor.py @@ -1,4 +1,5 @@ """Init file for Supervisor Supervisor RESTful API.""" + import asyncio from collections.abc import Awaitable import logging diff --git a/supervisor/api/utils.py b/supervisor/api/utils.py index b4218aa1c2b..4bfe4af3e5c 100644 --- a/supervisor/api/utils.py +++ b/supervisor/api/utils.py @@ -1,4 +1,5 @@ """Init file for Supervisor util for RESTful API.""" + import json from typing import Any diff --git a/supervisor/arch.py b/supervisor/arch.py index e1a17611713..b36e7e84fdf 100644 --- a/supervisor/arch.py +++ b/supervisor/arch.py @@ -1,4 +1,5 @@ """Handle Arch for underlay maschine/platforms.""" + import logging from pathlib import Path import platform diff --git a/supervisor/auth.py b/supervisor/auth.py index d1b511e15bf..d6cc447f849 100644 --- a/supervisor/auth.py +++ b/supervisor/auth.py @@ -1,4 +1,5 @@ """Manage SSO for Add-ons with Home Assistant user.""" + import asyncio import hashlib import logging diff --git a/supervisor/backups/backup.py b/supervisor/backups/backup.py index b43f0167245..e8489bd6b3a 100644 --- a/supervisor/backups/backup.py +++ b/supervisor/backups/backup.py @@ -1,4 +1,5 @@ """Representation of a backup file.""" + import asyncio from base64 import b64decode, b64encode from collections import defaultdict diff --git a/supervisor/backups/const.py b/supervisor/backups/const.py index 085b212e2c4..b0cd5c2ad17 100644 --- a/supervisor/backups/const.py +++ b/supervisor/backups/const.py @@ -1,4 +1,5 @@ """Backup consts.""" + from enum import StrEnum BUF_SIZE = 2**20 * 4 # 4MB diff --git a/supervisor/backups/utils.py b/supervisor/backups/utils.py index 6220a501fa8..faf591ba937 100644 --- a/supervisor/backups/utils.py +++ b/supervisor/backups/utils.py @@ -1,4 +1,5 @@ """Util add-on functions.""" + import hashlib import re diff --git a/supervisor/backups/validate.py b/supervisor/backups/validate.py index 701002cfc51..78d09760383 100644 --- a/supervisor/backups/validate.py +++ b/supervisor/backups/validate.py @@ -1,4 +1,5 @@ """Validate some things around restore.""" + from __future__ import annotations from typing import Any diff --git a/supervisor/bootstrap.py b/supervisor/bootstrap.py index 5e3dd2981a0..9f17128ff89 100644 --- a/supervisor/bootstrap.py +++ b/supervisor/bootstrap.py @@ -1,4 +1,6 @@ """Bootstrap Supervisor.""" + +# ruff: noqa: T100 import logging import os from pathlib import Path diff --git a/supervisor/bus.py b/supervisor/bus.py index 897738317d2..7f73bde897f 100644 --- a/supervisor/bus.py +++ b/supervisor/bus.py @@ -1,4 +1,5 @@ """Bus event system.""" + from __future__ import annotations from collections.abc import Awaitable, Callable diff --git a/supervisor/config.py b/supervisor/config.py index 09cca0064e6..53bbcbd0154 100644 --- a/supervisor/config.py +++ b/supervisor/config.py @@ -1,4 +1,5 @@ """Bootstrap Supervisor.""" + from datetime import UTC, datetime import logging import os diff --git a/supervisor/const.py b/supervisor/const.py index 0c8b6542a07..b1181af2af8 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -1,4 +1,5 @@ """Constants file for Supervisor.""" + from dataclasses import dataclass from enum import StrEnum from ipaddress import ip_network diff --git a/supervisor/core.py b/supervisor/core.py index 9f3b9bb61ae..0247435f425 100644 --- a/supervisor/core.py +++ b/supervisor/core.py @@ -1,4 +1,5 @@ """Main file for Supervisor.""" + import asyncio from collections.abc import Awaitable from contextlib import suppress diff --git a/supervisor/coresys.py b/supervisor/coresys.py index edac61f42e1..bc95df9cbb1 100644 --- a/supervisor/coresys.py +++ b/supervisor/coresys.py @@ -1,4 +1,5 @@ """Handle core shared data.""" + from __future__ import annotations import asyncio diff --git a/supervisor/dbus/agent/__init__.py b/supervisor/dbus/agent/__init__.py index 4da0223c7d7..57bcf0d342b 100644 --- a/supervisor/dbus/agent/__init__.py +++ b/supervisor/dbus/agent/__init__.py @@ -1,4 +1,5 @@ """OS-Agent implementation for DBUS.""" + import asyncio from collections.abc import Awaitable import logging diff --git a/supervisor/dbus/agent/apparmor.py b/supervisor/dbus/agent/apparmor.py index 66a66c6f0b8..ffeafddf949 100644 --- a/supervisor/dbus/agent/apparmor.py +++ b/supervisor/dbus/agent/apparmor.py @@ -1,4 +1,5 @@ """AppArmor object for OS-Agent.""" + from pathlib import Path from awesomeversion import AwesomeVersion diff --git a/supervisor/dbus/agent/boards/__init__.py b/supervisor/dbus/agent/boards/__init__.py index a71b88ce889..c05a6d3f43d 100644 --- a/supervisor/dbus/agent/boards/__init__.py +++ b/supervisor/dbus/agent/boards/__init__.py @@ -1,4 +1,5 @@ """Board management for OS Agent.""" + import logging from dbus_fast.aio.message_bus import MessageBus diff --git a/supervisor/dbus/agent/datadisk.py b/supervisor/dbus/agent/datadisk.py index 2debc786512..a6d679cc68c 100644 --- a/supervisor/dbus/agent/datadisk.py +++ b/supervisor/dbus/agent/datadisk.py @@ -1,4 +1,5 @@ """DataDisk object for OS-Agent.""" + from pathlib import Path from ..const import ( diff --git a/supervisor/dbus/const.py b/supervisor/dbus/const.py index 9246793a71a..82c75d8f3d3 100644 --- a/supervisor/dbus/const.py +++ b/supervisor/dbus/const.py @@ -1,4 +1,5 @@ """Constants for DBUS.""" + from enum import IntEnum, StrEnum from socket import AF_INET, AF_INET6 diff --git a/supervisor/dbus/hostname.py b/supervisor/dbus/hostname.py index 8327df63ad7..2f13fa15715 100644 --- a/supervisor/dbus/hostname.py +++ b/supervisor/dbus/hostname.py @@ -1,4 +1,5 @@ """D-Bus interface for hostname.""" + import logging from dbus_fast.aio.message_bus import MessageBus diff --git a/supervisor/dbus/interface.py b/supervisor/dbus/interface.py index c683abc660c..2b46882aab9 100644 --- a/supervisor/dbus/interface.py +++ b/supervisor/dbus/interface.py @@ -1,4 +1,5 @@ """Interface class for D-Bus wrappers.""" + from abc import ABC from collections.abc import Callable from functools import wraps diff --git a/supervisor/dbus/logind.py b/supervisor/dbus/logind.py index 52c12fbbbce..c50b38f15ca 100644 --- a/supervisor/dbus/logind.py +++ b/supervisor/dbus/logind.py @@ -1,4 +1,5 @@ """Interface to Logind over D-Bus.""" + import logging from dbus_fast.aio.message_bus import MessageBus diff --git a/supervisor/dbus/manager.py b/supervisor/dbus/manager.py index 0cd3cf779ae..d2397063b50 100644 --- a/supervisor/dbus/manager.py +++ b/supervisor/dbus/manager.py @@ -1,4 +1,5 @@ """D-Bus interface objects.""" + import asyncio import logging diff --git a/supervisor/dbus/network/__init__.py b/supervisor/dbus/network/__init__.py index 08a535a5103..741aceb0fc8 100644 --- a/supervisor/dbus/network/__init__.py +++ b/supervisor/dbus/network/__init__.py @@ -1,4 +1,5 @@ """Network Manager implementation for DBUS.""" + import logging from typing import Any diff --git a/supervisor/dbus/network/configuration.py b/supervisor/dbus/network/configuration.py index 867ae5a64e1..c598a726d03 100644 --- a/supervisor/dbus/network/configuration.py +++ b/supervisor/dbus/network/configuration.py @@ -1,4 +1,5 @@ """NetworkConnection objects for Network Manager.""" + from dataclasses import dataclass from ipaddress import IPv4Address, IPv6Address diff --git a/supervisor/dbus/network/dns.py b/supervisor/dbus/network/dns.py index 82ae3583eba..2b776bd104d 100644 --- a/supervisor/dbus/network/dns.py +++ b/supervisor/dbus/network/dns.py @@ -1,4 +1,5 @@ """Network Manager DNS Manager object.""" + from ipaddress import ip_address import logging from typing import Any diff --git a/supervisor/dbus/network/setting/__init__.py b/supervisor/dbus/network/setting/__init__.py index 2b065c09340..80758988d6b 100644 --- a/supervisor/dbus/network/setting/__init__.py +++ b/supervisor/dbus/network/setting/__init__.py @@ -1,4 +1,5 @@ """Connection object for Network Manager.""" + import logging from typing import Any diff --git a/supervisor/dbus/network/setting/generate.py b/supervisor/dbus/network/setting/generate.py index 44817cc87b0..c25fea29f54 100644 --- a/supervisor/dbus/network/setting/generate.py +++ b/supervisor/dbus/network/setting/generate.py @@ -1,4 +1,5 @@ """Payload generators for DBUS communication.""" + from __future__ import annotations import socket diff --git a/supervisor/dbus/network/settings.py b/supervisor/dbus/network/settings.py index d3402e0a288..48b0805144c 100644 --- a/supervisor/dbus/network/settings.py +++ b/supervisor/dbus/network/settings.py @@ -1,4 +1,5 @@ """Network Manager implementation for DBUS.""" + import logging from typing import Any diff --git a/supervisor/dbus/network/wireless.py b/supervisor/dbus/network/wireless.py index 8d314141728..711aa268854 100644 --- a/supervisor/dbus/network/wireless.py +++ b/supervisor/dbus/network/wireless.py @@ -1,4 +1,5 @@ """Wireless object for Network Manager.""" + import asyncio import logging from typing import Any diff --git a/supervisor/dbus/resolved.py b/supervisor/dbus/resolved.py index fdca304c007..4ac66a3b307 100644 --- a/supervisor/dbus/resolved.py +++ b/supervisor/dbus/resolved.py @@ -1,4 +1,5 @@ """D-Bus interface for systemd-resolved.""" + from __future__ import annotations import logging diff --git a/supervisor/dbus/timedate.py b/supervisor/dbus/timedate.py index 731bd56c118..44c662453f6 100644 --- a/supervisor/dbus/timedate.py +++ b/supervisor/dbus/timedate.py @@ -1,4 +1,5 @@ """Interface to systemd-timedate over D-Bus.""" + from datetime import datetime import logging diff --git a/supervisor/dbus/udisks2/__init__.py b/supervisor/dbus/udisks2/__init__.py index a02621e6267..076e159d8c6 100644 --- a/supervisor/dbus/udisks2/__init__.py +++ b/supervisor/dbus/udisks2/__init__.py @@ -1,4 +1,5 @@ """Interface to UDisks2 over D-Bus.""" + import asyncio import logging from typing import Any diff --git a/supervisor/dbus/udisks2/block.py b/supervisor/dbus/udisks2/block.py index c8d710248f1..77a68fd270a 100644 --- a/supervisor/dbus/udisks2/block.py +++ b/supervisor/dbus/udisks2/block.py @@ -1,4 +1,5 @@ """Interface to UDisks2 Block Device over D-Bus.""" + import asyncio from collections.abc import Callable from pathlib import Path diff --git a/supervisor/discovery/__init__.py b/supervisor/discovery/__init__.py index 04f5eb86226..f1468a98bb4 100644 --- a/supervisor/discovery/__init__.py +++ b/supervisor/discovery/__init__.py @@ -1,4 +1,5 @@ """Handle discover message for Home Assistant.""" + from __future__ import annotations from contextlib import suppress diff --git a/supervisor/docker/addon.py b/supervisor/docker/addon.py index 950c629661e..b02659cd5ff 100644 --- a/supervisor/docker/addon.py +++ b/supervisor/docker/addon.py @@ -1,4 +1,5 @@ """Init file for Supervisor add-on Docker object.""" + from __future__ import annotations from collections.abc import Awaitable diff --git a/supervisor/docker/audio.py b/supervisor/docker/audio.py index 003f8f6b0bb..4fe02274781 100644 --- a/supervisor/docker/audio.py +++ b/supervisor/docker/audio.py @@ -1,4 +1,5 @@ """Audio docker object.""" + import logging import docker diff --git a/supervisor/docker/cli.py b/supervisor/docker/cli.py index ca0eec0865d..e259ac19a34 100644 --- a/supervisor/docker/cli.py +++ b/supervisor/docker/cli.py @@ -1,4 +1,5 @@ """HA Cli docker object.""" + import logging from ..coresys import CoreSysAttributes diff --git a/supervisor/docker/const.py b/supervisor/docker/const.py index cb9a34e4f83..edd491e2cb4 100644 --- a/supervisor/docker/const.py +++ b/supervisor/docker/const.py @@ -1,4 +1,5 @@ """Docker constants.""" + from enum import StrEnum from docker.types import Mount diff --git a/supervisor/docker/dns.py b/supervisor/docker/dns.py index b357951ca03..00ce4260935 100644 --- a/supervisor/docker/dns.py +++ b/supervisor/docker/dns.py @@ -1,4 +1,5 @@ """DNS docker object.""" + import logging from docker.types import Mount diff --git a/supervisor/docker/homeassistant.py b/supervisor/docker/homeassistant.py index fcc3efcef66..ecc4981b390 100644 --- a/supervisor/docker/homeassistant.py +++ b/supervisor/docker/homeassistant.py @@ -1,4 +1,5 @@ """Init file for Supervisor Docker object.""" + from collections.abc import Awaitable from ipaddress import IPv4Address import logging diff --git a/supervisor/docker/interface.py b/supervisor/docker/interface.py index 8ccf8c34686..409ef207e55 100644 --- a/supervisor/docker/interface.py +++ b/supervisor/docker/interface.py @@ -1,4 +1,5 @@ """Interface class for Supervisor Docker object.""" + from __future__ import annotations from collections import defaultdict diff --git a/supervisor/docker/manager.py b/supervisor/docker/manager.py index faec8899347..54662d5b657 100644 --- a/supervisor/docker/manager.py +++ b/supervisor/docker/manager.py @@ -1,4 +1,5 @@ """Manager for Supervisor Docker.""" + from contextlib import suppress from ipaddress import IPv4Address import logging diff --git a/supervisor/docker/multicast.py b/supervisor/docker/multicast.py index 1439cd40c28..9935f7ee388 100644 --- a/supervisor/docker/multicast.py +++ b/supervisor/docker/multicast.py @@ -1,4 +1,5 @@ """HA Cli docker object.""" + import logging from ..coresys import CoreSysAttributes diff --git a/supervisor/docker/network.py b/supervisor/docker/network.py index b0b701b6c1e..f83b4b5f15f 100644 --- a/supervisor/docker/network.py +++ b/supervisor/docker/network.py @@ -1,4 +1,5 @@ """Internal network manager for Supervisor.""" + from contextlib import suppress from ipaddress import IPv4Address import logging diff --git a/supervisor/docker/observer.py b/supervisor/docker/observer.py index 67ec4d02959..65c7e3095fe 100644 --- a/supervisor/docker/observer.py +++ b/supervisor/docker/observer.py @@ -1,4 +1,5 @@ """Observer docker object.""" + import logging from ..const import DOCKER_NETWORK_MASK diff --git a/supervisor/docker/stats.py b/supervisor/docker/stats.py index b82aecea2d0..ffdf6f0a365 100644 --- a/supervisor/docker/stats.py +++ b/supervisor/docker/stats.py @@ -1,4 +1,5 @@ """Calc and represent docker stats data.""" + from contextlib import suppress diff --git a/supervisor/docker/supervisor.py b/supervisor/docker/supervisor.py index b347f73d83d..e5540a24694 100644 --- a/supervisor/docker/supervisor.py +++ b/supervisor/docker/supervisor.py @@ -1,4 +1,5 @@ """Init file for Supervisor Docker object.""" + from collections.abc import Awaitable from ipaddress import IPv4Address import logging diff --git a/supervisor/hardware/const.py b/supervisor/hardware/const.py index 8dd72db4be1..d158fb289ed 100644 --- a/supervisor/hardware/const.py +++ b/supervisor/hardware/const.py @@ -1,4 +1,5 @@ """Constants for hardware.""" + from enum import StrEnum diff --git a/supervisor/hardware/data.py b/supervisor/hardware/data.py index d5ca51d3455..4844709af48 100644 --- a/supervisor/hardware/data.py +++ b/supervisor/hardware/data.py @@ -1,4 +1,5 @@ """Data representation of Hardware.""" + from __future__ import annotations from pathlib import Path diff --git a/supervisor/hardware/disk.py b/supervisor/hardware/disk.py index 67ab696ff4d..649a63e3733 100644 --- a/supervisor/hardware/disk.py +++ b/supervisor/hardware/disk.py @@ -1,4 +1,5 @@ """Read disk hardware info from system.""" + import logging from pathlib import Path import shutil diff --git a/supervisor/hardware/helper.py b/supervisor/hardware/helper.py index 8d499fb8cc7..bc1d539d1d8 100644 --- a/supervisor/hardware/helper.py +++ b/supervisor/hardware/helper.py @@ -1,4 +1,5 @@ """Read hardware info from system.""" + from datetime import UTC, datetime import logging from pathlib import Path diff --git a/supervisor/hardware/manager.py b/supervisor/hardware/manager.py index 6c154d45e3d..d169577cef2 100644 --- a/supervisor/hardware/manager.py +++ b/supervisor/hardware/manager.py @@ -1,4 +1,5 @@ """Hardware Manager of Supervisor.""" + import logging from pathlib import Path diff --git a/supervisor/hardware/monitor.py b/supervisor/hardware/monitor.py index fcc7da6e303..0aa6fdcd643 100644 --- a/supervisor/hardware/monitor.py +++ b/supervisor/hardware/monitor.py @@ -1,4 +1,5 @@ """Supervisor Hardware monitor based on udev.""" + import asyncio import logging from pathlib import Path diff --git a/supervisor/hardware/policy.py b/supervisor/hardware/policy.py index 45042e7da84..6ded5e9ce3c 100644 --- a/supervisor/hardware/policy.py +++ b/supervisor/hardware/policy.py @@ -1,4 +1,5 @@ """Policy / cgroups management of local host.""" + import logging from ..coresys import CoreSys, CoreSysAttributes diff --git a/supervisor/homeassistant/api.py b/supervisor/homeassistant/api.py index b748df562d7..26a30416e7b 100644 --- a/supervisor/homeassistant/api.py +++ b/supervisor/homeassistant/api.py @@ -1,4 +1,5 @@ """Home Assistant control object.""" + import asyncio from contextlib import AbstractAsyncContextManager, asynccontextmanager, suppress from dataclasses import dataclass diff --git a/supervisor/homeassistant/const.py b/supervisor/homeassistant/const.py index 9a8419be01f..19243354742 100644 --- a/supervisor/homeassistant/const.py +++ b/supervisor/homeassistant/const.py @@ -1,4 +1,5 @@ """Constants for homeassistant.""" + from datetime import timedelta from enum import StrEnum from pathlib import PurePath diff --git a/supervisor/homeassistant/core.py b/supervisor/homeassistant/core.py index c24d8e77b38..911a1f84423 100644 --- a/supervisor/homeassistant/core.py +++ b/supervisor/homeassistant/core.py @@ -1,4 +1,5 @@ """Home Assistant control object.""" + import asyncio from collections.abc import Awaitable from contextlib import suppress diff --git a/supervisor/homeassistant/secrets.py b/supervisor/homeassistant/secrets.py index c6730b5da47..eda6cb7c773 100644 --- a/supervisor/homeassistant/secrets.py +++ b/supervisor/homeassistant/secrets.py @@ -1,4 +1,5 @@ """Handle Home Assistant secrets to add-ons.""" + from datetime import timedelta import logging from pathlib import Path diff --git a/supervisor/homeassistant/validate.py b/supervisor/homeassistant/validate.py index 01f3093c81e..1c8267d4710 100644 --- a/supervisor/homeassistant/validate.py +++ b/supervisor/homeassistant/validate.py @@ -1,4 +1,5 @@ """Validate functions.""" + import uuid import voluptuous as vol diff --git a/supervisor/homeassistant/websocket.py b/supervisor/homeassistant/websocket.py index cc7572e1991..2c54eda64db 100644 --- a/supervisor/homeassistant/websocket.py +++ b/supervisor/homeassistant/websocket.py @@ -1,4 +1,5 @@ """Home Assistant Websocket API.""" + from __future__ import annotations import asyncio diff --git a/supervisor/host/apparmor.py b/supervisor/host/apparmor.py index 51488a0980b..c867a2e177f 100644 --- a/supervisor/host/apparmor.py +++ b/supervisor/host/apparmor.py @@ -1,4 +1,5 @@ """AppArmor control for host.""" + from __future__ import annotations from contextlib import suppress diff --git a/supervisor/host/const.py b/supervisor/host/const.py index ea70325ef5b..9c3a9dc4ada 100644 --- a/supervisor/host/const.py +++ b/supervisor/host/const.py @@ -1,4 +1,5 @@ """Const for host.""" + from enum import StrEnum PARAM_BOOT_ID = "_BOOT_ID" diff --git a/supervisor/host/control.py b/supervisor/host/control.py index 9e92916bf6f..1a8790fcd09 100644 --- a/supervisor/host/control.py +++ b/supervisor/host/control.py @@ -1,4 +1,5 @@ """Power control for host.""" + from datetime import datetime import logging diff --git a/supervisor/host/info.py b/supervisor/host/info.py index 837be436fe7..87c7a041c38 100644 --- a/supervisor/host/info.py +++ b/supervisor/host/info.py @@ -1,4 +1,5 @@ """Info control for host.""" + import asyncio from datetime import datetime import logging diff --git a/supervisor/host/logs.py b/supervisor/host/logs.py index 0e0ef505932..f616749d508 100644 --- a/supervisor/host/logs.py +++ b/supervisor/host/logs.py @@ -1,4 +1,5 @@ """Logs control for host.""" + from __future__ import annotations from contextlib import asynccontextmanager diff --git a/supervisor/host/manager.py b/supervisor/host/manager.py index 51680405e66..e926c5ad301 100644 --- a/supervisor/host/manager.py +++ b/supervisor/host/manager.py @@ -1,4 +1,5 @@ """Host function like audio, D-Bus or systemd.""" + from contextlib import suppress from functools import lru_cache import logging diff --git a/supervisor/host/network.py b/supervisor/host/network.py index 981bd9f3138..f9fd00f959f 100644 --- a/supervisor/host/network.py +++ b/supervisor/host/network.py @@ -1,4 +1,5 @@ """Info control for host.""" + import asyncio from contextlib import suppress import logging diff --git a/supervisor/host/services.py b/supervisor/host/services.py index 2bb7583a617..0dceffaf09b 100644 --- a/supervisor/host/services.py +++ b/supervisor/host/services.py @@ -1,4 +1,5 @@ """Service control for host.""" + from collections.abc import Awaitable import logging diff --git a/supervisor/host/sound.py b/supervisor/host/sound.py index 4b5530a57e1..39583c22cbe 100644 --- a/supervisor/host/sound.py +++ b/supervisor/host/sound.py @@ -1,4 +1,5 @@ """Pulse host control.""" + from dataclasses import dataclass, field from datetime import timedelta from enum import StrEnum diff --git a/supervisor/ingress.py b/supervisor/ingress.py index d0e15ff9570..422c8f47c71 100644 --- a/supervisor/ingress.py +++ b/supervisor/ingress.py @@ -1,4 +1,5 @@ """Fetch last versions from webserver.""" + from datetime import timedelta import logging import random diff --git a/supervisor/jobs/const.py b/supervisor/jobs/const.py index 221b5972edb..f7b39891016 100644 --- a/supervisor/jobs/const.py +++ b/supervisor/jobs/const.py @@ -1,4 +1,5 @@ """Jobs constants.""" + from enum import StrEnum from pathlib import Path diff --git a/supervisor/jobs/decorator.py b/supervisor/jobs/decorator.py index 63eb5670b76..5f8934b2193 100644 --- a/supervisor/jobs/decorator.py +++ b/supervisor/jobs/decorator.py @@ -1,4 +1,5 @@ """Job decorator.""" + import asyncio from collections.abc import Callable from contextlib import suppress diff --git a/supervisor/misc/filter.py b/supervisor/misc/filter.py index 14ff3fe4082..cf04e06d198 100644 --- a/supervisor/misc/filter.py +++ b/supervisor/misc/filter.py @@ -1,4 +1,5 @@ """Filter tools.""" + import os import re diff --git a/supervisor/misc/scheduler.py b/supervisor/misc/scheduler.py index 8e34da2af48..b4cd49a5a48 100644 --- a/supervisor/misc/scheduler.py +++ b/supervisor/misc/scheduler.py @@ -1,4 +1,5 @@ """Schedule for Supervisor.""" + import asyncio from collections.abc import Awaitable, Callable from datetime import date, datetime, time, timedelta diff --git a/supervisor/misc/tasks.py b/supervisor/misc/tasks.py index 685f2bcb72e..56e29f7902b 100644 --- a/supervisor/misc/tasks.py +++ b/supervisor/misc/tasks.py @@ -1,4 +1,5 @@ """A collection of tasks.""" + import asyncio from collections.abc import Awaitable from datetime import timedelta diff --git a/supervisor/plugins/base.py b/supervisor/plugins/base.py index ff3028d55bf..afe2afefe8b 100644 --- a/supervisor/plugins/base.py +++ b/supervisor/plugins/base.py @@ -1,4 +1,5 @@ """Supervisor plugins base class.""" + from abc import ABC, abstractmethod import asyncio from collections.abc import Awaitable diff --git a/supervisor/plugins/const.py b/supervisor/plugins/const.py index 8b3bdaf5792..94701d03b1c 100644 --- a/supervisor/plugins/const.py +++ b/supervisor/plugins/const.py @@ -1,4 +1,5 @@ """Const for plugins.""" + from datetime import timedelta from pathlib import Path diff --git a/supervisor/plugins/manager.py b/supervisor/plugins/manager.py index 494cd4997d5..a18cbd8727b 100644 --- a/supervisor/plugins/manager.py +++ b/supervisor/plugins/manager.py @@ -1,4 +1,5 @@ """Plugin for Supervisor backend.""" + import asyncio import logging diff --git a/supervisor/resolution/check.py b/supervisor/resolution/check.py index c9f5e7f6007..14594168667 100644 --- a/supervisor/resolution/check.py +++ b/supervisor/resolution/check.py @@ -1,4 +1,5 @@ """Helpers to checks the system.""" + from importlib import import_module import logging from typing import Any diff --git a/supervisor/resolution/checks/addon_pwned.py b/supervisor/resolution/checks/addon_pwned.py index b9a7c5a054c..f5f76578ef5 100644 --- a/supervisor/resolution/checks/addon_pwned.py +++ b/supervisor/resolution/checks/addon_pwned.py @@ -1,4 +1,5 @@ """Helpers to check core security.""" + from datetime import timedelta import logging diff --git a/supervisor/resolution/checks/backups.py b/supervisor/resolution/checks/backups.py index 2c082600f8f..99c9e767351 100644 --- a/supervisor/resolution/checks/backups.py +++ b/supervisor/resolution/checks/backups.py @@ -1,4 +1,5 @@ """Helpers to check if backed up.""" + from ...backups.const import BackupType from ...const import CoreState from ...coresys import CoreSys diff --git a/supervisor/resolution/checks/base.py b/supervisor/resolution/checks/base.py index 203e75a72c7..1b81b4539d3 100644 --- a/supervisor/resolution/checks/base.py +++ b/supervisor/resolution/checks/base.py @@ -1,4 +1,5 @@ """Baseclass for system checks.""" + from abc import ABC, abstractmethod import logging diff --git a/supervisor/resolution/checks/core_security.py b/supervisor/resolution/checks/core_security.py index 7922f38ee53..5114617eb2e 100644 --- a/supervisor/resolution/checks/core_security.py +++ b/supervisor/resolution/checks/core_security.py @@ -1,4 +1,5 @@ """Helpers to check core security.""" + from enum import StrEnum from pathlib import Path diff --git a/supervisor/resolution/checks/dns_server.py b/supervisor/resolution/checks/dns_server.py index f74643197c7..792b89bf40a 100644 --- a/supervisor/resolution/checks/dns_server.py +++ b/supervisor/resolution/checks/dns_server.py @@ -1,4 +1,5 @@ """Helpers to check DNS servers for failure.""" + import asyncio from datetime import timedelta diff --git a/supervisor/resolution/checks/dns_server_ipv6.py b/supervisor/resolution/checks/dns_server_ipv6.py index 8ece866bc32..ae589b40f79 100644 --- a/supervisor/resolution/checks/dns_server_ipv6.py +++ b/supervisor/resolution/checks/dns_server_ipv6.py @@ -1,4 +1,5 @@ """Helpers to check DNS servers for IPv6 errors.""" + import asyncio from datetime import timedelta diff --git a/supervisor/resolution/checks/free_space.py b/supervisor/resolution/checks/free_space.py index 94b3f7dfbe8..6fb6343d785 100644 --- a/supervisor/resolution/checks/free_space.py +++ b/supervisor/resolution/checks/free_space.py @@ -1,4 +1,5 @@ """Helpers to check and fix issues with free space.""" + from ...backups.const import BackupType from ...const import CoreState from ...coresys import CoreSys diff --git a/supervisor/resolution/checks/network_interface_ipv4.py b/supervisor/resolution/checks/network_interface_ipv4.py index 7196535c9c9..daa01b8105e 100644 --- a/supervisor/resolution/checks/network_interface_ipv4.py +++ b/supervisor/resolution/checks/network_interface_ipv4.py @@ -1,4 +1,5 @@ """Helpers to check core security.""" + from ...const import CoreState from ...coresys import CoreSys from ...dbus.const import ConnectionStateFlags, ConnectionStateType diff --git a/supervisor/resolution/checks/supervisor_trust.py b/supervisor/resolution/checks/supervisor_trust.py index f7e204c6158..f779be0380f 100644 --- a/supervisor/resolution/checks/supervisor_trust.py +++ b/supervisor/resolution/checks/supervisor_trust.py @@ -1,4 +1,5 @@ """Helpers to check supervisor trust.""" + import logging from ...const import CoreState diff --git a/supervisor/resolution/const.py b/supervisor/resolution/const.py index b7055a97485..face2e72f27 100644 --- a/supervisor/resolution/const.py +++ b/supervisor/resolution/const.py @@ -1,4 +1,5 @@ """Constants for the resoulution manager.""" + from enum import StrEnum from pathlib import Path diff --git a/supervisor/resolution/data.py b/supervisor/resolution/data.py index 9eef1b8b22c..fc92bb7e80c 100644 --- a/supervisor/resolution/data.py +++ b/supervisor/resolution/data.py @@ -1,4 +1,5 @@ """Data objects.""" + from uuid import UUID, uuid4 import attr diff --git a/supervisor/resolution/evaluate.py b/supervisor/resolution/evaluate.py index 8c190ce312d..0287a57b4af 100644 --- a/supervisor/resolution/evaluate.py +++ b/supervisor/resolution/evaluate.py @@ -1,4 +1,5 @@ """Helpers to evaluate the system.""" + from importlib import import_module import logging diff --git a/supervisor/resolution/evaluations/apparmor.py b/supervisor/resolution/evaluations/apparmor.py index b4ab67dfb76..41d5bc98fe5 100644 --- a/supervisor/resolution/evaluations/apparmor.py +++ b/supervisor/resolution/evaluations/apparmor.py @@ -1,4 +1,5 @@ """Evaluation class for AppArmor.""" + from pathlib import Path from ...const import CoreState diff --git a/supervisor/resolution/evaluations/base.py b/supervisor/resolution/evaluations/base.py index 19d1d91d329..89d5acbe766 100644 --- a/supervisor/resolution/evaluations/base.py +++ b/supervisor/resolution/evaluations/base.py @@ -1,4 +1,5 @@ """Baseclass for system evaluations.""" + from abc import ABC, abstractmethod import logging diff --git a/supervisor/resolution/evaluations/cgroup.py b/supervisor/resolution/evaluations/cgroup.py index 5457326a8de..186bdab37f0 100644 --- a/supervisor/resolution/evaluations/cgroup.py +++ b/supervisor/resolution/evaluations/cgroup.py @@ -1,4 +1,5 @@ """Evaluation class for CGroup version.""" + from ...const import CoreState from ...coresys import CoreSys from ..const import UnsupportedReason diff --git a/supervisor/resolution/evaluations/container.py b/supervisor/resolution/evaluations/container.py index 808bc439e3a..b4184d13b06 100644 --- a/supervisor/resolution/evaluations/container.py +++ b/supervisor/resolution/evaluations/container.py @@ -1,4 +1,5 @@ """Evaluation class for container.""" + import logging from docker.errors import DockerException diff --git a/supervisor/resolution/evaluations/docker_configuration.py b/supervisor/resolution/evaluations/docker_configuration.py index 18b996038c9..473d5b76fe3 100644 --- a/supervisor/resolution/evaluations/docker_configuration.py +++ b/supervisor/resolution/evaluations/docker_configuration.py @@ -1,4 +1,5 @@ """Evaluation class for docker configuration.""" + import logging from ...const import CoreState diff --git a/supervisor/resolution/evaluations/lxc.py b/supervisor/resolution/evaluations/lxc.py index 136220b439e..5361c76b539 100644 --- a/supervisor/resolution/evaluations/lxc.py +++ b/supervisor/resolution/evaluations/lxc.py @@ -1,4 +1,5 @@ """Evaluation class for lxc.""" + from contextlib import suppress from pathlib import Path diff --git a/supervisor/resolution/evaluations/restart_policy.py b/supervisor/resolution/evaluations/restart_policy.py index 998b48c8f0b..cf138adf408 100644 --- a/supervisor/resolution/evaluations/restart_policy.py +++ b/supervisor/resolution/evaluations/restart_policy.py @@ -1,4 +1,5 @@ """Evaluation class for restart policy.""" + from supervisor.docker.const import RestartPolicy from supervisor.docker.interface import DockerInterface diff --git a/supervisor/resolution/evaluations/source_mods.py b/supervisor/resolution/evaluations/source_mods.py index b81848955cd..ee6411ee835 100644 --- a/supervisor/resolution/evaluations/source_mods.py +++ b/supervisor/resolution/evaluations/source_mods.py @@ -1,4 +1,5 @@ """Evaluation class for Content Trust.""" + import errno import logging from pathlib import Path diff --git a/supervisor/resolution/fixup.py b/supervisor/resolution/fixup.py index da56f7d18e3..46aa4968f00 100644 --- a/supervisor/resolution/fixup.py +++ b/supervisor/resolution/fixup.py @@ -1,4 +1,5 @@ """Helpers to fixup the system.""" + from importlib import import_module import logging diff --git a/supervisor/resolution/fixups/addon_execute_remove.py b/supervisor/resolution/fixups/addon_execute_remove.py index bff58cb21e3..ce9418e5ba7 100644 --- a/supervisor/resolution/fixups/addon_execute_remove.py +++ b/supervisor/resolution/fixups/addon_execute_remove.py @@ -1,4 +1,5 @@ """Helpers to fix addon issue by removing it.""" + import logging from ...coresys import CoreSys diff --git a/supervisor/resolution/fixups/base.py b/supervisor/resolution/fixups/base.py index 87787e9ce6a..e0ef19ee4be 100644 --- a/supervisor/resolution/fixups/base.py +++ b/supervisor/resolution/fixups/base.py @@ -1,4 +1,5 @@ """Baseclass for system fixup.""" + from abc import ABC, abstractmethod import logging diff --git a/supervisor/resolution/fixups/store_execute_reload.py b/supervisor/resolution/fixups/store_execute_reload.py index 5e56bfa95ab..5e603eb7d96 100644 --- a/supervisor/resolution/fixups/store_execute_reload.py +++ b/supervisor/resolution/fixups/store_execute_reload.py @@ -1,4 +1,5 @@ """Helpers to check and fix issues with free space.""" + import logging from ...coresys import CoreSys diff --git a/supervisor/resolution/fixups/store_execute_remove.py b/supervisor/resolution/fixups/store_execute_remove.py index b83fd3b1392..40af37fb70d 100644 --- a/supervisor/resolution/fixups/store_execute_remove.py +++ b/supervisor/resolution/fixups/store_execute_remove.py @@ -1,4 +1,5 @@ """Helpers to check and fix issues with free space.""" + import logging from ...coresys import CoreSys diff --git a/supervisor/resolution/fixups/store_execute_reset.py b/supervisor/resolution/fixups/store_execute_reset.py index 048dfda7c6a..2d3b3d82675 100644 --- a/supervisor/resolution/fixups/store_execute_reset.py +++ b/supervisor/resolution/fixups/store_execute_reset.py @@ -1,4 +1,5 @@ """Helpers to check and fix issues with free space.""" + import logging from ...coresys import CoreSys diff --git a/supervisor/resolution/fixups/system_clear_full_backup.py b/supervisor/resolution/fixups/system_clear_full_backup.py index faec085ec50..3515a2a58c1 100644 --- a/supervisor/resolution/fixups/system_clear_full_backup.py +++ b/supervisor/resolution/fixups/system_clear_full_backup.py @@ -1,4 +1,5 @@ """Helpers to check and fix issues with free space.""" + import logging from ...backups.const import BackupType diff --git a/supervisor/resolution/fixups/system_create_full_backup.py b/supervisor/resolution/fixups/system_create_full_backup.py index 37aae59ab42..6d05c4ad500 100644 --- a/supervisor/resolution/fixups/system_create_full_backup.py +++ b/supervisor/resolution/fixups/system_create_full_backup.py @@ -1,4 +1,5 @@ """Helpers to check and fix issues with free space.""" + import logging from ...coresys import CoreSys diff --git a/supervisor/resolution/fixups/system_execute_integrity.py b/supervisor/resolution/fixups/system_execute_integrity.py index 13e65aeae36..58711b467d0 100644 --- a/supervisor/resolution/fixups/system_execute_integrity.py +++ b/supervisor/resolution/fixups/system_execute_integrity.py @@ -1,4 +1,5 @@ """Helpers to check and fix issues with free space.""" + from datetime import timedelta import logging diff --git a/supervisor/resolution/fixups/system_execute_reboot.py b/supervisor/resolution/fixups/system_execute_reboot.py index 98de804333a..0d27621a570 100644 --- a/supervisor/resolution/fixups/system_execute_reboot.py +++ b/supervisor/resolution/fixups/system_execute_reboot.py @@ -1,4 +1,5 @@ """Reboot host fixup.""" + import asyncio import logging diff --git a/supervisor/resolution/module.py b/supervisor/resolution/module.py index 080698a2194..945eccc68c4 100644 --- a/supervisor/resolution/module.py +++ b/supervisor/resolution/module.py @@ -1,4 +1,5 @@ """Supervisor resolution center.""" + import logging from typing import Any diff --git a/supervisor/resolution/notify.py b/supervisor/resolution/notify.py index d282a43bb23..294d29d79fb 100644 --- a/supervisor/resolution/notify.py +++ b/supervisor/resolution/notify.py @@ -3,6 +3,7 @@ This helper creates persistant notification in the Core UI. In the future we want to remove this in favour of a "center" in the UI. """ + import logging from ..coresys import CoreSys, CoreSysAttributes diff --git a/supervisor/resolution/validate.py b/supervisor/resolution/validate.py index 89b4bb0754c..e8d8d6af0c4 100644 --- a/supervisor/resolution/validate.py +++ b/supervisor/resolution/validate.py @@ -1,4 +1,5 @@ """Validate resolution configuration schema.""" + from pathlib import Path import voluptuous as vol diff --git a/supervisor/security/const.py b/supervisor/security/const.py index ee6d0a835c7..ad875e6fad3 100644 --- a/supervisor/security/const.py +++ b/supervisor/security/const.py @@ -1,4 +1,5 @@ """Security constants.""" + from enum import StrEnum import attr diff --git a/supervisor/security/module.py b/supervisor/security/module.py index f7e03d59bd1..d15be69de9e 100644 --- a/supervisor/security/module.py +++ b/supervisor/security/module.py @@ -1,4 +1,5 @@ """Fetch last versions from webserver.""" + from __future__ import annotations import logging diff --git a/supervisor/services/__init__.py b/supervisor/services/__init__.py index ea8e9d92507..492346efa1d 100644 --- a/supervisor/services/__init__.py +++ b/supervisor/services/__init__.py @@ -1,4 +1,5 @@ """Handle internal services discovery.""" + from ..coresys import CoreSys, CoreSysAttributes from .const import SERVICE_MQTT, SERVICE_MYSQL from .data import ServicesData diff --git a/supervisor/services/data.py b/supervisor/services/data.py index a16fc981631..95924a2a5e1 100644 --- a/supervisor/services/data.py +++ b/supervisor/services/data.py @@ -1,4 +1,5 @@ """Handle service data for persistent supervisor reboot.""" + from typing import Any from ..const import FILE_HASSIO_SERVICES diff --git a/supervisor/services/interface.py b/supervisor/services/interface.py index a3c1dab402d..39e12e66309 100644 --- a/supervisor/services/interface.py +++ b/supervisor/services/interface.py @@ -1,4 +1,5 @@ """Interface for single service.""" + from abc import ABC, abstractmethod from typing import Any diff --git a/supervisor/services/modules/mqtt.py b/supervisor/services/modules/mqtt.py index 00e7fd8e420..398571f249a 100644 --- a/supervisor/services/modules/mqtt.py +++ b/supervisor/services/modules/mqtt.py @@ -1,4 +1,5 @@ """Provide the MQTT Service.""" + import logging from typing import Any diff --git a/supervisor/services/modules/mysql.py b/supervisor/services/modules/mysql.py index 291189b153e..3a9f143c259 100644 --- a/supervisor/services/modules/mysql.py +++ b/supervisor/services/modules/mysql.py @@ -1,4 +1,5 @@ """Provide the MySQL Service.""" + import logging from typing import Any diff --git a/supervisor/services/validate.py b/supervisor/services/validate.py index 03b307fb26e..4af49af1046 100644 --- a/supervisor/services/validate.py +++ b/supervisor/services/validate.py @@ -1,4 +1,5 @@ """Validate services schema.""" + import voluptuous as vol from ..utils.validate import schema_or diff --git a/supervisor/store/__init__.py b/supervisor/store/__init__.py index 7c0eb115692..5b3db3eafa4 100644 --- a/supervisor/store/__init__.py +++ b/supervisor/store/__init__.py @@ -1,4 +1,5 @@ """Add-on Store handler.""" + import asyncio from collections.abc import Awaitable import logging diff --git a/supervisor/store/const.py b/supervisor/store/const.py index 81429236f1e..a472e095bb1 100644 --- a/supervisor/store/const.py +++ b/supervisor/store/const.py @@ -1,4 +1,5 @@ """Constants for the add-on store.""" + from enum import StrEnum from pathlib import Path diff --git a/supervisor/store/data.py b/supervisor/store/data.py index 1e33b923f15..885e1b20e8b 100644 --- a/supervisor/store/data.py +++ b/supervisor/store/data.py @@ -1,4 +1,5 @@ """Init file for Supervisor add-on data.""" + from dataclasses import dataclass import errno import logging diff --git a/supervisor/store/git.py b/supervisor/store/git.py index b37f773baf5..69c637814cb 100644 --- a/supervisor/store/git.py +++ b/supervisor/store/git.py @@ -1,4 +1,5 @@ """Init file for Supervisor add-on Git.""" + import asyncio import functools as ft import logging diff --git a/supervisor/store/utils.py b/supervisor/store/utils.py index 91da7880fd7..1e8f4c003e1 100644 --- a/supervisor/store/utils.py +++ b/supervisor/store/utils.py @@ -1,4 +1,5 @@ """Util add-ons functions.""" + import hashlib import logging from pathlib import Path diff --git a/supervisor/supervisor.py b/supervisor/supervisor.py index ea6708dc4a0..126cf739de8 100644 --- a/supervisor/supervisor.py +++ b/supervisor/supervisor.py @@ -1,4 +1,5 @@ """Home Assistant control object.""" + from collections.abc import Awaitable from contextlib import suppress from datetime import timedelta diff --git a/supervisor/updater.py b/supervisor/updater.py index 47571fc031e..949090ca389 100644 --- a/supervisor/updater.py +++ b/supervisor/updater.py @@ -1,4 +1,5 @@ """Fetch last versions from webserver.""" + from contextlib import suppress from datetime import timedelta import json diff --git a/supervisor/utils/__init__.py b/supervisor/utils/__init__.py index 9f83f45f78b..a0e7c85b721 100644 --- a/supervisor/utils/__init__.py +++ b/supervisor/utils/__init__.py @@ -1,4 +1,5 @@ """Tools file for Supervisor.""" + import asyncio from functools import lru_cache from ipaddress import IPv4Address diff --git a/supervisor/utils/apparmor.py b/supervisor/utils/apparmor.py index 6d655708a13..50de8fc9b1f 100644 --- a/supervisor/utils/apparmor.py +++ b/supervisor/utils/apparmor.py @@ -1,4 +1,5 @@ """Some functions around AppArmor profiles.""" + import logging from pathlib import Path import re diff --git a/supervisor/utils/codenotary.py b/supervisor/utils/codenotary.py index f8138e8b2da..927d60acd6c 100644 --- a/supervisor/utils/codenotary.py +++ b/supervisor/utils/codenotary.py @@ -1,4 +1,5 @@ """Small wrapper for CodeNotary.""" + from __future__ import annotations import asyncio diff --git a/supervisor/utils/common.py b/supervisor/utils/common.py index e37b14b39dd..bddb2b8ca3f 100644 --- a/supervisor/utils/common.py +++ b/supervisor/utils/common.py @@ -1,4 +1,5 @@ """Common utils.""" + from contextlib import suppress import logging from pathlib import Path diff --git a/supervisor/utils/dbus.py b/supervisor/utils/dbus.py index 791f12984de..0e3c0c7217f 100644 --- a/supervisor/utils/dbus.py +++ b/supervisor/utils/dbus.py @@ -1,4 +1,5 @@ """DBus implementation with glib.""" + from __future__ import annotations import asyncio diff --git a/supervisor/utils/dt.py b/supervisor/utils/dt.py index c6a0c2667e0..01895acc0ea 100644 --- a/supervisor/utils/dt.py +++ b/supervisor/utils/dt.py @@ -1,4 +1,5 @@ """Tools file for Supervisor.""" + from contextlib import suppress from datetime import UTC, datetime, timedelta, timezone, tzinfo import re diff --git a/supervisor/utils/json.py b/supervisor/utils/json.py index d9c9a30820f..d3a6b43e432 100644 --- a/supervisor/utils/json.py +++ b/supervisor/utils/json.py @@ -1,4 +1,5 @@ """Tools file for Supervisor.""" + from functools import partial import logging from pathlib import Path diff --git a/supervisor/utils/log_format.py b/supervisor/utils/log_format.py index 65b0cf1986d..c73dbe3bf4e 100644 --- a/supervisor/utils/log_format.py +++ b/supervisor/utils/log_format.py @@ -1,4 +1,5 @@ """Custom log messages.""" + import logging import re diff --git a/supervisor/utils/logging.py b/supervisor/utils/logging.py index 346160c232c..344b46e4466 100644 --- a/supervisor/utils/logging.py +++ b/supervisor/utils/logging.py @@ -1,4 +1,5 @@ """Logging utilities.""" + from __future__ import annotations import logging diff --git a/supervisor/utils/pwned.py b/supervisor/utils/pwned.py index 7c2250154f3..eb1feae9c5f 100644 --- a/supervisor/utils/pwned.py +++ b/supervisor/utils/pwned.py @@ -1,4 +1,5 @@ """Small wrapper for haveibeenpwned.com API.""" + import io import logging diff --git a/supervisor/utils/systemd_journal.py b/supervisor/utils/systemd_journal.py index 051222dbd04..3155dc675b6 100644 --- a/supervisor/utils/systemd_journal.py +++ b/supervisor/utils/systemd_journal.py @@ -1,4 +1,5 @@ """Utilities for working with systemd journal export format.""" + from collections.abc import AsyncGenerator from datetime import UTC, datetime from functools import wraps diff --git a/supervisor/utils/whoami.py b/supervisor/utils/whoami.py index edb285395c2..db7a0dd5281 100644 --- a/supervisor/utils/whoami.py +++ b/supervisor/utils/whoami.py @@ -2,6 +2,7 @@ https://github.com/home-assistant/whoami.home-assistant.io """ + from datetime import datetime import logging diff --git a/supervisor/utils/yaml.py b/supervisor/utils/yaml.py index 684fedc9db3..1448901db6e 100644 --- a/supervisor/utils/yaml.py +++ b/supervisor/utils/yaml.py @@ -1,4 +1,5 @@ """Tools handle YAML files for Supervisor.""" + import logging from pathlib import Path diff --git a/supervisor/validate.py b/supervisor/validate.py index 8aa3f2966c3..b22a1b3e4a6 100644 --- a/supervisor/validate.py +++ b/supervisor/validate.py @@ -1,4 +1,5 @@ """Validate functions.""" + import ipaddress import re diff --git a/tests/addons/test_addon.py b/tests/addons/test_addon.py index 0c24dd9f9f8..f67d6267d09 100644 --- a/tests/addons/test_addon.py +++ b/tests/addons/test_addon.py @@ -132,9 +132,11 @@ async def test_addon_watchdog(coresys: CoreSys, install_addon_ssh: Addon) -> Non install_addon_ssh.watchdog = True install_addon_ssh._manual_stop = False # pylint: disable=protected-access - with patch.object(Addon, "restart") as restart, patch.object( - Addon, "start" - ) as start, patch.object(DockerAddon, "current_state") as current_state: + with ( + patch.object(Addon, "restart") as restart, + patch.object(Addon, "start") as start, + patch.object(DockerAddon, "current_state") as current_state, + ): # Restart if it becomes unhealthy current_state.return_value = ContainerState.UNHEALTHY _fire_test_event(coresys, f"addon_{TEST_ADDON_SLUG}", ContainerState.UNHEALTHY) @@ -177,11 +179,15 @@ async def test_watchdog_on_stop(coresys: CoreSys, install_addon_ssh: Addon) -> N install_addon_ssh.watchdog = True - with patch.object(Addon, "restart") as restart, patch.object( - DockerAddon, - "current_state", - return_value=ContainerState.STOPPED, - ), patch.object(DockerAddon, "stop"): + with ( + patch.object(Addon, "restart") as restart, + patch.object( + DockerAddon, + "current_state", + return_value=ContainerState.STOPPED, + ), + patch.object(DockerAddon, "stop"), + ): # Do not restart when addon stopped by user _fire_test_event(coresys, f"addon_{TEST_ADDON_SLUG}", ContainerState.RUNNING) await asyncio.sleep(0) @@ -205,14 +211,20 @@ async def test_listener_attached_on_install( coresys.hardware.disk.get_disk_free_space = lambda x: 5000 container_collection = MagicMock() container_collection.get.side_effect = DockerException() - with patch( - "supervisor.docker.manager.DockerAPI.containers", - new=PropertyMock(return_value=container_collection), - ), patch("pathlib.Path.is_dir", return_value=True), patch( - "supervisor.addons.addon.Addon.need_build", new=PropertyMock(return_value=False) - ), patch( - "supervisor.addons.model.AddonModel.with_ingress", - new=PropertyMock(return_value=False), + with ( + patch( + "supervisor.docker.manager.DockerAPI.containers", + new=PropertyMock(return_value=container_collection), + ), + patch("pathlib.Path.is_dir", return_value=True), + patch( + "supervisor.addons.addon.Addon.need_build", + new=PropertyMock(return_value=False), + ), + patch( + "supervisor.addons.model.AddonModel.with_ingress", + new=PropertyMock(return_value=False), + ), ): await coresys.addons.install(TEST_ADDON_SLUG) @@ -234,14 +246,19 @@ async def test_watchdog_during_attach( store = coresys.addons.store[TEST_ADDON_SLUG] coresys.addons.data.install(store) - with patch.object(Addon, "restart") as restart, patch.object( - type(coresys.hardware.helper), - "last_boot", - new=PropertyMock(return_value=utcnow()), - ), patch.object(DockerAddon, "attach"), patch.object( - DockerAddon, - "current_state", - return_value=ContainerState.STOPPED, + with ( + patch.object(Addon, "restart") as restart, + patch.object( + type(coresys.hardware.helper), + "last_boot", + new=PropertyMock(return_value=utcnow()), + ), + patch.object(DockerAddon, "attach"), + patch.object( + DockerAddon, + "current_state", + return_value=ContainerState.STOPPED, + ), ): coresys.config.last_boot = coresys.hardware.helper.last_boot + boot_timedelta addon = Addon(coresys, store.slug) @@ -269,10 +286,15 @@ async def test_install_update_fails_if_out_of_date( with pytest.raises(AddonsJobError): await coresys.addons.update(TEST_ADDON_SLUG) - with patch.object( - type(coresys.plugins.audio), "need_update", new=PropertyMock(return_value=True) - ), patch.object( - type(coresys.plugins.audio), "update", side_effect=AudioUpdateError + with ( + patch.object( + type(coresys.plugins.audio), + "need_update", + new=PropertyMock(return_value=True), + ), + patch.object( + type(coresys.plugins.audio), "update", side_effect=AudioUpdateError + ), ): with pytest.raises(AddonsJobError): await coresys.addons.install(TEST_ADDON_SLUG) @@ -437,9 +459,12 @@ async def test_backup_with_pre_post_command( await install_addon_ssh.load() tarfile = SecureTarFile(coresys.config.path_tmp / "test.tar.gz", "w") - with patch.object( - Addon, "backup_pre", new=PropertyMock(return_value="backup_pre") - ), patch.object(Addon, "backup_post", new=PropertyMock(return_value="backup_post")): + with ( + patch.object(Addon, "backup_pre", new=PropertyMock(return_value="backup_pre")), + patch.object( + Addon, "backup_post", new=PropertyMock(return_value="backup_post") + ), + ): assert await install_addon_ssh.backup(tarfile) is None assert container.exec_run.call_count == 2 @@ -478,9 +503,11 @@ async def test_backup_with_pre_command_error( await install_addon_ssh.load() tarfile = SecureTarFile(coresys.config.path_tmp / "test.tar.gz", "w") - with patch.object(DockerAddon, "is_running", return_value=True), patch.object( - Addon, "backup_pre", new=PropertyMock(return_value="backup_pre") - ), pytest.raises(AddonsError): + with ( + patch.object(DockerAddon, "is_running", return_value=True), + patch.object(Addon, "backup_pre", new=PropertyMock(return_value="backup_pre")), + pytest.raises(AddonsError), + ): assert await install_addon_ssh.backup(tarfile) is None assert not tarfile.path.exists() @@ -501,10 +528,15 @@ async def test_backup_cold_mode( await install_addon_ssh.load() tarfile = SecureTarFile(coresys.config.path_tmp / "test.tar.gz", "w") - with patch.object( - AddonModel, "backup_mode", new=PropertyMock(return_value=AddonBackupMode.COLD) - ), patch.object( - DockerAddon, "is_running", side_effect=[status == "running", False, False] + with ( + patch.object( + AddonModel, + "backup_mode", + new=PropertyMock(return_value=AddonBackupMode.COLD), + ), + patch.object( + DockerAddon, "is_running", side_effect=[status == "running", False, False] + ), ): start_task = await install_addon_ssh.backup(tarfile) @@ -532,14 +564,16 @@ async def mock_stop(*args, **kwargs): # Patching out the normal end of backup process leaves the container in a stopped state # Watchdog should still not try to restart it though, it should remain this way tarfile = SecureTarFile(coresys.config.path_tmp / "test.tar.gz", "w") - with patch.object(Addon, "start") as start, patch.object( - Addon, "restart" - ) as restart, patch.object(Addon, "end_backup"), patch.object( - DockerAddon, "stop", new=mock_stop - ), patch.object( - AddonModel, - "backup_mode", - new=PropertyMock(return_value=AddonBackupMode.COLD), + with ( + patch.object(Addon, "start") as start, + patch.object(Addon, "restart") as restart, + patch.object(Addon, "end_backup"), + patch.object(DockerAddon, "stop", new=mock_stop), + patch.object( + AddonModel, + "backup_mode", + new=PropertyMock(return_value=AddonBackupMode.COLD), + ), ): await install_addon_ssh.backup(tarfile) await asyncio.sleep(0) @@ -584,8 +618,9 @@ async def test_restore_while_running( await install_addon_ssh.load() tarfile = SecureTarFile(get_fixture_path("backup_local_ssh_stopped.tar.gz"), "r") - with patch.object(DockerAddon, "is_running", return_value=True), patch.object( - Ingress, "update_hass_panel" + with ( + patch.object(DockerAddon, "is_running", return_value=True), + patch.object(Ingress, "update_hass_panel"), ): start_task = await coresys.addons.restore(TEST_ADDON_SLUG, tarfile) @@ -616,10 +651,11 @@ async def mock_stop(*args, **kwargs): # We restore a stopped backup so restore will not restart it # Watchdog will see it stop and should not attempt reanimation either tarfile = SecureTarFile(get_fixture_path("backup_local_ssh_stopped.tar.gz"), "r") - with patch.object(Addon, "start") as start, patch.object( - Addon, "restart" - ) as restart, patch.object(DockerAddon, "stop", new=mock_stop), patch.object( - Ingress, "update_hass_panel" + with ( + patch.object(Addon, "start") as start, + patch.object(Addon, "restart") as restart, + patch.object(DockerAddon, "stop", new=mock_stop), + patch.object(Ingress, "update_hass_panel"), ): await coresys.addons.restore(TEST_ADDON_SLUG, tarfile) await asyncio.sleep(0) diff --git a/tests/addons/test_build.py b/tests/addons/test_build.py index 6366cd07f68..9f55f690cad 100644 --- a/tests/addons/test_build.py +++ b/tests/addons/test_build.py @@ -1,4 +1,5 @@ """Test addon build.""" + from unittest.mock import PropertyMock, patch from awesomeversion import AwesomeVersion @@ -11,10 +12,13 @@ async def test_platform_set(coresys: CoreSys, install_addon_ssh: Addon): """Test platform set in docker args.""" build = AddonBuild(coresys, install_addon_ssh) - with patch.object( - type(coresys.arch), "supported", new=PropertyMock(return_value=["amd64"]) - ), patch.object( - type(coresys.arch), "default", new=PropertyMock(return_value="amd64") + with ( + patch.object( + type(coresys.arch), "supported", new=PropertyMock(return_value=["amd64"]) + ), + patch.object( + type(coresys.arch), "default", new=PropertyMock(return_value="amd64") + ), ): args = build.get_docker_args(AwesomeVersion("latest")) @@ -24,10 +28,13 @@ async def test_platform_set(coresys: CoreSys, install_addon_ssh: Addon): async def test_dockerfile_evaluation(coresys: CoreSys, install_addon_ssh: Addon): """Test platform set in docker args.""" build = AddonBuild(coresys, install_addon_ssh) - with patch.object( - type(coresys.arch), "supported", new=PropertyMock(return_value=["amd64"]) - ), patch.object( - type(coresys.arch), "default", new=PropertyMock(return_value="amd64") + with ( + patch.object( + type(coresys.arch), "supported", new=PropertyMock(return_value=["amd64"]) + ), + patch.object( + type(coresys.arch), "default", new=PropertyMock(return_value="amd64") + ), ): args = build.get_docker_args(AwesomeVersion("latest")) @@ -39,10 +46,13 @@ async def test_dockerfile_evaluation(coresys: CoreSys, install_addon_ssh: Addon) async def test_dockerfile_evaluation_arch(coresys: CoreSys, install_addon_ssh: Addon): """Test platform set in docker args.""" build = AddonBuild(coresys, install_addon_ssh) - with patch.object( - type(coresys.arch), "supported", new=PropertyMock(return_value=["aarch64"]) - ), patch.object( - type(coresys.arch), "default", new=PropertyMock(return_value="aarch64") + with ( + patch.object( + type(coresys.arch), "supported", new=PropertyMock(return_value=["aarch64"]) + ), + patch.object( + type(coresys.arch), "default", new=PropertyMock(return_value="aarch64") + ), ): args = build.get_docker_args(AwesomeVersion("latest")) @@ -56,10 +66,13 @@ async def test_dockerfile_evaluation_arch(coresys: CoreSys, install_addon_ssh: A async def test_build_valid(coresys: CoreSys, install_addon_ssh: Addon): """Test platform set in docker args.""" build = AddonBuild(coresys, install_addon_ssh) - with patch.object( - type(coresys.arch), "supported", new=PropertyMock(return_value=["aarch64"]) - ), patch.object( - type(coresys.arch), "default", new=PropertyMock(return_value="aarch64") + with ( + patch.object( + type(coresys.arch), "supported", new=PropertyMock(return_value=["aarch64"]) + ), + patch.object( + type(coresys.arch), "default", new=PropertyMock(return_value="aarch64") + ), ): assert build.is_valid @@ -67,9 +80,12 @@ async def test_build_valid(coresys: CoreSys, install_addon_ssh: Addon): async def test_build_invalid(coresys: CoreSys, install_addon_ssh: Addon): """Test platform set in docker args.""" build = AddonBuild(coresys, install_addon_ssh) - with patch.object( - type(coresys.arch), "supported", new=PropertyMock(return_value=["amd64"]) - ), patch.object( - type(coresys.arch), "default", new=PropertyMock(return_value="amd64") + with ( + patch.object( + type(coresys.arch), "supported", new=PropertyMock(return_value=["amd64"]) + ), + patch.object( + type(coresys.arch), "default", new=PropertyMock(return_value="amd64") + ), ): assert not build.is_valid diff --git a/tests/addons/test_config.py b/tests/addons/test_config.py index 5c36757b467..fa723b6a316 100644 --- a/tests/addons/test_config.py +++ b/tests/addons/test_config.py @@ -1,6 +1,5 @@ """Validate Add-on configs.""" - import pytest import voluptuous as vol @@ -116,9 +115,9 @@ def test_invalid_repository(): with pytest.raises(vol.Invalid): vd.SCHEMA_ADDON_CONFIG(config) - config[ - "image" - ] = "registry.gitlab.com/company/add-ons/test-example/text-example:no-tag-allow" + config["image"] = ( + "registry.gitlab.com/company/add-ons/test-example/text-example:no-tag-allow" + ) with pytest.raises(vol.Invalid): vd.SCHEMA_ADDON_CONFIG(config) diff --git a/tests/addons/test_manager.py b/tests/addons/test_manager.py index 2b7b5f3c174..2c2fe45a689 100644 --- a/tests/addons/test_manager.py +++ b/tests/addons/test_manager.py @@ -35,9 +35,10 @@ @pytest.fixture(autouse=True) async def fixture_mock_arch_disk() -> None: """Mock supported arch and disk space.""" - with patch( - "shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3)) - ), patch.object(CpuArch, "supported", new=PropertyMock(return_value=["amd64"])): + with ( + patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3))), + patch.object(CpuArch, "supported", new=PropertyMock(return_value=["amd64"])), + ): yield @@ -62,9 +63,10 @@ async def test_image_added_removed_on_update( assert install_addon_ssh.image == "local/amd64-addon-ssh" assert coresys.addons.store.get(TEST_ADDON_SLUG).image == "test/amd64-my-ssh-addon" - with patch.object(DockerInterface, "install") as install, patch.object( - DockerAddon, "_build" - ) as build: + with ( + patch.object(DockerInterface, "install") as install, + patch.object(DockerAddon, "_build") as build, + ): await coresys.addons.update(TEST_ADDON_SLUG) build.assert_not_called() install.assert_called_once_with( @@ -82,9 +84,10 @@ async def test_image_added_removed_on_update( assert install_addon_ssh.image == "test/amd64-my-ssh-addon" assert coresys.addons.store.get(TEST_ADDON_SLUG).image == "local/amd64-addon-ssh" - with patch.object(DockerInterface, "install") as install, patch.object( - DockerAddon, "_build" - ) as build: + with ( + patch.object(DockerInterface, "install") as install, + patch.object(DockerAddon, "_build") as build, + ): await coresys.addons.update(TEST_ADDON_SLUG) build.assert_called_once_with(AwesomeVersion("11.0.0"), "local/amd64-addon-ssh") install.assert_not_called() @@ -96,8 +99,9 @@ async def test_addon_boot_system_error( ): """Test system errors during addon boot.""" install_addon_ssh.boot = AddonBoot.AUTO - with patch.object(Addon, "write_options"), patch.object( - DockerAddon, "run", side_effect=err + with ( + patch.object(Addon, "write_options"), + patch.object(DockerAddon, "run", side_effect=err), ): await coresys.addons.boot(AddonStartup.APPLICATION) @@ -123,8 +127,9 @@ async def test_addon_boot_other_error( """Test other errors captured during addon boot.""" install_addon_ssh.boot = AddonBoot.AUTO err = OSError() - with patch.object(Addon, "write_options"), patch.object( - DockerAddon, "run", side_effect=err + with ( + patch.object(Addon, "write_options"), + patch.object(DockerAddon, "run", side_effect=err), ): await coresys.addons.boot(AddonStartup.APPLICATION) @@ -186,9 +191,10 @@ async def test_load( """Test addon manager load.""" caplog.clear() - with patch.object(DockerInterface, "attach") as attach, patch.object( - PluginDns, "write_hosts" - ) as write_hosts: + with ( + patch.object(DockerInterface, "attach") as attach, + patch.object(PluginDns, "write_hosts") as write_hosts, + ): await coresys.addons.load() attach.assert_called_once_with(version=AwesomeVersion("9.2.1")) @@ -254,8 +260,9 @@ async def test_update( assert install_addon_ssh.need_update is True - with patch.object(DockerInterface, "install"), patch.object( - DockerAddon, "is_running", return_value=False + with ( + patch.object(DockerInterface, "install"), + patch.object(DockerAddon, "is_running", return_value=False), ): start_task = await coresys.addons.update(TEST_ADDON_SLUG) @@ -276,9 +283,11 @@ async def test_rebuild( install_addon_ssh.path_data.mkdir() await install_addon_ssh.load() - with patch.object(DockerAddon, "_build"), patch.object( - DockerAddon, "is_running", return_value=False - ), patch.object(Addon, "need_build", new=PropertyMock(return_value=True)): + with ( + patch.object(DockerAddon, "_build"), + patch.object(DockerAddon, "is_running", return_value=False), + patch.object(Addon, "need_build", new=PropertyMock(return_value=True)), + ): start_task = await coresys.addons.rebuild(TEST_ADDON_SLUG) assert bool(start_task) is (status == "running") @@ -382,9 +391,10 @@ async def mock_update(_, version, image, *args, **kwargs): assert image == "test_image" await event.wait() - with patch.object(DockerAddon, "update", new=mock_update), patch.object( - DockerAPI, "cleanup_old_images" - ) as cleanup: + with ( + patch.object(DockerAddon, "update", new=mock_update), + patch.object(DockerAPI, "cleanup_old_images") as cleanup, + ): await coresys.addons.update("local_ssh") cleanup.assert_called_once_with( "test_image", AwesomeVersion("1.1.1"), {"local/amd64-addon-ssh"} @@ -434,9 +444,12 @@ async def mock_update(*args, **kwargs): await asyncio.sleep(0) # Start should be called exactly once by update itself. Restart should never be called - with patch.object(DockerAddon, "stop", new=mock_stop), patch.object( - DockerAddon, "update", new=mock_update - ), patch.object(Addon, "start") as start, patch.object(Addon, "restart") as restart: + with ( + patch.object(DockerAddon, "stop", new=mock_stop), + patch.object(DockerAddon, "update", new=mock_update), + patch.object(Addon, "start") as start, + patch.object(Addon, "restart") as restart, + ): await coresys.addons.update("local_ssh") await asyncio.sleep(0) start.assert_called_once() diff --git a/tests/addons/test_options.py b/tests/addons/test_options.py index 99eabb47cb5..847cc285cc7 100644 --- a/tests/addons/test_options.py +++ b/tests/addons/test_options.py @@ -1,4 +1,5 @@ """Test add-ons schema to UI schema convertion.""" + from pathlib import Path import pytest diff --git a/tests/api/__init__.py b/tests/api/__init__.py index b395105c77d..1b712021acc 100644 --- a/tests/api/__init__.py +++ b/tests/api/__init__.py @@ -1,4 +1,5 @@ """Test for API calls.""" + from unittest.mock import MagicMock from aiohttp.test_utils import TestClient diff --git a/tests/api/test_discovery.py b/tests/api/test_discovery.py index 16dc0a98eb0..01295859b24 100644 --- a/tests/api/test_discovery.py +++ b/tests/api/test_discovery.py @@ -47,10 +47,13 @@ async def test_api_list_discovery( skip_state: AddonState, ): """Test listing discovery messages only returns ones for healthy services.""" - with patch( - "supervisor.utils.common.read_json_or_yaml_file", - return_value=load_json_fixture("discovery.json"), - ), patch("supervisor.utils.common.Path.is_file", return_value=True): + with ( + patch( + "supervisor.utils.common.read_json_or_yaml_file", + return_value=load_json_fixture("discovery.json"), + ), + patch("supervisor.utils.common.Path.is_file", return_value=True), + ): coresys.discovery.read_data() await coresys.discovery.load() diff --git a/tests/api/test_dns.py b/tests/api/test_dns.py index 72a4eb3e473..8e0027d6ef4 100644 --- a/tests/api/test_dns.py +++ b/tests/api/test_dns.py @@ -1,4 +1,5 @@ """Test DNS API.""" + from unittest.mock import MagicMock, patch from aiohttp.test_utils import TestClient diff --git a/tests/api/test_docker.py b/tests/api/test_docker.py index 3390ff2842d..040a958d46e 100644 --- a/tests/api/test_docker.py +++ b/tests/api/test_docker.py @@ -1,4 +1,5 @@ """Test Docker API.""" + import pytest diff --git a/tests/api/test_hardware.py b/tests/api/test_hardware.py index 492a43216f8..44df630f388 100644 --- a/tests/api/test_hardware.py +++ b/tests/api/test_hardware.py @@ -1,4 +1,5 @@ """Test Docker API.""" + from pathlib import Path from aiohttp.test_utils import TestClient diff --git a/tests/api/test_network.py b/tests/api/test_network.py index 0a6df77ba62..5b5f6094569 100644 --- a/tests/api/test_network.py +++ b/tests/api/test_network.py @@ -1,4 +1,5 @@ """Test NetwrokInterface API.""" + from unittest.mock import AsyncMock, patch from aiohttp.test_utils import TestClient @@ -203,10 +204,11 @@ async def test_api_network_wireless_scan(api_client: TestClient): ) result = await resp.json() - assert ["UPC4814466", "VQ@35(55720"] == [ - ap["ssid"] for ap in result["data"]["accesspoints"] + assert [ap["ssid"] for ap in result["data"]["accesspoints"]] == [ + "UPC4814466", + "VQ@35(55720", ] - assert [47, 63] == [ap["signal"] for ap in result["data"]["accesspoints"]] + assert [ap["signal"] for ap in result["data"]["accesspoints"]] == [47, 63] async def test_api_network_reload( diff --git a/tests/api/test_resolution.py b/tests/api/test_resolution.py index b15023219e6..f3db99e2f4d 100644 --- a/tests/api/test_resolution.py +++ b/tests/api/test_resolution.py @@ -1,4 +1,5 @@ """Test Resolution API.""" + from unittest.mock import AsyncMock import pytest diff --git a/tests/api/test_root.py b/tests/api/test_root.py index 37743d72d19..88b2c3754b5 100644 --- a/tests/api/test_root.py +++ b/tests/api/test_root.py @@ -1,4 +1,5 @@ """Test Supervisor API.""" + # pylint: disable=protected-access from unittest.mock import AsyncMock diff --git a/tests/api/test_store.py b/tests/api/test_store.py index e629845cd84..f75d7237393 100644 --- a/tests/api/test_store.py +++ b/tests/api/test_store.py @@ -93,8 +93,9 @@ async def test_api_store_repositories_repository( async def test_api_store_add_repository(api_client: TestClient, coresys: CoreSys): """Test POST /store/repositories REST API.""" - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "supervisor.store.repository.Repository.validate", return_value=True + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch("supervisor.store.repository.Repository.validate", return_value=True), ): response = await api_client.post( "/store/repositories", json={"repository": REPO_URL} @@ -178,10 +179,11 @@ async def container_events_task(*args, **kwargs): nonlocal _container_events_task _container_events_task = asyncio.create_task(container_events()) - with patch.object(DockerAddon, "run", new=container_events_task), patch.object( - DockerInterface, "install" - ), patch.object(DockerAddon, "is_running", return_value=False), patch.object( - CpuArch, "supported", new=PropertyMock(return_value=["amd64"]) + with ( + patch.object(DockerAddon, "run", new=container_events_task), + patch.object(DockerInterface, "install"), + patch.object(DockerAddon, "is_running", return_value=False), + patch.object(CpuArch, "supported", new=PropertyMock(return_value=["amd64"])), ): resp = await api_client.post(f"/store/addons/{TEST_ADDON_SLUG}/update") diff --git a/tests/api/test_supervisor.py b/tests/api/test_supervisor.py index 483bbd486f7..4ec22470842 100644 --- a/tests/api/test_supervisor.py +++ b/tests/api/test_supervisor.py @@ -1,4 +1,5 @@ """Test Supervisor API.""" + # pylint: disable=protected-access from unittest.mock import MagicMock, patch @@ -38,8 +39,9 @@ async def test_api_supervisor_options_add_repository( with pytest.raises(StoreNotFound): coresys.store.get_from_url(REPO_URL) - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "supervisor.store.repository.Repository.validate", return_value=True + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch("supervisor.store.repository.Repository.validate", return_value=True), ): response = await api_client.post( "/supervisor/options", json={"addons_repositories": [REPO_URL]} @@ -71,11 +73,11 @@ async def test_api_supervisor_options_repositories_skipped_on_error( api_client: TestClient, coresys: CoreSys, git_error: StoreGitError ): """Test repositories skipped on error via POST /supervisor/options REST API.""" - with patch( - "supervisor.store.repository.Repository.load", side_effect=git_error - ), patch( - "supervisor.store.repository.Repository.validate", return_value=False - ), patch("supervisor.store.repository.Repository.remove"): + with ( + patch("supervisor.store.repository.Repository.load", side_effect=git_error), + patch("supervisor.store.repository.Repository.validate", return_value=False), + patch("supervisor.store.repository.Repository.remove"), + ): response = await api_client.post( "/supervisor/options", json={"addons_repositories": [REPO_URL]} ) diff --git a/tests/conftest.py b/tests/conftest.py index cf7715b3dd1..5ccc031bdb6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ """Common test functions.""" + import asyncio from functools import partial from inspect import unwrap @@ -81,25 +82,25 @@ async def docker() -> DockerAPI: image = MagicMock() image.attrs = {"Os": "linux", "Architecture": "amd64"} - with patch( - "supervisor.docker.manager.DockerClient", return_value=MagicMock() - ), patch( - "supervisor.docker.manager.DockerAPI.images", return_value=MagicMock() - ), patch( - "supervisor.docker.manager.DockerAPI.containers", return_value=MagicMock() - ), patch( - "supervisor.docker.manager.DockerAPI.api", return_value=MagicMock() - ), patch( - "supervisor.docker.manager.DockerAPI.images.get", return_value=image - ), patch( - "supervisor.docker.manager.DockerAPI.images.list", return_value=images - ), patch( - "supervisor.docker.manager.DockerAPI.info", - return_value=MagicMock(), - ), patch( - "supervisor.docker.manager.DockerConfig", - return_value=MagicMock(), - ), patch("supervisor.docker.manager.DockerAPI.unload"): + with ( + patch("supervisor.docker.manager.DockerClient", return_value=MagicMock()), + patch("supervisor.docker.manager.DockerAPI.images", return_value=MagicMock()), + patch( + "supervisor.docker.manager.DockerAPI.containers", return_value=MagicMock() + ), + patch("supervisor.docker.manager.DockerAPI.api", return_value=MagicMock()), + patch("supervisor.docker.manager.DockerAPI.images.get", return_value=image), + patch("supervisor.docker.manager.DockerAPI.images.list", return_value=images), + patch( + "supervisor.docker.manager.DockerAPI.info", + return_value=MagicMock(), + ), + patch( + "supervisor.docker.manager.DockerConfig", + return_value=MagicMock(), + ), + patch("supervisor.docker.manager.DockerAPI.unload"), + ): docker_obj = DockerAPI(MagicMock()) with patch("supervisor.docker.monitor.DockerMonitor.load"): await docker_obj.load() @@ -306,8 +307,9 @@ async def coresys( supervisor_name, ) -> CoreSys: """Create a CoreSys Mock.""" - with patch("supervisor.bootstrap.initialize_system"), patch( - "supervisor.utils.sentry.sentry_sdk.init" + with ( + patch("supervisor.bootstrap.initialize_system"), + patch("supervisor.utils.sentry.sentry_sdk.init"), ): coresys_obj = await initialize_coresys() @@ -332,8 +334,9 @@ async def coresys( coresys_obj._machine_id = uuid4() # Mock host communication - with patch("supervisor.dbus.manager.MessageBus") as message_bus, patch( - "supervisor.dbus.manager.SOCKET_DBUS" + with ( + patch("supervisor.dbus.manager.MessageBus") as message_bus, + patch("supervisor.dbus.manager.SOCKET_DBUS"), ): message_bus.return_value.connect = AsyncMock(return_value=dbus_session_bus) await coresys_obj._dbus.load() @@ -412,9 +415,10 @@ async def tmp_supervisor_data(coresys: CoreSys, tmp_path: Path) -> Path: @pytest.fixture async def journald_gateway() -> MagicMock: """Mock logs control.""" - with patch("supervisor.host.logs.Path.is_socket", return_value=True), patch( - "supervisor.host.logs.ClientSession.get" - ) as get: + with ( + patch("supervisor.host.logs.Path.is_socket", return_value=True), + patch("supervisor.host.logs.ClientSession.get") as get, + ): reader = asyncio.StreamReader(loop=asyncio.get_running_loop()) async def response_text(): @@ -523,9 +527,10 @@ async def repository(coresys: CoreSys): ) coresys.config._data[ATTR_ADDONS_CUSTOM_LIST] = [] - with patch( - "supervisor.store.validate.BUILTIN_REPOSITORIES", {"local", "core"} - ), patch("supervisor.store.git.GitRepo.load", return_value=None): + with ( + patch("supervisor.store.validate.BUILTIN_REPOSITORIES", {"local", "core"}), + patch("supervisor.store.git.GitRepo.load", return_value=None), + ): await coresys.store.load() repository_obj = Repository( @@ -638,15 +643,16 @@ async def backups( @pytest.fixture async def journald_logs(coresys: CoreSys) -> MagicMock: """Mock journald logs and make it available.""" - with patch.object( - LogsControl, "available", new=PropertyMock(return_value=True) - ), patch.object( - LogsControl, "get_boot_ids", return_value=["aaa", "bbb", "ccc"] - ), patch.object( - LogsControl, - "get_identifiers", - return_value=["hassio_supervisor", "hassos-config", "kernel"], - ), patch.object(LogsControl, "journald_logs", new=MagicMock()) as logs: + with ( + patch.object(LogsControl, "available", new=PropertyMock(return_value=True)), + patch.object(LogsControl, "get_boot_ids", return_value=["aaa", "bbb", "ccc"]), + patch.object( + LogsControl, + "get_identifiers", + return_value=["hassio_supervisor", "hassos-config", "kernel"], + ), + patch.object(LogsControl, "journald_logs", new=MagicMock()) as logs, + ): await coresys.host.logs.load() yield logs @@ -663,18 +669,22 @@ async def docker_logs(docker: DockerAPI, supervisor_name) -> MagicMock: @pytest.fixture async def capture_exception() -> Mock: """Mock capture exception method for testing.""" - with patch("supervisor.utils.sentry.sentry_connected", return_value=True), patch( - "supervisor.utils.sentry.sentry_sdk.capture_exception" - ) as capture_exception: + with ( + patch("supervisor.utils.sentry.sentry_connected", return_value=True), + patch( + "supervisor.utils.sentry.sentry_sdk.capture_exception" + ) as capture_exception, + ): yield capture_exception @pytest.fixture async def capture_event() -> Mock: """Mock capture event for testing.""" - with patch("supervisor.utils.sentry.sentry_connected", return_value=True), patch( - "supervisor.utils.sentry.sentry_sdk.capture_event" - ) as capture_event: + with ( + patch("supervisor.utils.sentry.sentry_connected", return_value=True), + patch("supervisor.utils.sentry.sentry_sdk.capture_event") as capture_event, + ): yield capture_event @@ -686,9 +696,10 @@ async def os_available(request: pytest.FixtureRequest) -> None: if hasattr(request, "param") else AwesomeVersion("10.2") ) - with patch.object( - OSManager, "available", new=PropertyMock(return_value=True) - ), patch.object(OSManager, "version", new=PropertyMock(return_value=version)): + with ( + patch.object(OSManager, "available", new=PropertyMock(return_value=True)), + patch.object(OSManager, "version", new=PropertyMock(return_value=version)), + ): yield diff --git a/tests/dbus/agent/boards/test_board.py b/tests/dbus/agent/boards/test_board.py index 87efb7a8a0f..29d68cae15e 100644 --- a/tests/dbus/agent/boards/test_board.py +++ b/tests/dbus/agent/boards/test_board.py @@ -1,4 +1,5 @@ """Test Boards manager.""" + # pylint: disable=import-error from dbus_fast.aio.message_bus import MessageBus import pytest diff --git a/tests/dbus/agent/boards/test_green.py b/tests/dbus/agent/boards/test_green.py index 10cee120f22..556dca7967f 100644 --- a/tests/dbus/agent/boards/test_green.py +++ b/tests/dbus/agent/boards/test_green.py @@ -29,9 +29,12 @@ async def test_dbus_green(green_service: GreenService, dbus_session_bus: Message assert green.power_led is True assert green.user_led is True - with patch("supervisor.utils.common.Path.is_file", return_value=True), patch( - "supervisor.utils.common.read_json_file", - return_value={"activity_led": False, "user_led": False}, + with ( + patch("supervisor.utils.common.Path.is_file", return_value=True), + patch( + "supervisor.utils.common.read_json_file", + return_value={"activity_led": False, "user_led": False}, + ), ): green = Green() await green.connect(dbus_session_bus) diff --git a/tests/dbus/agent/boards/test_yellow.py b/tests/dbus/agent/boards/test_yellow.py index 5cd052916ff..333e810c9e3 100644 --- a/tests/dbus/agent/boards/test_yellow.py +++ b/tests/dbus/agent/boards/test_yellow.py @@ -29,9 +29,12 @@ async def test_dbus_yellow(yellow_service: YellowService, dbus_session_bus: Mess assert yellow.heartbeat_led is True assert yellow.power_led is True - with patch("supervisor.utils.common.Path.is_file", return_value=True), patch( - "supervisor.utils.common.read_json_file", - return_value={"disk_led": False, "heartbeat_led": False}, + with ( + patch("supervisor.utils.common.Path.is_file", return_value=True), + patch( + "supervisor.utils.common.read_json_file", + return_value={"disk_led": False, "heartbeat_led": False}, + ), ): yellow = Yellow() await yellow.connect(dbus_session_bus) diff --git a/tests/dbus/agent/test_agent.py b/tests/dbus/agent/test_agent.py index 37ae7f412d9..055415857ae 100644 --- a/tests/dbus/agent/test_agent.py +++ b/tests/dbus/agent/test_agent.py @@ -1,4 +1,5 @@ """Test OSAgent dbus interface.""" + # pylint: disable=import-error from dbus_fast.aio.message_bus import MessageBus import pytest diff --git a/tests/dbus/agent/test_apparmor.py b/tests/dbus/agent/test_apparmor.py index 857eb62ef90..8e7bf632e48 100644 --- a/tests/dbus/agent/test_apparmor.py +++ b/tests/dbus/agent/test_apparmor.py @@ -1,4 +1,5 @@ """Test AppArmor/Agent dbus interface.""" + # pylint: disable=import-error from pathlib import Path diff --git a/tests/dbus/agent/test_cgroup.py b/tests/dbus/agent/test_cgroup.py index e67be97cc14..e4e3a2b378f 100644 --- a/tests/dbus/agent/test_cgroup.py +++ b/tests/dbus/agent/test_cgroup.py @@ -1,4 +1,5 @@ """Test CGroup/Agent dbus interface.""" + # pylint: disable=import-error from dbus_fast.aio.message_bus import MessageBus import pytest diff --git a/tests/dbus/test_hostname.py b/tests/dbus/test_hostname.py index 4563a38dcde..e674a2a137d 100644 --- a/tests/dbus/test_hostname.py +++ b/tests/dbus/test_hostname.py @@ -1,4 +1,5 @@ """Test hostname dbus interface.""" + # pylint: disable=import-error from dbus_fast.aio.message_bus import MessageBus import pytest diff --git a/tests/dbus/test_interface.py b/tests/dbus/test_interface.py index cc5edda7421..a5152001752 100644 --- a/tests/dbus/test_interface.py +++ b/tests/dbus/test_interface.py @@ -149,8 +149,9 @@ async def mock_introspect(*args, **kwargs): """Return introspection without properties.""" return load_fixture("test_no_properties_interface.xml") - with patch.object(MessageBus, "introspect", new=mock_introspect), pytest.raises( - DBusInterfaceError + with ( + patch.object(MessageBus, "introspect", new=mock_introspect), + pytest.raises(DBusInterfaceError), ): await proxy.connect(dbus_session_bus) diff --git a/tests/dbus/test_login.py b/tests/dbus/test_login.py index d53df0027d4..bada0476b7b 100644 --- a/tests/dbus/test_login.py +++ b/tests/dbus/test_login.py @@ -1,4 +1,5 @@ """Test login dbus interface.""" + # pylint: disable=import-error from dbus_fast.aio.message_bus import MessageBus import pytest diff --git a/tests/dbus/test_rauc.py b/tests/dbus/test_rauc.py index c6c666e202a..d4381b39500 100644 --- a/tests/dbus/test_rauc.py +++ b/tests/dbus/test_rauc.py @@ -1,4 +1,5 @@ """Test rauc dbus interface.""" + # pylint: disable=import-error from dbus_fast.aio.message_bus import MessageBus import pytest diff --git a/tests/dbus/test_systemd.py b/tests/dbus/test_systemd.py index 607c94e8619..fb0c54da270 100644 --- a/tests/dbus/test_systemd.py +++ b/tests/dbus/test_systemd.py @@ -1,4 +1,5 @@ """Test hostname dbus interface.""" + # pylint: disable=import-error from dbus_fast import DBusError, Variant from dbus_fast.aio.message_bus import MessageBus diff --git a/tests/dbus/test_timedate.py b/tests/dbus/test_timedate.py index 819953b700a..ab4caf888de 100644 --- a/tests/dbus/test_timedate.py +++ b/tests/dbus/test_timedate.py @@ -1,4 +1,5 @@ """Test TimeDate dbus interface.""" + # pylint: disable=import-error from datetime import UTC, datetime diff --git a/tests/dbus_service_mocks/systemd.py b/tests/dbus_service_mocks/systemd.py index 7d05d3f15e8..a12aa633228 100644 --- a/tests/dbus_service_mocks/systemd.py +++ b/tests/dbus_service_mocks/systemd.py @@ -29,9 +29,9 @@ class Systemd(DBusServiceMock): kexec_watchdog_usec = 0 service_watchdogs = True virtualization = "" - response_get_unit: dict[str, list[str | DBusError]] | list[ - str | DBusError - ] | str | DBusError = "/org/freedesktop/systemd1/unit/tmp_2dyellow_2emount" + response_get_unit: ( + dict[str, list[str | DBusError]] | list[str | DBusError] | str | DBusError + ) = "/org/freedesktop/systemd1/unit/tmp_2dyellow_2emount" response_stop_unit: str | DBusError = "/org/freedesktop/systemd1/job/7623" response_reload_or_restart_unit: str | DBusError = ( "/org/freedesktop/systemd1/job/7623" diff --git a/tests/docker/__init__.py b/tests/docker/__init__.py index 6437e7cf515..64be418e4a1 100644 --- a/tests/docker/__init__.py +++ b/tests/docker/__init__.py @@ -1,4 +1,5 @@ """Docker tests.""" + from docker.types import Mount # dev mount with equivalent of bind-recursive=writable specified via dict value diff --git a/tests/docker/test_addon.py b/tests/docker/test_addon.py index 3f18524db52..edd11cdb5a3 100644 --- a/tests/docker/test_addon.py +++ b/tests/docker/test_addon.py @@ -1,4 +1,5 @@ """Test docker addon setup.""" + from ipaddress import IPv4Address from typing import Any from unittest.mock import MagicMock, Mock, PropertyMock, patch @@ -319,9 +320,13 @@ async def test_addon_run_docker_error( coresys, addonsdata_system, "basic-addon-config.json" ) - with patch.object(DockerAddon, "stop"), patch.object( - AddonOptions, "validate", new=PropertyMock(return_value=lambda _: None) - ), pytest.raises(DockerNotFound): + with ( + patch.object(DockerAddon, "stop"), + patch.object( + AddonOptions, "validate", new=PropertyMock(return_value=lambda _: None) + ), + pytest.raises(DockerNotFound), + ): await docker_addon.run() assert ( @@ -342,9 +347,13 @@ async def test_addon_run_add_host_error( coresys, addonsdata_system, "basic-addon-config.json" ) - with patch.object(DockerAddon, "stop"), patch.object( - AddonOptions, "validate", new=PropertyMock(return_value=lambda _: None) - ), patch.object(PluginDns, "add_host", side_effect=(err := CoreDNSError())): + with ( + patch.object(DockerAddon, "stop"), + patch.object( + AddonOptions, "validate", new=PropertyMock(return_value=lambda _: None) + ), + patch.object(PluginDns, "add_host", side_effect=(err := CoreDNSError())), + ): await docker_addon.run() capture_exception.assert_called_once_with(err) @@ -360,11 +369,14 @@ async def test_addon_stop_delete_host_error( coresys, addonsdata_system, "basic-addon-config.json" ) - with patch.object( - DockerAddon, - "ip_address", - new=PropertyMock(return_value=IPv4Address("172.30.33.1")), - ), patch.object(PluginDns, "delete_host", side_effect=(err := CoreDNSError())): + with ( + patch.object( + DockerAddon, + "ip_address", + new=PropertyMock(return_value=IPv4Address("172.30.33.1")), + ), + patch.object(PluginDns, "delete_host", side_effect=(err := CoreDNSError())), + ): await docker_addon.stop() capture_exception.assert_called_once_with(err) diff --git a/tests/docker/test_credentials.py b/tests/docker/test_credentials.py index 6b311bb640f..7138bffed40 100644 --- a/tests/docker/test_credentials.py +++ b/tests/docker/test_credentials.py @@ -1,4 +1,5 @@ """Test docker login.""" + # pylint: disable=protected-access from supervisor.coresys import CoreSys from supervisor.docker.interface import DOCKER_HUB, DockerInterface diff --git a/tests/docker/test_homeassistant.py b/tests/docker/test_homeassistant.py index 02fd2fe42a3..5e4833325ad 100644 --- a/tests/docker/test_homeassistant.py +++ b/tests/docker/test_homeassistant.py @@ -21,9 +21,13 @@ async def test_homeassistant_start( """Test starting homeassistant.""" coresys.homeassistant.version = AwesomeVersion("2023.8.1") - with patch.object(DockerAPI, "run") as run, patch.object( - DockerHomeAssistant, "is_running", side_effect=[False, False, True] - ), patch("supervisor.homeassistant.core.asyncio.sleep"): + with ( + patch.object(DockerAPI, "run") as run, + patch.object( + DockerHomeAssistant, "is_running", side_effect=[False, False, True] + ), + patch("supervisor.homeassistant.core.asyncio.sleep"), + ): await coresys.homeassistant.core.start() run.assert_called_once() @@ -107,8 +111,9 @@ async def test_landingpage_start( """Test starting landingpage.""" coresys.homeassistant.version = LANDINGPAGE - with patch.object(DockerAPI, "run") as run, patch.object( - DockerHomeAssistant, "is_running", return_value=False + with ( + patch.object(DockerAPI, "run") as run, + patch.object(DockerHomeAssistant, "is_running", return_value=False), ): await coresys.homeassistant.core.start() diff --git a/tests/docker/test_interface.py b/tests/docker/test_interface.py index 7c11ee65be1..353c2cea608 100644 --- a/tests/docker/test_interface.py +++ b/tests/docker/test_interface.py @@ -1,4 +1,5 @@ """Test Docker interface.""" + import asyncio from typing import Any from unittest.mock import MagicMock, Mock, PropertyMock, call, patch @@ -56,11 +57,14 @@ async def test_docker_image_platform(coresys: CoreSys, cpu_arch: str, platform: async def test_docker_image_default_platform(coresys: CoreSys): """Test platform set using supervisor arch when omitted.""" - with patch.object( - type(coresys.supervisor), "arch", PropertyMock(return_value="i386") - ), patch.object( - coresys.docker.images, "pull", return_value=Mock(id="test:1.2.3") - ) as pull: + with ( + patch.object( + type(coresys.supervisor), "arch", PropertyMock(return_value="i386") + ), + patch.object( + coresys.docker.images, "pull", return_value=Mock(id="test:1.2.3") + ) as pull, + ): instance = DockerInterface(coresys) await instance.install(AwesomeVersion("1.2.3"), "test") assert pull.call_count == 1 @@ -151,11 +155,13 @@ async def test_attach_existing_container( attrs["Config"] = {} container_collection = MagicMock() container_collection.get.return_value = Container(attrs) - with patch( - "supervisor.docker.manager.DockerAPI.containers", - new=PropertyMock(return_value=container_collection), - ), patch.object(type(coresys.bus), "fire_event") as fire_event, patch( - "supervisor.docker.interface.time", return_value=1 + with ( + patch( + "supervisor.docker.manager.DockerAPI.containers", + new=PropertyMock(return_value=container_collection), + ), + patch.object(type(coresys.bus), "fire_event") as fire_event, + patch("supervisor.docker.interface.time", return_value=1), ): await coresys.homeassistant.core.instance.attach(AwesomeVersion("2022.7.3")) await asyncio.sleep(0) @@ -198,13 +204,17 @@ async def test_attach_container_failure(coresys: CoreSys): image_collection = MagicMock() image_config = {"Image": "sha256:abc123"} image_collection.get.return_value = Image({"Config": image_config}) - with patch( - "supervisor.docker.manager.DockerAPI.containers", - new=PropertyMock(return_value=container_collection), - ), patch( - "supervisor.docker.manager.DockerAPI.images", - new=PropertyMock(return_value=image_collection), - ), patch.object(type(coresys.bus), "fire_event") as fire_event: + with ( + patch( + "supervisor.docker.manager.DockerAPI.containers", + new=PropertyMock(return_value=container_collection), + ), + patch( + "supervisor.docker.manager.DockerAPI.images", + new=PropertyMock(return_value=image_collection), + ), + patch.object(type(coresys.bus), "fire_event") as fire_event, + ): await coresys.homeassistant.core.instance.attach(AwesomeVersion("2022.7.3")) assert not [ event @@ -220,13 +230,17 @@ async def test_attach_total_failure(coresys: CoreSys): container_collection.get.side_effect = DockerException() image_collection = MagicMock() image_collection.get.side_effect = DockerException() - with patch( - "supervisor.docker.manager.DockerAPI.containers", - new=PropertyMock(return_value=container_collection), - ), patch( - "supervisor.docker.manager.DockerAPI.images", - new=PropertyMock(return_value=image_collection), - ), pytest.raises(DockerError): + with ( + patch( + "supervisor.docker.manager.DockerAPI.containers", + new=PropertyMock(return_value=container_collection), + ), + patch( + "supervisor.docker.manager.DockerAPI.images", + new=PropertyMock(return_value=image_collection), + ), + pytest.raises(DockerError), + ): await coresys.homeassistant.core.instance.attach(AwesomeVersion("2022.7.3")) diff --git a/tests/docker/test_monitor.py b/tests/docker/test_monitor.py index b2ef457862a..fd9eddd1df2 100644 --- a/tests/docker/test_monitor.py +++ b/tests/docker/test_monitor.py @@ -90,10 +90,13 @@ async def test_events( event["Actor"]["Attributes"]["name"] = "some_container" event["id"] = "abc123" event["time"] = 123 - with patch( - "supervisor.docker.manager.DockerAPI.events", - new=PropertyMock(return_value=[event]), - ), patch.object(type(coresys.bus), "fire_event") as fire_event: + with ( + patch( + "supervisor.docker.manager.DockerAPI.events", + new=PropertyMock(return_value=[event]), + ), + patch.object(type(coresys.bus), "fire_event") as fire_event, + ): await coresys.docker.monitor.load() await asyncio.sleep(0.1) if expected: @@ -122,22 +125,25 @@ async def test_unlabeled_container(coresys: CoreSys): ): await coresys.homeassistant.core.instance.attach(AwesomeVersion("2022.7.3")) - with patch( - "supervisor.docker.manager.DockerAPI.events", - new=PropertyMock( - return_value=[ - { - "id": "abc123", - "time": 123, - "Type": "container", - "Action": "die", - "Actor": { - "Attributes": {"name": "homeassistant", "exitCode": "137"} - }, - } - ] + with ( + patch( + "supervisor.docker.manager.DockerAPI.events", + new=PropertyMock( + return_value=[ + { + "id": "abc123", + "time": 123, + "Type": "container", + "Action": "die", + "Actor": { + "Attributes": {"name": "homeassistant", "exitCode": "137"} + }, + } + ] + ), ), - ), patch.object(type(coresys.bus), "fire_event") as fire_event: + patch.object(type(coresys.bus), "fire_event") as fire_event, + ): await coresys.docker.monitor.load() await asyncio.sleep(0.1) fire_event.assert_called_once_with( diff --git a/tests/docker/test_stats.py b/tests/docker/test_stats.py index e0dca4a5872..f121fcfa281 100644 --- a/tests/docker/test_stats.py +++ b/tests/docker/test_stats.py @@ -1,4 +1,5 @@ """Test docker stats.""" + import pytest from supervisor.docker.stats import DockerStats diff --git a/tests/hardware/test_data.py b/tests/hardware/test_data.py index daac0adbf4e..39f13f05ab4 100644 --- a/tests/hardware/test_data.py +++ b/tests/hardware/test_data.py @@ -1,4 +1,5 @@ """Test HardwareManager Module.""" + from pathlib import Path from supervisor.hardware.data import Device diff --git a/tests/hardware/test_disk.py b/tests/hardware/test_disk.py index ad48b866531..d488dfbcab0 100644 --- a/tests/hardware/test_disk.py +++ b/tests/hardware/test_disk.py @@ -1,4 +1,5 @@ """Test hardware utils.""" + # pylint: disable=protected-access from pathlib import Path from unittest.mock import patch diff --git a/tests/hardware/test_helper.py b/tests/hardware/test_helper.py index 39907adf9d4..155ec3ba7ba 100644 --- a/tests/hardware/test_helper.py +++ b/tests/hardware/test_helper.py @@ -1,4 +1,5 @@ """Test hardware utils.""" + import errno from pathlib import Path from unittest.mock import MagicMock, patch diff --git a/tests/hardware/test_module.py b/tests/hardware/test_module.py index e68a160fc8b..be45bd78e02 100644 --- a/tests/hardware/test_module.py +++ b/tests/hardware/test_module.py @@ -1,4 +1,5 @@ """Test HardwareManager Module.""" + from pathlib import Path from supervisor.hardware.const import UdevSubsystem diff --git a/tests/hardware/test_policy.py b/tests/hardware/test_policy.py index 13d5d0154a7..db072efc6fd 100644 --- a/tests/hardware/test_policy.py +++ b/tests/hardware/test_policy.py @@ -1,4 +1,5 @@ """Test HardwareManager Module.""" + from pathlib import Path from supervisor.hardware.const import PolicyGroup diff --git a/tests/homeassistant/test_core.py b/tests/homeassistant/test_core.py index 036ecf7fd93..9f2b7cd62b4 100644 --- a/tests/homeassistant/test_core.py +++ b/tests/homeassistant/test_core.py @@ -31,16 +31,25 @@ async def test_update_fails_if_out_of_date(coresys: CoreSys): """Test update of Home Assistant fails when supervisor or plugin is out of date.""" coresys.hardware.disk.get_disk_free_space = lambda x: 5000 - with patch.object( - type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) - ), pytest.raises(HomeAssistantJobError): + with ( + patch.object( + type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) + ), + pytest.raises(HomeAssistantJobError), + ): await coresys.homeassistant.core.update() - with patch.object( - type(coresys.plugins.audio), "need_update", new=PropertyMock(return_value=True) - ), patch.object( - type(coresys.plugins.audio), "update", side_effect=AudioUpdateError - ), pytest.raises(HomeAssistantJobError): + with ( + patch.object( + type(coresys.plugins.audio), + "need_update", + new=PropertyMock(return_value=True), + ), + patch.object( + type(coresys.plugins.audio), "update", side_effect=AudioUpdateError + ), + pytest.raises(HomeAssistantJobError), + ): await coresys.homeassistant.core.update() @@ -49,15 +58,21 @@ async def test_install_landingpage_docker_error( ): """Test install landing page fails due to docker error.""" coresys.security.force = True - with patch.object( - DockerHomeAssistant, "attach", side_effect=DockerError - ), patch.object( - Updater, "image_homeassistant", new=PropertyMock(return_value="homeassistant") - ), patch.object( - DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) - ), patch("supervisor.homeassistant.core.asyncio.sleep") as sleep, patch( - "supervisor.security.module.cas_validate", - side_effect=[CodeNotaryError, None], + with ( + patch.object(DockerHomeAssistant, "attach", side_effect=DockerError), + patch.object( + Updater, + "image_homeassistant", + new=PropertyMock(return_value="homeassistant"), + ), + patch.object( + DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) + ), + patch("supervisor.homeassistant.core.asyncio.sleep") as sleep, + patch( + "supervisor.security.module.cas_validate", + side_effect=[CodeNotaryError, None], + ), ): await coresys.homeassistant.core.install_landingpage() sleep.assert_awaited_once_with(30) @@ -72,13 +87,18 @@ async def test_install_landingpage_other_error( """Test install landing page fails due to other error.""" coresys.docker.images.pull.side_effect = [(err := OSError()), MagicMock()] - with patch.object( - DockerHomeAssistant, "attach", side_effect=DockerError - ), patch.object( - Updater, "image_homeassistant", new=PropertyMock(return_value="homeassistant") - ), patch.object( - DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) - ), patch("supervisor.homeassistant.core.asyncio.sleep") as sleep: + with ( + patch.object(DockerHomeAssistant, "attach", side_effect=DockerError), + patch.object( + Updater, + "image_homeassistant", + new=PropertyMock(return_value="homeassistant"), + ), + patch.object( + DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) + ), + patch("supervisor.homeassistant.core.asyncio.sleep") as sleep, + ): await coresys.homeassistant.core.install_landingpage() sleep.assert_awaited_once_with(30) @@ -91,17 +111,25 @@ async def test_install_docker_error( ): """Test install fails due to docker error.""" coresys.security.force = True - with patch.object(HomeAssistantCore, "start"), patch.object( - DockerHomeAssistant, "cleanup" - ), patch.object( - Updater, "image_homeassistant", new=PropertyMock(return_value="homeassistant") - ), patch.object( - Updater, "version_homeassistant", new=PropertyMock(return_value="2022.7.3") - ), patch.object( - DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) - ), patch("supervisor.homeassistant.core.asyncio.sleep") as sleep, patch( - "supervisor.security.module.cas_validate", - side_effect=[CodeNotaryError, None], + with ( + patch.object(HomeAssistantCore, "start"), + patch.object(DockerHomeAssistant, "cleanup"), + patch.object( + Updater, + "image_homeassistant", + new=PropertyMock(return_value="homeassistant"), + ), + patch.object( + Updater, "version_homeassistant", new=PropertyMock(return_value="2022.7.3") + ), + patch.object( + DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) + ), + patch("supervisor.homeassistant.core.asyncio.sleep") as sleep, + patch( + "supervisor.security.module.cas_validate", + side_effect=[CodeNotaryError, None], + ), ): await coresys.homeassistant.core.install() sleep.assert_awaited_once_with(30) @@ -116,15 +144,22 @@ async def test_install_other_error( """Test install fails due to other error.""" coresys.docker.images.pull.side_effect = [(err := OSError()), MagicMock()] - with patch.object(HomeAssistantCore, "start"), patch.object( - DockerHomeAssistant, "cleanup" - ), patch.object( - Updater, "image_homeassistant", new=PropertyMock(return_value="homeassistant") - ), patch.object( - Updater, "version_homeassistant", new=PropertyMock(return_value="2022.7.3") - ), patch.object( - DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) - ), patch("supervisor.homeassistant.core.asyncio.sleep") as sleep: + with ( + patch.object(HomeAssistantCore, "start"), + patch.object(DockerHomeAssistant, "cleanup"), + patch.object( + Updater, + "image_homeassistant", + new=PropertyMock(return_value="homeassistant"), + ), + patch.object( + Updater, "version_homeassistant", new=PropertyMock(return_value="2022.7.3") + ), + patch.object( + DockerInterface, "arch", new=PropertyMock(return_value=CpuArch.AMD64) + ), + patch("supervisor.homeassistant.core.asyncio.sleep") as sleep, + ): await coresys.homeassistant.core.install() sleep.assert_awaited_once_with(30) @@ -149,13 +184,15 @@ async def test_start( else: coresys.docker.containers.get.side_effect = NotFound("missing") - with patch.object( - HomeAssistant, - "version", - new=PropertyMock(return_value=AwesomeVersion("2023.7.0")), - ), patch.object(DockerAPI, "run") as run, patch.object( - HomeAssistantCore, "_block_till_run" - ) as block_till_run: + with ( + patch.object( + HomeAssistant, + "version", + new=PropertyMock(return_value=AwesomeVersion("2023.7.0")), + ), + patch.object(DockerAPI, "run") as run, + patch.object(HomeAssistantCore, "_block_till_run") as block_till_run, + ): await coresys.homeassistant.core.start() block_till_run.assert_called_once() @@ -182,11 +219,14 @@ async def test_start_existing_container(coresys: CoreSys, path_extern): coresys.docker.containers.get.return_value.image.id = "123" coresys.docker.containers.get.return_value.status = "exited" - with patch.object( - HomeAssistant, - "version", - new=PropertyMock(return_value=AwesomeVersion("2023.7.0")), - ), patch.object(HomeAssistantCore, "_block_till_run") as block_till_run: + with ( + patch.object( + HomeAssistant, + "version", + new=PropertyMock(return_value=AwesomeVersion("2023.7.0")), + ), + patch.object(HomeAssistantCore, "_block_till_run") as block_till_run, + ): await coresys.homeassistant.core.start() block_till_run.assert_called_once() @@ -271,18 +311,19 @@ async def test_api_check_timeout( async def mock_instance_start(*_): container.status = "running" - with patch.object( - DockerHomeAssistant, "start", new=mock_instance_start - ), patch.object(DockerAPI, "container_is_initialized", return_value=True), travel( - datetime(2023, 10, 2, 0, 0, 0), tick=False - ) as traveller: + with ( + patch.object(DockerHomeAssistant, "start", new=mock_instance_start), + patch.object(DockerAPI, "container_is_initialized", return_value=True), + travel(datetime(2023, 10, 2, 0, 0, 0), tick=False) as traveller, + ): async def mock_sleep(*args): traveller.shift(timedelta(minutes=1)) - with patch( - "supervisor.homeassistant.core.asyncio.sleep", new=mock_sleep - ), pytest.raises(HomeAssistantCrashError): + with ( + patch("supervisor.homeassistant.core.asyncio.sleep", new=mock_sleep), + pytest.raises(HomeAssistantCrashError), + ): await coresys.homeassistant.core.start() assert coresys.homeassistant.api.get_api_state.call_count == 3 @@ -301,11 +342,11 @@ async def test_api_check_success( async def mock_instance_start(*_): container.status = "running" - with patch.object( - DockerHomeAssistant, "start", new=mock_instance_start - ), patch.object(DockerAPI, "container_is_initialized", return_value=True), travel( - datetime(2023, 10, 2, 0, 0, 0), tick=False - ) as traveller: + with ( + patch.object(DockerHomeAssistant, "start", new=mock_instance_start), + patch.object(DockerAPI, "container_is_initialized", return_value=True), + travel(datetime(2023, 10, 2, 0, 0, 0), tick=False) as traveller, + ): async def mock_sleep(*args): traveller.shift(timedelta(minutes=1)) diff --git a/tests/homeassistant/test_home_assistant_watchdog.py b/tests/homeassistant/test_home_assistant_watchdog.py index db22142d0de..ff5e117c5e1 100644 --- a/tests/homeassistant/test_home_assistant_watchdog.py +++ b/tests/homeassistant/test_home_assistant_watchdog.py @@ -1,4 +1,5 @@ """Test Home Assistant watchdog.""" + import asyncio from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch @@ -14,21 +15,24 @@ async def test_home_assistant_watchdog(coresys: CoreSys) -> None: """Test homeassistant watchdog works correctly.""" coresys.homeassistant.version = AwesomeVersion("2022.7.3") - with patch( - "supervisor.docker.interface.DockerInterface.version", - new=PropertyMock(return_value=AwesomeVersion("2022.7.3")), - ), patch.object(type(coresys.homeassistant.core.instance), "attach"): + with ( + patch( + "supervisor.docker.interface.DockerInterface.version", + new=PropertyMock(return_value=AwesomeVersion("2022.7.3")), + ), + patch.object(type(coresys.homeassistant.core.instance), "attach"), + ): await coresys.homeassistant.core.load() coresys.homeassistant.core.watchdog = True - with patch.object( - type(coresys.homeassistant.core), "restart" - ) as restart, patch.object( - type(coresys.homeassistant.core), "start" - ) as start, patch.object( - type(coresys.homeassistant.core.instance), "current_state" - ) as current_state: + with ( + patch.object(type(coresys.homeassistant.core), "restart") as restart, + patch.object(type(coresys.homeassistant.core), "start") as start, + patch.object( + type(coresys.homeassistant.core.instance), "current_state" + ) as current_state, + ): current_state.return_value = ContainerState.UNHEALTHY coresys.bus.fire_event( BusEvent.DOCKER_CONTAINER_STATE_CHANGE, @@ -106,22 +110,27 @@ async def test_home_assistant_watchdog(coresys: CoreSys) -> None: async def test_home_assistant_watchdog_rebuild_on_failure(coresys: CoreSys) -> None: """Test home assistant watchdog rebuilds if start fails.""" coresys.homeassistant.version = AwesomeVersion("2022.7.3") - with patch( - "supervisor.docker.interface.DockerInterface.version", - new=PropertyMock(return_value=AwesomeVersion("2022.7.3")), - ), patch.object(type(coresys.homeassistant.core.instance), "attach"): + with ( + patch( + "supervisor.docker.interface.DockerInterface.version", + new=PropertyMock(return_value=AwesomeVersion("2022.7.3")), + ), + patch.object(type(coresys.homeassistant.core.instance), "attach"), + ): await coresys.homeassistant.core.load() coresys.homeassistant.core.watchdog = True - with patch.object( - type(coresys.homeassistant.core), "start", side_effect=HomeAssistantError() - ) as start, patch.object( - type(coresys.homeassistant.core), "rebuild" - ) as rebuild, patch.object( - type(coresys.homeassistant.core.instance), - "current_state", - return_value=ContainerState.FAILED, + with ( + patch.object( + type(coresys.homeassistant.core), "start", side_effect=HomeAssistantError() + ) as start, + patch.object(type(coresys.homeassistant.core), "rebuild") as rebuild, + patch.object( + type(coresys.homeassistant.core.instance), + "current_state", + return_value=ContainerState.FAILED, + ), ): coresys.bus.fire_event( BusEvent.DOCKER_CONTAINER_STATE_CHANGE, @@ -149,12 +158,14 @@ async def test_home_assistant_watchdog_skip_on_load( coresys.bus.register_event(BusEvent.DOCKER_CONTAINER_STATE_CHANGE, events) coresys.homeassistant.version = AwesomeVersion("2022.7.3") - with patch( - "supervisor.docker.interface.DockerInterface.version", - new=PropertyMock(return_value=AwesomeVersion("2022.7.3")), - ), patch.object( - type(coresys.homeassistant.core), "restart" - ) as restart, patch.object(type(coresys.homeassistant.core), "start") as start: + with ( + patch( + "supervisor.docker.interface.DockerInterface.version", + new=PropertyMock(return_value=AwesomeVersion("2022.7.3")), + ), + patch.object(type(coresys.homeassistant.core), "restart") as restart, + patch.object(type(coresys.homeassistant.core), "start") as start, + ): await coresys.homeassistant.core.load() # No events should be raised on attach diff --git a/tests/homeassistant/test_module.py b/tests/homeassistant/test_module.py index 951f931a82d..f8f6f270842 100644 --- a/tests/homeassistant/test_module.py +++ b/tests/homeassistant/test_module.py @@ -54,8 +54,8 @@ async def test_load( async def test_get_users_none(coresys: CoreSys, ha_ws_client: AsyncMock): """Test get users returning none does not fail.""" ha_ws_client.async_send_command.return_value = None - assert [] == await coresys.homeassistant.get_users.__wrapped__( - coresys.homeassistant + assert ( + await coresys.homeassistant.get_users.__wrapped__(coresys.homeassistant) == [] ) diff --git a/tests/homeassistant/test_websocket.py b/tests/homeassistant/test_websocket.py index a5b636a63ba..e44ba366be0 100644 --- a/tests/homeassistant/test_websocket.py +++ b/tests/homeassistant/test_websocket.py @@ -1,4 +1,5 @@ """Test websocket.""" + # pylint: disable=protected-access, import-error import asyncio import logging diff --git a/tests/host/test_apparmor_control.py b/tests/host/test_apparmor_control.py index 41da7a898df..e328e84702f 100644 --- a/tests/host/test_apparmor_control.py +++ b/tests/host/test_apparmor_control.py @@ -13,8 +13,11 @@ async def test_load_profile_error(coresys: CoreSys): """Test error loading apparmor profile.""" test_path = Path("test") - with patch("supervisor.host.apparmor.validate_profile"), patch( - "supervisor.host.apparmor.shutil.copyfile", side_effect=(err := OSError()) + with ( + patch("supervisor.host.apparmor.validate_profile"), + patch( + "supervisor.host.apparmor.shutil.copyfile", side_effect=(err := OSError()) + ), ): err.errno = errno.EBUSY with raises(HostAppArmorError): diff --git a/tests/host/test_connectivity.py b/tests/host/test_connectivity.py index 5ea4bfffcea..72984be06dc 100644 --- a/tests/host/test_connectivity.py +++ b/tests/host/test_connectivity.py @@ -1,4 +1,5 @@ """Test supported features.""" + # pylint: disable=protected-access import asyncio from unittest.mock import PropertyMock, patch diff --git a/tests/host/test_info.py b/tests/host/test_info.py index 630780a3c22..7a25b4c4445 100644 --- a/tests/host/test_info.py +++ b/tests/host/test_info.py @@ -1,4 +1,5 @@ """Test host info.""" + from unittest.mock import patch from supervisor.host.info import InfoCenter diff --git a/tests/host/test_logs.py b/tests/host/test_logs.py index 312eeb2bd44..2017cc96bfc 100644 --- a/tests/host/test_logs.py +++ b/tests/host/test_logs.py @@ -48,9 +48,10 @@ async def test_logs(coresys: CoreSys, journald_gateway: MagicMock): == "2024-03-04 02:52:56.193 homeassistant systemd[1]: Started Hostname Service." ) - with patch.object( - LogsControl, "available", new=PropertyMock(return_value=False) - ), pytest.raises(HostNotSupportedError): + with ( + patch.object(LogsControl, "available", new=PropertyMock(return_value=False)), + pytest.raises(HostNotSupportedError), + ): async with coresys.host.logs.journald_logs(): pass diff --git a/tests/host/test_manager.py b/tests/host/test_manager.py index c21ac9e608d..b43963838cf 100644 --- a/tests/host/test_manager.py +++ b/tests/host/test_manager.py @@ -48,9 +48,10 @@ async def test_reload(coresys: CoreSys, systemd_service: SystemdService): await coresys.host.load() systemd_service.ListUnits.calls.clear() - with patch("supervisor.utils.dbus.DBus.connect") as connect, patch.object( - coresys.host.sound, "update" - ) as sound_update: + with ( + patch("supervisor.utils.dbus.DBus.connect") as connect, + patch.object(coresys.host.sound, "update") as sound_update, + ): await coresys.host.reload() connect.assert_not_called() diff --git a/tests/host/test_network.py b/tests/host/test_network.py index b5f08035c06..a4fc4a27a90 100644 --- a/tests/host/test_network.py +++ b/tests/host/test_network.py @@ -1,4 +1,5 @@ """Test network manager.""" + import asyncio from ipaddress import IPv4Address, IPv6Address from unittest.mock import AsyncMock, patch diff --git a/tests/jobs/test_job_decorator.py b/tests/jobs/test_job_decorator.py index 4356e7110fc..426973d7c75 100644 --- a/tests/jobs/test_job_decorator.py +++ b/tests/jobs/test_job_decorator.py @@ -1,4 +1,5 @@ """Test the condition decorators.""" + import asyncio from datetime import datetime, timedelta from unittest.mock import ANY, AsyncMock, Mock, PropertyMock, patch @@ -101,10 +102,11 @@ async def execute_system(self): mock_websession = AsyncMock() mock_websession.head.side_effect = head_side_effect coresys.supervisor.connectivity = None - with patch( - "supervisor.utils.dbus.DBus.call_dbus", return_value=connectivity - ), patch.object( - CoreSys, "websession", new=PropertyMock(return_value=mock_websession) + with ( + patch("supervisor.utils.dbus.DBus.call_dbus", return_value=connectivity), + patch.object( + CoreSys, "websession", new=PropertyMock(return_value=mock_websession) + ), ): assert await test.execute_host() is host_result assert await test.execute_system() is system_result @@ -502,10 +504,13 @@ async def execute(self) -> bool: ) assert await test.execute() - with patch.object( - PluginAudio, "need_update", new=PropertyMock(return_value=True) - ), patch.object( - PluginAudio, "update", side_effect=[AudioUpdateError, None, AudioUpdateError] + with ( + patch.object(PluginAudio, "need_update", new=PropertyMock(return_value=True)), + patch.object( + PluginAudio, + "update", + side_effect=[AudioUpdateError, None, AudioUpdateError], + ), ): assert not await test.execute() assert await test.execute() diff --git a/tests/misc/test_filter_data.py b/tests/misc/test_filter_data.py index 5d609c18926..5cb8e769569 100644 --- a/tests/misc/test_filter_data.py +++ b/tests/misc/test_filter_data.py @@ -1,4 +1,5 @@ """Test sentry data filter.""" + import os from unittest.mock import patch diff --git a/tests/misc/test_sanitise_url.py b/tests/misc/test_sanitise_url.py index 2041855fcd0..67a8a8d11a1 100644 --- a/tests/misc/test_sanitise_url.py +++ b/tests/misc/test_sanitise_url.py @@ -1,4 +1,5 @@ """Test supervisor.utils.sanitize_url.""" + from supervisor.misc.filter import sanitize_url diff --git a/tests/misc/test_scheduler.py b/tests/misc/test_scheduler.py index 4a9d246c362..8ae15eae428 100644 --- a/tests/misc/test_scheduler.py +++ b/tests/misc/test_scheduler.py @@ -1,4 +1,5 @@ """Test Supervisor scheduler backend.""" + import asyncio from supervisor.const import CoreState diff --git a/tests/misc/test_tasks.py b/tests/misc/test_tasks.py index 65071d45256..795ea994802 100644 --- a/tests/misc/test_tasks.py +++ b/tests/misc/test_tasks.py @@ -28,9 +28,10 @@ async def test_watchdog_homeassistant_api( tasks: Tasks, caplog: pytest.LogCaptureFixture ): """Test watchdog of homeassistant api.""" - with patch.object( - HomeAssistantAPI, "check_api_state", return_value=False - ), patch.object(HomeAssistantCore, "restart") as restart: + with ( + patch.object(HomeAssistantAPI, "check_api_state", return_value=False), + patch.object(HomeAssistantCore, "restart") as restart, + ): await tasks._watchdog_homeassistant_api() restart.assert_not_called() @@ -55,9 +56,10 @@ async def test_watchdog_homeassistant_api_off(tasks: Tasks, coresys: CoreSys): """Test watchdog of homeassistant api does not run when disabled.""" coresys.homeassistant.watchdog = False - with patch.object( - HomeAssistantAPI, "check_api_state", return_value=False - ), patch.object(HomeAssistantCore, "restart") as restart: + with ( + patch.object(HomeAssistantAPI, "check_api_state", return_value=False), + patch.object(HomeAssistantCore, "restart") as restart, + ): await tasks._watchdog_homeassistant_api() await tasks._watchdog_homeassistant_api() restart.assert_not_called() @@ -67,9 +69,10 @@ async def test_watchdog_homeassistant_api_error_state(tasks: Tasks, coresys: Cor """Test watchdog of homeassistant api does not restart when in error state.""" coresys.homeassistant.core._error_state = True - with patch.object( - HomeAssistantAPI, "check_api_state", return_value=False - ), patch.object(HomeAssistantCore, "restart") as restart: + with ( + patch.object(HomeAssistantAPI, "check_api_state", return_value=False), + patch.object(HomeAssistantCore, "restart") as restart, + ): await tasks._watchdog_homeassistant_api() await tasks._watchdog_homeassistant_api() restart.assert_not_called() @@ -79,9 +82,10 @@ async def test_watchdog_homeassistant_api_landing_page(tasks: Tasks, coresys: Co """Test watchdog of homeassistant api does not monitor landing page.""" coresys.homeassistant.version = LANDINGPAGE - with patch.object( - HomeAssistantAPI, "check_api_state", return_value=False - ), patch.object(HomeAssistantCore, "restart") as restart: + with ( + patch.object(HomeAssistantAPI, "check_api_state", return_value=False), + patch.object(HomeAssistantCore, "restart") as restart, + ): await tasks._watchdog_homeassistant_api() await tasks._watchdog_homeassistant_api() restart.assert_not_called() @@ -93,9 +97,10 @@ async def test_watchdog_homeassistant_api_not_running( """Test watchdog of homeassistant api does not monitor when home assistant not running.""" container.status = "stopped" - with patch.object( - HomeAssistantAPI, "check_api_state", return_value=False - ), patch.object(HomeAssistantCore, "restart") as restart: + with ( + patch.object(HomeAssistantAPI, "check_api_state", return_value=False), + patch.object(HomeAssistantCore, "restart") as restart, + ): await tasks._watchdog_homeassistant_api() await tasks._watchdog_homeassistant_api() restart.assert_not_called() @@ -105,13 +110,13 @@ async def test_watchdog_homeassistant_api_reanimation_limit( tasks: Tasks, caplog: pytest.LogCaptureFixture, capture_exception: Mock ): """Test watchdog of homeassistant api stops after max reanimation failures.""" - with patch.object( - HomeAssistantAPI, "check_api_state", return_value=False - ), patch.object( - HomeAssistantCore, "restart", side_effect=(err := HomeAssistantError()) - ) as restart, patch.object( - HomeAssistantCore, "rebuild", side_effect=err - ) as rebuild: + with ( + patch.object(HomeAssistantAPI, "check_api_state", return_value=False), + patch.object( + HomeAssistantCore, "restart", side_effect=(err := HomeAssistantError()) + ) as restart, + patch.object(HomeAssistantCore, "rebuild", side_effect=err) as rebuild, + ): for _ in range(5): await tasks._watchdog_homeassistant_api() restart.assert_not_called() diff --git a/tests/mounts/test_mount.py b/tests/mounts/test_mount.py index 48b4a601d82..ad0ac5296fb 100644 --- a/tests/mounts/test_mount.py +++ b/tests/mounts/test_mount.py @@ -1,4 +1,5 @@ """Tests for mounts.""" + from __future__ import annotations import asyncio diff --git a/tests/os/test_data_disk.py b/tests/os/test_data_disk.py index e70de2e60c7..5d3edd8f38b 100644 --- a/tests/os/test_data_disk.py +++ b/tests/os/test_data_disk.py @@ -312,8 +312,9 @@ async def test_datadisk_wipe_errors( system_service.ScheduleWipeDevice.calls.clear() system_service.response_schedule_wipe_device = True logind_service.side_effect_reboot = DBusError(ErrorType.FAILED, "fail") - with patch.object(Core, "shutdown"), pytest.raises( - HassOSError, match="Can't restart device" + with ( + patch.object(Core, "shutdown"), + pytest.raises(HassOSError, match="Can't restart device"), ): await coresys.os.datadisk.wipe_disk() diff --git a/tests/os/test_manager.py b/tests/os/test_manager.py index 4c5c067539d..c35ff2a6bf4 100644 --- a/tests/os/test_manager.py +++ b/tests/os/test_manager.py @@ -68,11 +68,15 @@ def test_ota_url_os_name_rel_5_downgrade(coresys: CoreSys) -> None: async def test_update_fails_if_out_of_date(coresys: CoreSys) -> None: """Test update of OS fails if Supervisor is out of date.""" coresys.core.state = CoreState.RUNNING - with patch.object( - type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) - ), patch.object( - type(coresys.os), "available", new=PropertyMock(return_value=True) - ), pytest.raises(HassOSJobError): + with ( + patch.object( + type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) + ), + patch.object( + type(coresys.os), "available", new=PropertyMock(return_value=True) + ), + pytest.raises(HassOSJobError), + ): await coresys.os.update() diff --git a/tests/plugins/test_audio.py b/tests/plugins/test_audio.py index 448d9b19800..fe418a675c4 100644 --- a/tests/plugins/test_audio.py +++ b/tests/plugins/test_audio.py @@ -1,4 +1,5 @@ """Test audio plugin.""" + import errno from pathlib import Path from unittest.mock import AsyncMock, Mock, patch @@ -13,9 +14,10 @@ @pytest.fixture(name="docker_interface") async def fixture_docker_interface() -> tuple[AsyncMock, AsyncMock]: """Mock docker interface methods.""" - with patch.object(DockerAudio, "run") as run, patch.object( - DockerAudio, "restart" - ) as restart: + with ( + patch.object(DockerAudio, "run") as run, + patch.object(DockerAudio, "restart") as restart, + ): yield (run, restart) @@ -63,9 +65,12 @@ async def test_load_error( coresys: CoreSys, caplog: pytest.LogCaptureFixture, container ): """Test error reading config file during load.""" - with patch( - "supervisor.plugins.audio.Path.read_text", side_effect=(err := OSError()) - ), patch("supervisor.plugins.audio.shutil.copy", side_effect=err): + with ( + patch( + "supervisor.plugins.audio.Path.read_text", side_effect=(err := OSError()) + ), + patch("supervisor.plugins.audio.shutil.copy", side_effect=err), + ): err.errno = errno.EBUSY await coresys.plugins.audio.load() diff --git a/tests/plugins/test_dns.py b/tests/plugins/test_dns.py index a112b54ec02..4c71da1b8a7 100644 --- a/tests/plugins/test_dns.py +++ b/tests/plugins/test_dns.py @@ -1,4 +1,5 @@ """Test DNS plugin.""" + import asyncio import errno from ipaddress import IPv4Address @@ -20,9 +21,10 @@ @pytest.fixture(name="docker_interface") async def fixture_docker_interface() -> tuple[AsyncMock, AsyncMock]: """Mock docker interface methods.""" - with patch.object(DockerDNS, "run") as run, patch.object( - DockerDNS, "restart" - ) as restart: + with ( + patch.object(DockerDNS, "run") as run, + patch.object(DockerDNS, "restart") as restart, + ): yield (run, restart) @@ -84,9 +86,10 @@ async def test_reset(coresys: CoreSys): coresys.plugins.dns._loop = True # pylint: disable=protected-access assert len(coresys.addons.installed) == 0 - with patch.object( - type(coresys.plugins.dns.hosts), "unlink" - ) as unlink, patch.object(type(coresys.plugins.dns), "write_hosts") as write_hosts: + with ( + patch.object(type(coresys.plugins.dns.hosts), "unlink") as unlink, + patch.object(type(coresys.plugins.dns), "write_hosts") as write_hosts, + ): await coresys.plugins.dns.reset() assert coresys.plugins.dns.servers == [] @@ -135,21 +138,28 @@ async def test_loop_detection_on_failure(coresys: CoreSys): assert len(coresys.resolution.issues) == 0 assert len(coresys.resolution.suggestions) == 0 - with patch.object(type(coresys.plugins.dns.instance), "attach"), patch.object( - type(coresys.plugins.dns.instance), - "is_running", - return_value=True, + with ( + patch.object(type(coresys.plugins.dns.instance), "attach"), + patch.object( + type(coresys.plugins.dns.instance), + "is_running", + return_value=True, + ), ): await coresys.plugins.dns.load() - with patch.object(type(coresys.plugins.dns), "rebuild") as rebuild, patch.object( - type(coresys.plugins.dns.instance), - "current_state", - side_effect=[ - ContainerState.FAILED, - ContainerState.FAILED, - ], - ), patch.object(type(coresys.plugins.dns.instance), "logs") as logs: + with ( + patch.object(type(coresys.plugins.dns), "rebuild") as rebuild, + patch.object( + type(coresys.plugins.dns.instance), + "current_state", + side_effect=[ + ContainerState.FAILED, + ContainerState.FAILED, + ], + ), + patch.object(type(coresys.plugins.dns.instance), "logs") as logs, + ): logs.return_value = b"" coresys.bus.fire_event( BusEvent.DOCKER_CONTAINER_STATE_CHANGE, @@ -190,9 +200,10 @@ async def test_load_error( coresys: CoreSys, caplog: pytest.LogCaptureFixture, container ): """Test error reading config files during load.""" - with patch( - "supervisor.plugins.dns.Path.read_text", side_effect=(err := OSError()) - ), patch("supervisor.plugins.dns.Path.write_text", side_effect=err): + with ( + patch("supervisor.plugins.dns.Path.read_text", side_effect=(err := OSError())), + patch("supervisor.plugins.dns.Path.write_text", side_effect=err), + ): err.errno = errno.EBUSY await coresys.plugins.dns.load() diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index 9143787ab36..0764c51119d 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -41,14 +41,16 @@ async def test_load(coresys: CoreSys): await coresys.updater.load() need_update = PropertyMock(return_value=True) - with patch.object(DockerInterface, "attach") as attach, patch.object( - DockerInterface, "update" - ) as update, patch.object(Supervisor, "need_update", new=need_update), patch.object( - PluginBase, "need_update", new=PropertyMock(return_value=True) - ), patch.object( - PluginBase, - "version", - new=PropertyMock(return_value=AwesomeVersion("1970-01-01")), + with ( + patch.object(DockerInterface, "attach") as attach, + patch.object(DockerInterface, "update") as update, + patch.object(Supervisor, "need_update", new=need_update), + patch.object(PluginBase, "need_update", new=PropertyMock(return_value=True)), + patch.object( + PluginBase, + "version", + new=PropertyMock(return_value=AwesomeVersion("1970-01-01")), + ), ): await coresys.plugins.load() diff --git a/tests/resolution/check/test_check.py b/tests/resolution/check/test_check.py index 7bf77b57cff..2595a6c8ade 100644 --- a/tests/resolution/check/test_check.py +++ b/tests/resolution/check/test_check.py @@ -1,4 +1,5 @@ """Test check.""" + # pylint: disable=import-error,protected-access from unittest.mock import AsyncMock, patch @@ -15,12 +16,15 @@ @pytest.fixture(autouse=True) def fixture_mock_dns_query(): """Mock aiodns query.""" - with patch( - "supervisor.resolution.checks.dns_server.DNSResolver.query", - new_callable=AsyncMock, - ), patch( - "supervisor.resolution.checks.dns_server_ipv6.DNSResolver.query", - new_callable=AsyncMock, + with ( + patch( + "supervisor.resolution.checks.dns_server.DNSResolver.query", + new_callable=AsyncMock, + ), + patch( + "supervisor.resolution.checks.dns_server_ipv6.DNSResolver.query", + new_callable=AsyncMock, + ), ): yield diff --git a/tests/resolution/check/test_check_addon_pwned.py b/tests/resolution/check/test_check_addon_pwned.py index aff246cbe5d..ec2c99a2fda 100644 --- a/tests/resolution/check/test_check_addon_pwned.py +++ b/tests/resolution/check/test_check_addon_pwned.py @@ -1,4 +1,5 @@ """Test Check Addon Pwned.""" + # pylint: disable=import-error,protected-access from unittest.mock import AsyncMock, patch diff --git a/tests/resolution/check/test_check_backups.py b/tests/resolution/check/test_check_backups.py index d0728b2d0e7..e39bc75ed30 100644 --- a/tests/resolution/check/test_check_backups.py +++ b/tests/resolution/check/test_check_backups.py @@ -1,4 +1,5 @@ """Test core version check.""" + # pylint: disable=import-error,protected-access from datetime import timedelta from unittest.mock import patch diff --git a/tests/resolution/check/test_check_core_security.py b/tests/resolution/check/test_check_core_security.py index 35be243cb8c..516231d3640 100644 --- a/tests/resolution/check/test_check_core_security.py +++ b/tests/resolution/check/test_check_core_security.py @@ -1,4 +1,5 @@ """Test core version check.""" + # pylint: disable=import-error,protected-access from pathlib import Path from unittest.mock import patch diff --git a/tests/resolution/check/test_check_detached_addon_missing.py b/tests/resolution/check/test_check_detached_addon_missing.py index 70a1a91bfa1..575539a2c53 100644 --- a/tests/resolution/check/test_check_detached_addon_missing.py +++ b/tests/resolution/check/test_check_detached_addon_missing.py @@ -1,4 +1,5 @@ """Test check for detached addons due to repo missing.""" + from unittest.mock import patch from supervisor.addons.addon import Addon diff --git a/tests/resolution/check/test_check_detached_addon_removed.py b/tests/resolution/check/test_check_detached_addon_removed.py index 0e7f2273576..be8b83cc92c 100644 --- a/tests/resolution/check/test_check_detached_addon_removed.py +++ b/tests/resolution/check/test_check_detached_addon_removed.py @@ -1,4 +1,5 @@ """Test check for detached addons due to removal from repo.""" + from pathlib import Path from unittest.mock import PropertyMock, patch diff --git a/tests/resolution/check/test_check_disabled_data_disk.py b/tests/resolution/check/test_check_disabled_data_disk.py index 2f9e400051c..1bb9a232a80 100644 --- a/tests/resolution/check/test_check_disabled_data_disk.py +++ b/tests/resolution/check/test_check_disabled_data_disk.py @@ -1,4 +1,5 @@ """Test check for disabled data disk.""" + # pylint: disable=import-error from dataclasses import replace from unittest.mock import patch diff --git a/tests/resolution/check/test_check_dns_server_failure.py b/tests/resolution/check/test_check_dns_server_failure.py index 68ed4f6d8b9..ae86fa32514 100644 --- a/tests/resolution/check/test_check_dns_server_failure.py +++ b/tests/resolution/check/test_check_dns_server_failure.py @@ -1,4 +1,5 @@ """Test check DNS Servers for failures.""" + from unittest.mock import AsyncMock, Mock, call, patch from aiodns.error import DNSError @@ -115,9 +116,10 @@ async def test_check_if_affected(coresys: CoreSys): ) assert len(coresys.resolution.issues) == 1 - with patch.object( - CheckDNSServer, "approve_check", return_value=True - ) as approve, patch.object(CheckDNSServer, "run_check", return_value=None) as check: + with ( + patch.object(CheckDNSServer, "approve_check", return_value=True) as approve, + patch.object(CheckDNSServer, "run_check", return_value=None) as check, + ): await dns_server() approve.assert_called_once() check.assert_called_once() diff --git a/tests/resolution/check/test_check_dns_server_ipv6_error.py b/tests/resolution/check/test_check_dns_server_ipv6_error.py index 744b249d986..6e193f68ec2 100644 --- a/tests/resolution/check/test_check_dns_server_ipv6_error.py +++ b/tests/resolution/check/test_check_dns_server_ipv6_error.py @@ -1,4 +1,5 @@ """Test check DNS Servers for IPv6 errors.""" + from unittest.mock import AsyncMock, Mock, call, patch from aiodns.error import DNSError @@ -126,11 +127,10 @@ async def test_check_if_affected(coresys: CoreSys): ) assert len(coresys.resolution.issues) == 1 - with patch.object( - CheckDNSServerIPv6, "approve_check", return_value=True - ) as approve, patch.object( - CheckDNSServerIPv6, "run_check", return_value=None - ) as check: + with ( + patch.object(CheckDNSServerIPv6, "approve_check", return_value=True) as approve, + patch.object(CheckDNSServerIPv6, "run_check", return_value=None) as check, + ): await dns_server_ipv6() approve.assert_called_once() check.assert_called_once() diff --git a/tests/resolution/check/test_check_free_space.py b/tests/resolution/check/test_check_free_space.py index 5ad14804ec7..1bcd461e568 100644 --- a/tests/resolution/check/test_check_free_space.py +++ b/tests/resolution/check/test_check_free_space.py @@ -1,4 +1,5 @@ """Test check free space fixup.""" + # pylint: disable=import-error,protected-access from unittest.mock import MagicMock, PropertyMock, patch diff --git a/tests/resolution/check/test_check_multiple_data_disks.py b/tests/resolution/check/test_check_multiple_data_disks.py index f18367daa37..b5bd8880709 100644 --- a/tests/resolution/check/test_check_multiple_data_disks.py +++ b/tests/resolution/check/test_check_multiple_data_disks.py @@ -1,4 +1,5 @@ """Test check for multiple data disks.""" + # pylint: disable=import-error from dataclasses import replace from unittest.mock import patch diff --git a/tests/resolution/check/test_check_network_interface_ipv4.py b/tests/resolution/check/test_check_network_interface_ipv4.py index ff8ba71b1bc..a6debf07b73 100644 --- a/tests/resolution/check/test_check_network_interface_ipv4.py +++ b/tests/resolution/check/test_check_network_interface_ipv4.py @@ -1,4 +1,5 @@ """Test Check Network Interface.""" + from unittest.mock import PropertyMock, patch import pytest diff --git a/tests/resolution/check/test_check_supervisor_trust.py b/tests/resolution/check/test_check_supervisor_trust.py index 80bd87b78e8..44a50d31c1b 100644 --- a/tests/resolution/check/test_check_supervisor_trust.py +++ b/tests/resolution/check/test_check_supervisor_trust.py @@ -1,4 +1,5 @@ """Test Check Supervisor trust.""" + # pylint: disable=import-error,protected-access from unittest.mock import AsyncMock, patch diff --git a/tests/resolution/evaluation/test_connectivity_check.py b/tests/resolution/evaluation/test_connectivity_check.py index b4774c752ca..e9850f2766a 100644 --- a/tests/resolution/evaluation/test_connectivity_check.py +++ b/tests/resolution/evaluation/test_connectivity_check.py @@ -1,4 +1,5 @@ """Test connectivity check evaluation.""" + from unittest.mock import PropertyMock, patch from supervisor.const import CoreState diff --git a/tests/resolution/evaluation/test_evaluate_apparmor.py b/tests/resolution/evaluation/test_evaluate_apparmor.py index 01d87ff191d..ef57db046de 100644 --- a/tests/resolution/evaluation/test_evaluate_apparmor.py +++ b/tests/resolution/evaluation/test_evaluate_apparmor.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access import errno from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_cgroup.py b/tests/resolution/evaluation/test_evaluate_cgroup.py index df9881bd726..e213ddde940 100644 --- a/tests/resolution/evaluation/test_evaluate_cgroup.py +++ b/tests/resolution/evaluation/test_evaluate_cgroup.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_container.py b/tests/resolution/evaluation/test_evaluate_container.py index ba36ae29570..59b4cdfb414 100644 --- a/tests/resolution/evaluation/test_evaluate_container.py +++ b/tests/resolution/evaluation/test_evaluate_container.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import MagicMock, patch diff --git a/tests/resolution/evaluation/test_evaluate_content_trust.py b/tests/resolution/evaluation/test_evaluate_content_trust.py index a1656fa67d2..47e7d41ec33 100644 --- a/tests/resolution/evaluation/test_evaluate_content_trust.py +++ b/tests/resolution/evaluation/test_evaluate_content_trust.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_dbus.py b/tests/resolution/evaluation/test_evaluate_dbus.py index c83dd36fa35..0073150bbd0 100644 --- a/tests/resolution/evaluation/test_evaluate_dbus.py +++ b/tests/resolution/evaluation/test_evaluate_dbus.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_dns_server.py b/tests/resolution/evaluation/test_evaluate_dns_server.py index da9017a41f6..f45399a6908 100644 --- a/tests/resolution/evaluation/test_evaluate_dns_server.py +++ b/tests/resolution/evaluation/test_evaluate_dns_server.py @@ -1,4 +1,5 @@ """Test DNS server evaluation.""" + from unittest.mock import patch from supervisor.const import CoreState diff --git a/tests/resolution/evaluation/test_evaluate_docker_configuration.py b/tests/resolution/evaluation/test_evaluate_docker_configuration.py index 31121ba70a4..f1317360bd7 100644 --- a/tests/resolution/evaluation/test_evaluate_docker_configuration.py +++ b/tests/resolution/evaluation/test_evaluate_docker_configuration.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_docker_version.py b/tests/resolution/evaluation/test_evaluate_docker_version.py index 9122279b603..efbe5ac105f 100644 --- a/tests/resolution/evaluation/test_evaluate_docker_version.py +++ b/tests/resolution/evaluation/test_evaluate_docker_version.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_job_conditions.py b/tests/resolution/evaluation/test_evaluate_job_conditions.py index 5fb68328416..9cb92b962b4 100644 --- a/tests/resolution/evaluation/test_evaluate_job_conditions.py +++ b/tests/resolution/evaluation/test_evaluate_job_conditions.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_lxc.py b/tests/resolution/evaluation/test_evaluate_lxc.py index 12a960c68a8..4c950819d34 100644 --- a/tests/resolution/evaluation/test_evaluate_lxc.py +++ b/tests/resolution/evaluation/test_evaluate_lxc.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from pathlib import Path from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_network_manager.py b/tests/resolution/evaluation/test_evaluate_network_manager.py index 29a645923e8..6df61d758f3 100644 --- a/tests/resolution/evaluation/test_evaluate_network_manager.py +++ b/tests/resolution/evaluation/test_evaluate_network_manager.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_operating_system.py b/tests/resolution/evaluation/test_evaluate_operating_system.py index 53d26d66c11..d2b764d2a7b 100644 --- a/tests/resolution/evaluation/test_evaluate_operating_system.py +++ b/tests/resolution/evaluation/test_evaluate_operating_system.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import MagicMock, patch diff --git a/tests/resolution/evaluation/test_evaluate_os_agent.py b/tests/resolution/evaluation/test_evaluate_os_agent.py index 90b6699fc35..4b480e6fb91 100644 --- a/tests/resolution/evaluation/test_evaluate_os_agent.py +++ b/tests/resolution/evaluation/test_evaluate_os_agent.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import MagicMock, patch diff --git a/tests/resolution/evaluation/test_evaluate_privileged.py b/tests/resolution/evaluation/test_evaluate_privileged.py index ee1971a44e1..69b97133ba5 100644 --- a/tests/resolution/evaluation/test_evaluate_privileged.py +++ b/tests/resolution/evaluation/test_evaluate_privileged.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/evaluation/test_evaluate_source_mods.py b/tests/resolution/evaluation/test_evaluate_source_mods.py index 1e7f0223d70..3bede779938 100644 --- a/tests/resolution/evaluation/test_evaluate_source_mods.py +++ b/tests/resolution/evaluation/test_evaluate_source_mods.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access import errno import os diff --git a/tests/resolution/evaluation/test_evaluate_systemd.py b/tests/resolution/evaluation/test_evaluate_systemd.py index 5bbc370451d..dab30e65c54 100644 --- a/tests/resolution/evaluation/test_evaluate_systemd.py +++ b/tests/resolution/evaluation/test_evaluate_systemd.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import MagicMock, patch diff --git a/tests/resolution/evaluation/test_evaluate_systemd_journal.py b/tests/resolution/evaluation/test_evaluate_systemd_journal.py index 7c1b53c47e1..0d00e1eedce 100644 --- a/tests/resolution/evaluation/test_evaluate_systemd_journal.py +++ b/tests/resolution/evaluation/test_evaluate_systemd_journal.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import MagicMock, patch diff --git a/tests/resolution/evaluation/test_evaluation.py b/tests/resolution/evaluation/test_evaluation.py index 6650e7c5e7e..dd654ccec38 100644 --- a/tests/resolution/evaluation/test_evaluation.py +++ b/tests/resolution/evaluation/test_evaluation.py @@ -1,4 +1,5 @@ """Test evaluation.""" + # pylint: disable=import-error from unittest.mock import patch @@ -10,22 +11,28 @@ async def test_evaluation_initialize(coresys: CoreSys): """Test evaluation for initialize.""" coresys.core.state = CoreState.INITIALIZE - with patch( - "supervisor.resolution.evaluations.dbus.EvaluateDbus.evaluate", - return_value=False, - ) as dbus, patch( - "supervisor.resolution.evaluations.lxc.EvaluateLxc.evaluate", - return_value=False, - ) as lxc, patch( - "supervisor.resolution.evaluations.privileged.EvaluatePrivileged.evaluate", - return_value=False, - ) as privileged, patch( - "supervisor.resolution.evaluations.docker_configuration.EvaluateDockerConfiguration.evaluate", - return_value=False, - ) as docker_configuration, patch( - "supervisor.resolution.evaluations.docker_version.EvaluateDockerVersion.evaluate", - return_value=False, - ) as docker_version: + with ( + patch( + "supervisor.resolution.evaluations.dbus.EvaluateDbus.evaluate", + return_value=False, + ) as dbus, + patch( + "supervisor.resolution.evaluations.lxc.EvaluateLxc.evaluate", + return_value=False, + ) as lxc, + patch( + "supervisor.resolution.evaluations.privileged.EvaluatePrivileged.evaluate", + return_value=False, + ) as privileged, + patch( + "supervisor.resolution.evaluations.docker_configuration.EvaluateDockerConfiguration.evaluate", + return_value=False, + ) as docker_configuration, + patch( + "supervisor.resolution.evaluations.docker_version.EvaluateDockerVersion.evaluate", + return_value=False, + ) as docker_version, + ): await coresys.resolution.evaluate.evaluate_system() dbus.assert_called_once() lxc.assert_called_once() @@ -37,16 +44,20 @@ async def test_evaluation_initialize(coresys: CoreSys): async def test_evaluation_setup(coresys: CoreSys): """Test evaluation for setup.""" coresys.core.state = CoreState.SETUP - with patch( - "supervisor.resolution.evaluations.operating_system.EvaluateOperatingSystem.evaluate", - return_value=False, - ) as operating_system, patch( - "supervisor.resolution.evaluations.network_manager.EvaluateNetworkManager.evaluate", - return_value=False, - ) as network_manager, patch( - "supervisor.resolution.evaluations.systemd.EvaluateSystemd.evaluate", - return_value=False, - ) as systemd: + with ( + patch( + "supervisor.resolution.evaluations.operating_system.EvaluateOperatingSystem.evaluate", + return_value=False, + ) as operating_system, + patch( + "supervisor.resolution.evaluations.network_manager.EvaluateNetworkManager.evaluate", + return_value=False, + ) as network_manager, + patch( + "supervisor.resolution.evaluations.systemd.EvaluateSystemd.evaluate", + return_value=False, + ) as systemd, + ): await coresys.resolution.evaluate.evaluate_system() operating_system.assert_called_once() network_manager.assert_called_once() @@ -56,13 +67,16 @@ async def test_evaluation_setup(coresys: CoreSys): async def test_evaluation_running(coresys: CoreSys): """Test evaluation for running.""" coresys.core.state = CoreState.RUNNING - with patch( - "supervisor.resolution.evaluations.container.EvaluateContainer.evaluate", - return_value=False, - ) as container, patch( - "supervisor.resolution.evaluations.network_manager.EvaluateNetworkManager.evaluate", - return_value=False, - ) as network_manager: + with ( + patch( + "supervisor.resolution.evaluations.container.EvaluateContainer.evaluate", + return_value=False, + ) as container, + patch( + "supervisor.resolution.evaluations.network_manager.EvaluateNetworkManager.evaluate", + return_value=False, + ) as network_manager, + ): await coresys.resolution.evaluate.evaluate_system() container.assert_called_once() network_manager.assert_called_once() diff --git a/tests/resolution/fixup/test_addon_execute_rebuild.py b/tests/resolution/fixup/test_addon_execute_rebuild.py index 2ebe1abefc2..c3104248bd9 100644 --- a/tests/resolution/fixup/test_addon_execute_rebuild.py +++ b/tests/resolution/fixup/test_addon_execute_rebuild.py @@ -97,9 +97,10 @@ async def test_fixup_unknown_core( reference="local_ssh", suggestions=[SuggestionType.EXECUTE_REBUILD], ) - with patch.object(Addon, "restart") as restart, patch.object( - DockerInterface, "stop" - ) as stop: + with ( + patch.object(Addon, "restart") as restart, + patch.object(DockerInterface, "stop") as stop, + ): await addon_execute_rebuild() restart.assert_not_called() stop.assert_not_called() diff --git a/tests/resolution/fixup/test_addon_execute_remove.py b/tests/resolution/fixup/test_addon_execute_remove.py index 9ca20c054bf..60376fc6d06 100644 --- a/tests/resolution/fixup/test_addon_execute_remove.py +++ b/tests/resolution/fixup/test_addon_execute_remove.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + from unittest.mock import patch from supervisor.addons.addon import Addon diff --git a/tests/resolution/fixup/test_core_execute_rebuild.py b/tests/resolution/fixup/test_core_execute_rebuild.py index 33f0ddb649f..2c4c232e7fb 100644 --- a/tests/resolution/fixup/test_core_execute_rebuild.py +++ b/tests/resolution/fixup/test_core_execute_rebuild.py @@ -82,9 +82,10 @@ async def test_fixup_unknown_core( ContextType.CORE, suggestions=[SuggestionType.EXECUTE_REBUILD], ) - with patch.object(HomeAssistantCore, "rebuild") as rebuild, patch.object( - DockerInterface, "stop" - ) as stop: + with ( + patch.object(HomeAssistantCore, "rebuild") as rebuild, + patch.object(DockerInterface, "stop") as stop, + ): await core_execute_rebuild() rebuild.assert_not_called() stop.assert_not_called() diff --git a/tests/resolution/fixup/test_fixup.py b/tests/resolution/fixup/test_fixup.py index fa53a0014c3..3cb6bb29eeb 100644 --- a/tests/resolution/fixup/test_fixup.py +++ b/tests/resolution/fixup/test_fixup.py @@ -1,4 +1,5 @@ """Test check.""" + # pylint: disable=import-error, protected-access from unittest.mock import AsyncMock, patch diff --git a/tests/resolution/fixup/test_store_execute_reload.py b/tests/resolution/fixup/test_store_execute_reload.py index 5ecd7e61283..13ce93bf487 100644 --- a/tests/resolution/fixup/test_store_execute_reload.py +++ b/tests/resolution/fixup/test_store_execute_reload.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import AsyncMock, patch diff --git a/tests/resolution/fixup/test_store_execute_remove.py b/tests/resolution/fixup/test_store_execute_remove.py index bc43e05c96f..552a46e2aa7 100644 --- a/tests/resolution/fixup/test_store_execute_remove.py +++ b/tests/resolution/fixup/test_store_execute_remove.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from unittest.mock import patch diff --git a/tests/resolution/fixup/test_store_execute_reset.py b/tests/resolution/fixup/test_store_execute_reset.py index 9137f887734..8a7a0360399 100644 --- a/tests/resolution/fixup/test_store_execute_reset.py +++ b/tests/resolution/fixup/test_store_execute_reset.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from pathlib import Path from unittest.mock import AsyncMock, patch diff --git a/tests/resolution/fixup/test_system_clear_full_backup.py b/tests/resolution/fixup/test_system_clear_full_backup.py index dbb4899e78c..710050f113f 100644 --- a/tests/resolution/fixup/test_system_clear_full_backup.py +++ b/tests/resolution/fixup/test_system_clear_full_backup.py @@ -1,4 +1,5 @@ """Test clear full backup fixup.""" + # pylint: disable=import-error,protected-access from supervisor.backups.backup import Backup from supervisor.backups.const import BackupType diff --git a/tests/resolution/fixup/test_system_create_full_backup.py b/tests/resolution/fixup/test_system_create_full_backup.py index 3f0a97262de..ac017ca0f4a 100644 --- a/tests/resolution/fixup/test_system_create_full_backup.py +++ b/tests/resolution/fixup/test_system_create_full_backup.py @@ -1,4 +1,5 @@ """Test create full backup fixup.""" + # pylint: disable=import-error,protected-access from unittest.mock import AsyncMock diff --git a/tests/resolution/fixup/test_system_execute_integrity.py b/tests/resolution/fixup/test_system_execute_integrity.py index 72883c63f0b..8bc04e026a5 100644 --- a/tests/resolution/fixup/test_system_execute_integrity.py +++ b/tests/resolution/fixup/test_system_execute_integrity.py @@ -1,4 +1,5 @@ """Test evaluation base.""" + # pylint: disable=import-error,protected-access from datetime import timedelta from unittest.mock import AsyncMock diff --git a/tests/resolution/fixup/test_system_execute_rebuild.py b/tests/resolution/fixup/test_system_execute_rebuild.py index aa604a6967c..c9da5c2272d 100644 --- a/tests/resolution/fixup/test_system_execute_rebuild.py +++ b/tests/resolution/fixup/test_system_execute_rebuild.py @@ -42,13 +42,11 @@ async def test_fixup(coresys: CoreSys): ContextType.SYSTEM, suggestions=[SuggestionType.EXECUTE_REBUILD], ) - with patch.object( - FixupAddonExecuteRebuild, "process_fixup" - ) as addon_fixup, patch.object( - FixupCoreExecuteRebuild, "process_fixup" - ) as core_fixup, patch.object( - FixupPluginExecuteRebuild, "process_fixup" - ) as plugin_fixup: + with ( + patch.object(FixupAddonExecuteRebuild, "process_fixup") as addon_fixup, + patch.object(FixupCoreExecuteRebuild, "process_fixup") as core_fixup, + patch.object(FixupPluginExecuteRebuild, "process_fixup") as plugin_fixup, + ): await system_execute_rebuild() addon_fixup.assert_called_once_with(reference="local_ssh") core_fixup.assert_called_once() diff --git a/tests/resolution/fixup/test_system_rename_data_disk.py b/tests/resolution/fixup/test_system_rename_data_disk.py index 6355be32ebb..d2ad03fc00f 100644 --- a/tests/resolution/fixup/test_system_rename_data_disk.py +++ b/tests/resolution/fixup/test_system_rename_data_disk.py @@ -1,4 +1,5 @@ """Test system fixup rename data disk.""" + # pylint: disable=import-error from dbus_fast import Variant import pytest diff --git a/tests/resolution/test_check.py b/tests/resolution/test_check.py index ec201804656..0a3b2851bbd 100644 --- a/tests/resolution/test_check.py +++ b/tests/resolution/test_check.py @@ -12,8 +12,9 @@ async def test_check_system_error(coresys: CoreSys, capture_exception: Mock): """Test error while checking system.""" coresys.core.state = CoreState.STARTUP - with patch.object(CheckCoreSecurity, "run_check", side_effect=ValueError), patch( - "shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3)) + with ( + patch.object(CheckCoreSecurity, "run_check", side_effect=ValueError), + patch("shutil.disk_usage", return_value=(42, 42, 2 * (1024.0**3))), ): await coresys.resolution.check.check_system() diff --git a/tests/resolution/test_resolution_manager.py b/tests/resolution/test_resolution_manager.py index 3f928aedc6b..183412add28 100644 --- a/tests/resolution/test_resolution_manager.py +++ b/tests/resolution/test_resolution_manager.py @@ -1,4 +1,5 @@ """Tests for resolution manager.""" + import asyncio from typing import Any from unittest.mock import AsyncMock, patch diff --git a/tests/security/test_module.py b/tests/security/test_module.py index f80f932326b..ece4860552c 100644 --- a/tests/security/test_module.py +++ b/tests/security/test_module.py @@ -1,4 +1,5 @@ """Testing handling with Security.""" + from unittest.mock import AsyncMock, patch import pytest @@ -52,10 +53,13 @@ async def test_force_content_trust(coresys: CoreSys): coresys.security.force = True - with patch( - "supervisor.security.module.cas_validate", - AsyncMock(side_effect=CodeNotaryError), - ) as cas_validate, pytest.raises(CodeNotaryError): + with ( + patch( + "supervisor.security.module.cas_validate", + AsyncMock(side_effect=CodeNotaryError), + ) as cas_validate, + pytest.raises(CodeNotaryError), + ): await coresys.security.verify_content("test@mail.com", "ffffffffffffff") diff --git a/tests/store/test_custom_repository.py b/tests/store/test_custom_repository.py index 1f3dc40a185..11aef5499e8 100644 --- a/tests/store/test_custom_repository.py +++ b/tests/store/test_custom_repository.py @@ -1,4 +1,5 @@ """Test add custom repository.""" + import json from unittest.mock import PropertyMock, patch @@ -25,10 +26,14 @@ async def test_add_valid_repository( ): """Test add custom repository.""" current = coresys.store.repository_urls - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "supervisor.utils.common.read_yaml_file", - return_value={"name": "Awesome repository"}, - ), patch("pathlib.Path.exists", return_value=True): + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch( + "supervisor.utils.common.read_yaml_file", + return_value={"name": "Awesome repository"}, + ), + patch("pathlib.Path.exists", return_value=True), + ): if use_update: await store_manager.update_repositories(current + ["http://example.com"]) else: @@ -42,9 +47,12 @@ async def test_add_valid_repository( async def test_add_invalid_repository(coresys: CoreSys, store_manager: StoreManager): """Test add invalid custom repository.""" current = coresys.store.repository_urls - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "pathlib.Path.read_text", - return_value="", + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch( + "pathlib.Path.read_text", + return_value="", + ), ): await store_manager.update_repositories( current + ["http://example.com"], add_with_errors=True @@ -62,10 +70,14 @@ async def test_error_on_invalid_repository( ): """Test invalid repository not added.""" current = coresys.store.repository_urls - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "pathlib.Path.read_text", - return_value="", - ), pytest.raises(StoreError): + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch( + "pathlib.Path.read_text", + return_value="", + ), + pytest.raises(StoreError), + ): if use_update: await store_manager.update_repositories(current + ["http://example.com"]) else: @@ -82,10 +94,14 @@ async def test_add_invalid_repository_file( ): """Test add invalid custom repository file.""" current = coresys.store.repository_urls - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "pathlib.Path.read_text", - return_value=json.dumps({"name": "Awesome repository"}), - ), patch("pathlib.Path.exists", return_value=False): + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch( + "pathlib.Path.read_text", + return_value=json.dumps({"name": "Awesome repository"}), + ), + patch("pathlib.Path.exists", return_value=False), + ): await store_manager.update_repositories( current + ["http://example.com"], add_with_errors=True ) @@ -138,9 +154,10 @@ async def test_error_on_repository_with_git_error( ): """Test repo not added on git error.""" current = coresys.store.repository_urls - with patch( - "supervisor.store.repository.Repository.load", side_effect=git_error - ), pytest.raises(StoreError): + with ( + patch("supervisor.store.repository.Repository.load", side_effect=git_error), + pytest.raises(StoreError), + ): if use_update: await store_manager.update_repositories(current + ["http://example.com"]) else: @@ -225,10 +242,13 @@ async def test_update_partial_error(coresys: CoreSys, store_manager: StoreManage current = coresys.store.repository_urls initial = len(current) - with patch( - "supervisor.store.repository.Repository.load", - side_effect=[None, StoreGitError()], - ), pytest.raises(StoreError): + with ( + patch( + "supervisor.store.repository.Repository.load", + side_effect=[None, StoreGitError()], + ), + pytest.raises(StoreError), + ): await store_manager.update_repositories( current + ["http://example.com", "http://example2.com"] ) @@ -242,11 +262,11 @@ async def test_error_adding_duplicate( ): """Test adding a duplicate repository causes an error.""" assert repository.source in coresys.store.repository_urls - with patch( - "supervisor.store.repository.Repository.validate", return_value=True - ), patch( - "supervisor.store.repository.Repository.load", return_value=None - ), pytest.raises(StoreError): + with ( + patch("supervisor.store.repository.Repository.validate", return_value=True), + patch("supervisor.store.repository.Repository.load", return_value=None), + pytest.raises(StoreError), + ): await store_manager.add_repository(repository.source) @@ -257,10 +277,14 @@ async def test_add_with_update_repositories( assert repository.source in coresys.store.repository_urls assert "http://example.com" not in coresys.store.repository_urls - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "supervisor.utils.common.read_yaml_file", - return_value={"name": "Awesome repository"}, - ), patch("pathlib.Path.exists", return_value=True): + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch( + "supervisor.utils.common.read_yaml_file", + return_value={"name": "Awesome repository"}, + ), + patch("pathlib.Path.exists", return_value=True), + ): await store_manager.update_repositories(["http://example.com"], replace=False) assert repository.source in coresys.store.repository_urls @@ -272,9 +296,12 @@ async def test_add_repository_fails_if_out_of_date( coresys: CoreSys, store_manager: StoreManager, use_update: bool ): """Test adding a repository fails when supervisor not updated.""" - with patch.object( - type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) - ), pytest.raises(StoreJobError): + with ( + patch.object( + type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) + ), + pytest.raises(StoreJobError), + ): if use_update: await store_manager.update_repositories( coresys.store.repository_urls + ["http://example.com"], @@ -288,12 +315,13 @@ async def test_repositories_loaded_ignore_updates( coresys: CoreSys, store_manager: StoreManager, need_update: bool ): """Test repositories loaded whether or not supervisor needs an update.""" - with patch( - "supervisor.store.repository.Repository.load", return_value=None - ), patch.object( - type(coresys.supervisor), - "need_update", - new=PropertyMock(return_value=need_update), + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch.object( + type(coresys.supervisor), + "need_update", + new=PropertyMock(return_value=need_update), + ), ): await store_manager.load() diff --git a/tests/store/test_reading_addons.py b/tests/store/test_reading_addons.py index aba5f8b0b62..40d21dd406b 100644 --- a/tests/store/test_reading_addons.py +++ b/tests/store/test_reading_addons.py @@ -1,4 +1,5 @@ """Test that we are reading add-on files correctly.""" + import errno from pathlib import Path from unittest.mock import patch diff --git a/tests/store/test_repository_git.py b/tests/store/test_repository_git.py index 54c14ddc4ff..09c7c185092 100644 --- a/tests/store/test_repository_git.py +++ b/tests/store/test_repository_git.py @@ -1,4 +1,5 @@ """Test git repository.""" + from __future__ import annotations from pathlib import Path @@ -68,9 +69,12 @@ async def test_git_load(coresys: CoreSys, tmp_path: Path): """Test git load.""" repo = GitRepo(coresys, tmp_path, REPO_URL) - with patch("pathlib.Path.is_dir", return_value=True), patch.object( - GitRepo, "sys_run_in_executor", new_callable=AsyncMock - ) as run_in_executor: + with ( + patch("pathlib.Path.is_dir", return_value=True), + patch.object( + GitRepo, "sys_run_in_executor", new_callable=AsyncMock + ) as run_in_executor, + ): await repo.load() assert run_in_executor.call_count == 2 @@ -90,9 +94,13 @@ async def test_git_load_error(coresys: CoreSys, tmp_path: Path, git_errors: Exce """Test git load error.""" repo = GitRepo(coresys, tmp_path, REPO_URL) - with patch("pathlib.Path.is_dir", return_value=True), patch.object( - GitRepo, "sys_run_in_executor", new_callable=AsyncMock - ) as run_in_executor, pytest.raises(StoreGitError): + with ( + patch("pathlib.Path.is_dir", return_value=True), + patch.object( + GitRepo, "sys_run_in_executor", new_callable=AsyncMock + ) as run_in_executor, + pytest.raises(StoreGitError), + ): run_in_executor.side_effect = git_errors await repo.load() diff --git a/tests/store/test_store_manager.py b/tests/store/test_store_manager.py index e2b1831fcff..3abb97e6aa8 100644 --- a/tests/store/test_store_manager.py +++ b/tests/store/test_store_manager.py @@ -1,4 +1,5 @@ """Test store manager.""" + from typing import Any from unittest.mock import PropertyMock, patch @@ -30,12 +31,11 @@ async def mock_refresh_cache(obj: AddonStore): nonlocal refresh_cache_calls refresh_cache_calls.add(obj.slug) - with patch( - "supervisor.store.repository.Repository.load", return_value=None - ), patch.object( - type(coresys.config), "addons_repositories", return_value=[] - ), patch("pathlib.Path.exists", return_value=True), patch.object( - AddonStore, "refresh_path_cache", new=mock_refresh_cache + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch.object(type(coresys.config), "addons_repositories", return_value=[]), + patch("pathlib.Path.exists", return_value=True), + patch.object(AddonStore, "refresh_path_cache", new=mock_refresh_cache), ): await store_manager.load() @@ -65,20 +65,21 @@ async def test_load_with_custom_repository(coresys: CoreSys): async def mock_refresh_cache(_): pass - with patch( - "supervisor.utils.common.read_json_or_yaml_file", - return_value={"repositories": ["http://example.com"]}, - ), patch("pathlib.Path.is_file", return_value=True): + with ( + patch( + "supervisor.utils.common.read_json_or_yaml_file", + return_value={"repositories": ["http://example.com"]}, + ), + patch("pathlib.Path.is_file", return_value=True), + ): store_manager = StoreManager(coresys) - with patch( - "supervisor.store.repository.Repository.load", return_value=None - ), patch.object( - type(coresys.config), "addons_repositories", return_value=[] - ), patch( - "supervisor.store.repository.Repository.validate", return_value=True - ), patch("pathlib.Path.exists", return_value=True), patch.object( - AddonStore, "refresh_path_cache", new=mock_refresh_cache + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch.object(type(coresys.config), "addons_repositories", return_value=[]), + patch("supervisor.store.repository.Repository.validate", return_value=True), + patch("pathlib.Path.exists", return_value=True), + patch.object(AddonStore, "refresh_path_cache", new=mock_refresh_cache), ): await store_manager.load() @@ -109,9 +110,11 @@ async def test_load_from_core_config(coresys: CoreSys): migrate_system_env(coresys) - with patch("supervisor.store.repository.Repository.load", return_value=None), patch( - "supervisor.store.repository.Repository.validate", return_value=True - ), patch("pathlib.Path.exists", return_value=True): + with ( + patch("supervisor.store.repository.Repository.load", return_value=None), + patch("supervisor.store.repository.Repository.validate", return_value=True), + patch("pathlib.Path.exists", return_value=True), + ): await coresys.store.load() assert len(coresys.store.all) == 6 @@ -140,9 +143,12 @@ async def test_load_from_core_config(coresys: CoreSys): async def test_reload_fails_if_out_of_date(coresys: CoreSys): """Test reload fails when supervisor not updated.""" - with patch.object( - type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) - ), pytest.raises(StoreJobError): + with ( + patch.object( + type(coresys.supervisor), "need_update", new=PropertyMock(return_value=True) + ), + pytest.raises(StoreJobError), + ): await coresys.store.reload() @@ -181,17 +187,18 @@ async def test_update_unavailable_addon( **config, ) - with patch.object(BackupManager, "do_backup_partial") as backup, patch.object( - AddonStore, "data", new=PropertyMock(return_value=addon_config) - ), patch.object( - CpuArch, "supported", new=PropertyMock(return_value=["amd64"]) - ), patch.object( - CoreSys, "machine", new=PropertyMock(return_value="qemux86-64") - ), patch.object( - HomeAssistant, - "version", - new=PropertyMock(return_value=AwesomeVersion("2022.1.1")), - ), patch("shutil.disk_usage", return_value=(42, 42, (1024.0**3))): + with ( + patch.object(BackupManager, "do_backup_partial") as backup, + patch.object(AddonStore, "data", new=PropertyMock(return_value=addon_config)), + patch.object(CpuArch, "supported", new=PropertyMock(return_value=["amd64"])), + patch.object(CoreSys, "machine", new=PropertyMock(return_value="qemux86-64")), + patch.object( + HomeAssistant, + "version", + new=PropertyMock(return_value=AwesomeVersion("2022.1.1")), + ), + patch("shutil.disk_usage", return_value=(42, 42, (1024.0**3))), + ): with pytest.raises(AddonsNotSupportedError): await coresys.addons.update("local_ssh", backup=True) @@ -235,18 +242,17 @@ async def test_install_unavailable_addon( **config, ) - with patch.object( - AddonStore, "data", new=PropertyMock(return_value=addon_config) - ), patch.object( - CpuArch, "supported", new=PropertyMock(return_value=["amd64"]) - ), patch.object( - CoreSys, "machine", new=PropertyMock(return_value="qemux86-64") - ), patch.object( - HomeAssistant, - "version", - new=PropertyMock(return_value=AwesomeVersion("2022.1.1")), - ), patch("shutil.disk_usage", return_value=(42, 42, (1024.0**3))), pytest.raises( - AddonsNotSupportedError + with ( + patch.object(AddonStore, "data", new=PropertyMock(return_value=addon_config)), + patch.object(CpuArch, "supported", new=PropertyMock(return_value=["amd64"])), + patch.object(CoreSys, "machine", new=PropertyMock(return_value="qemux86-64")), + patch.object( + HomeAssistant, + "version", + new=PropertyMock(return_value=AwesomeVersion("2022.1.1")), + ), + patch("shutil.disk_usage", return_value=(42, 42, (1024.0**3))), + pytest.raises(AddonsNotSupportedError), ): await coresys.addons.install("local_ssh") diff --git a/tests/store/test_translation_load.py b/tests/store/test_translation_load.py index 6e0a9f33dce..4725e5980c5 100644 --- a/tests/store/test_translation_load.py +++ b/tests/store/test_translation_load.py @@ -1,4 +1,5 @@ """Test loading add-translation.""" + # pylint: disable=import-error,protected-access import os from pathlib import Path diff --git a/tests/store/test_validate.py b/tests/store/test_validate.py index 5a2b2503279..17c6f0d9578 100644 --- a/tests/store/test_validate.py +++ b/tests/store/test_validate.py @@ -1,4 +1,5 @@ """Test schema validation.""" + from typing import Any import pytest diff --git a/tests/test_arch.py b/tests/test_arch.py index ed66968e8e6..0f9284094c3 100644 --- a/tests/test_arch.py +++ b/tests/test_arch.py @@ -1,4 +1,5 @@ """Test arch object.""" + from unittest.mock import patch import pytest diff --git a/tests/test_auth.py b/tests/test_auth.py index 0ccde0e76b1..7d5db2c8af3 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,4 +1,5 @@ """Test auth object.""" + import asyncio from unittest.mock import AsyncMock, MagicMock diff --git a/tests/test_core.py b/tests/test_core.py index 3b4dfa4fc42..87985225ab2 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,4 +1,5 @@ """Testing handling with CoreState.""" + # pylint: disable=W0212 import datetime import errno @@ -64,15 +65,18 @@ async def test_adjust_system_datetime_if_time_behind(coresys: CoreSys): utc_ts = datetime.datetime.now().replace(tzinfo=datetime.UTC) + datetime.timedelta( days=4 ) - with patch( - "supervisor.core.retrieve_whoami", - new_callable=AsyncMock, - side_effect=[WhoamiData("Europe/Zurich", utc_ts)], - ) as mock_retrieve_whoami, patch.object( - SystemControl, "set_datetime" - ) as mock_set_datetime, patch.object( - InfoCenter, "dt_synchronized", new=PropertyMock(return_value=False) - ), patch.object(Supervisor, "check_connectivity") as mock_check_connectivity: + with ( + patch( + "supervisor.core.retrieve_whoami", + new_callable=AsyncMock, + side_effect=[WhoamiData("Europe/Zurich", utc_ts)], + ) as mock_retrieve_whoami, + patch.object(SystemControl, "set_datetime") as mock_set_datetime, + patch.object( + InfoCenter, "dt_synchronized", new=PropertyMock(return_value=False) + ), + patch.object(Supervisor, "check_connectivity") as mock_check_connectivity, + ): await coresys.core._adjust_system_datetime() mock_retrieve_whoami.assert_called_once() mock_set_datetime.assert_called_once() diff --git a/tests/test_ingress.py b/tests/test_ingress.py index c698a18c386..9e164c8e961 100644 --- a/tests/test_ingress.py +++ b/tests/test_ingress.py @@ -1,4 +1,5 @@ """Test ingress.""" + from datetime import timedelta from pathlib import Path from unittest.mock import ANY, patch diff --git a/tests/test_main.py b/tests/test_main.py index ef2e4f4c4af..6c0d31bb9ab 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,4 +1,5 @@ """Testing handling with main.""" + from pathlib import Path import supervisor.__main__ as main diff --git a/tests/test_supervisor.py b/tests/test_supervisor.py index 7fa03bf1468..0254de9c6f8 100644 --- a/tests/test_supervisor.py +++ b/tests/test_supervisor.py @@ -78,9 +78,11 @@ async def test_connectivity_check_throttling( async def test_update_failed(coresys: CoreSys, capture_exception: Mock): """Test update failure.""" err = DockerError() - with patch.object(DockerSupervisor, "install", side_effect=err), patch.object( - type(coresys.supervisor), "update_apparmor" - ), pytest.raises(SupervisorUpdateError): + with ( + patch.object(DockerSupervisor, "install", side_effect=err), + patch.object(type(coresys.supervisor), "update_apparmor"), + pytest.raises(SupervisorUpdateError), + ): await coresys.supervisor.update(AwesomeVersion("1.0")) capture_exception.assert_called_once_with(err) @@ -98,9 +100,10 @@ async def test_update_apparmor( ): """Test updating apparmor.""" coresys.updater.channel = channel - with patch("supervisor.coresys.aiohttp.ClientSession.get") as get, patch.object( - AppArmorControl, "load_profile" - ) as load_profile: + with ( + patch("supervisor.coresys.aiohttp.ClientSession.get") as get, + patch.object(AppArmorControl, "load_profile") as load_profile, + ): get.return_value.__aenter__.return_value.status = 200 get.return_value.__aenter__.return_value.text = AsyncMock(return_value="") await coresys.supervisor.update_apparmor() @@ -114,9 +117,11 @@ async def test_update_apparmor( async def test_update_apparmor_error(coresys: CoreSys, tmp_supervisor_data): """Test error updating apparmor profile.""" - with patch("supervisor.coresys.aiohttp.ClientSession.get") as get, patch.object( - AppArmorControl, "load_profile" - ), patch("supervisor.supervisor.Path.write_text", side_effect=(err := OSError())): + with ( + patch("supervisor.coresys.aiohttp.ClientSession.get") as get, + patch.object(AppArmorControl, "load_profile"), + patch("supervisor.supervisor.Path.write_text", side_effect=(err := OSError())), + ): get.return_value.__aenter__.return_value.status = 200 get.return_value.__aenter__.return_value.text = AsyncMock(return_value="") diff --git a/tests/test_updater.py b/tests/test_updater.py index 1f05d0b54f2..208310ca438 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -1,4 +1,5 @@ """Test updater files.""" + from unittest.mock import patch from awesomeversion import AwesomeVersion diff --git a/tests/utils/test_check_port.py b/tests/utils/test_check_port.py index f365c0d78c1..0a06063d191 100644 --- a/tests/utils/test_check_port.py +++ b/tests/utils/test_check_port.py @@ -1,4 +1,5 @@ """Check ports.""" + from ipaddress import ip_address from supervisor.coresys import CoreSys diff --git a/tests/utils/test_codenotary.py b/tests/utils/test_codenotary.py index 2cbab20bf1b..fa1b6b5a72a 100644 --- a/tests/utils/test_codenotary.py +++ b/tests/utils/test_codenotary.py @@ -1,4 +1,5 @@ """Test CodeNotary.""" + from __future__ import annotations from dataclasses import dataclass diff --git a/tests/utils/test_common.py b/tests/utils/test_common.py index b64d692c1e4..1c0bbc82d29 100644 --- a/tests/utils/test_common.py +++ b/tests/utils/test_common.py @@ -1,4 +1,5 @@ """Test common.""" + from pathlib import Path import pytest diff --git a/tests/utils/test_json.py b/tests/utils/test_json.py index c4b7468284b..7fff60e8434 100644 --- a/tests/utils/test_json.py +++ b/tests/utils/test_json.py @@ -1,4 +1,5 @@ """test json.""" + import time from typing import NamedTuple diff --git a/tests/utils/test_log_format.py b/tests/utils/test_log_format.py index 65cdfedf851..f0daf8d4cf0 100644 --- a/tests/utils/test_log_format.py +++ b/tests/utils/test_log_format.py @@ -1,4 +1,5 @@ """Tests for message formater.""" + from supervisor.utils.log_format import format_message diff --git a/tests/utils/test_logging.py b/tests/utils/test_logging.py index 2a4f1ca992e..8b51070925a 100644 --- a/tests/utils/test_logging.py +++ b/tests/utils/test_logging.py @@ -1,4 +1,5 @@ """Test supervisor logging util methods.""" + import asyncio import logging import queue @@ -19,8 +20,9 @@ async def test_logging_with_queue_handler() -> None: handler.emit(log_record) - with pytest.raises(asyncio.CancelledError), patch.object( - handler, "enqueue", side_effect=asyncio.CancelledError + with ( + pytest.raises(asyncio.CancelledError), + patch.object(handler, "enqueue", side_effect=asyncio.CancelledError), ): handler.emit(log_record) @@ -28,16 +30,18 @@ async def test_logging_with_queue_handler() -> None: handler.handle(log_record) emit_mock.assert_called_once() - with patch.object(handler, "filter") as filter_mock, patch.object( - handler, "emit" - ) as emit_mock: + with ( + patch.object(handler, "filter") as filter_mock, + patch.object(handler, "emit") as emit_mock, + ): filter_mock.return_value = False handler.handle(log_record) emit_mock.assert_not_called() - with patch.object(handler, "enqueue", side_effect=OSError), patch.object( - handler, "handleError" - ) as mock_handle_error: + with ( + patch.object(handler, "enqueue", side_effect=OSError), + patch.object(handler, "handleError") as mock_handle_error, + ): handler.emit(log_record) mock_handle_error.assert_called_once() diff --git a/tests/utils/test_remove_folder.py b/tests/utils/test_remove_folder.py index af70b25e717..733baa3b313 100644 --- a/tests/utils/test_remove_folder.py +++ b/tests/utils/test_remove_folder.py @@ -1,4 +1,5 @@ """test json.""" + from pathlib import Path import shutil diff --git a/tests/utils/test_systemd_journal.py b/tests/utils/test_systemd_journal.py index 5c9f23151a6..0ba172b0632 100644 --- a/tests/utils/test_systemd_journal.py +++ b/tests/utils/test_systemd_journal.py @@ -1,4 +1,5 @@ """Test systemd journal utilities.""" + import asyncio from unittest.mock import MagicMock