1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-07-08 14:23:51 +01:00
Files
supervisor/tests/backups/conftest.py
T
Stefan Agner 81e235376e Fix typos repo-wide and add codespell pre-commit hook (#6949)
* Fix typos in comments, docstrings and log messages

Correct 39 spelling mistakes across comments, docstrings and log/error
message strings throughout the package (e.g. "conection" -> "connection",
"Incomming" -> "Incoming", "Rasie" -> "Raise"). All changes are confined
to human-readable text; no identifiers, attributes or D-Bus contracts are
touched, so there is no behavior change. Found with codespell.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Fix typos in tests and CI workflow

Correct spelling mistakes in test comments, docstrings and data, plus one
in the builder workflow, so the whole tree is clean for the codespell hook
added next. The assertion in test_network_manager.py is updated to match
the corrected "Unknown error while processing" log message in the source.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Add codespell pre-commit hook

Wire up codespell so spelling mistakes in comments, docstrings and strings
are caught automatically. The vendored frontend panel is excluded, and
"hass" and "astroid" are added to the ignore list as known false positives
(the Home Assistant abbreviation and the pylint dependency package).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Address review feedback

Improve grammar in several of the touched comments and docstrings: use the
plural "ignore conditions" for the list-returning property, add the missing
auxiliary verb and fix agreement in the timezone-filter comment, fix
"backups ... use" agreement, and reword "underlay" to "underlying" in the
arch module docstring.

Also drop the "*.json" skip from the codespell hook. It was carried over
from another project but is unnecessary here (all tracked JSON is clean),
and skipping it would needlessly leave translation and data JSON unchecked.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Reword onboarding comment

"overflight" was a literal calque of the German "überflogen"; use the
idiomatic "skimmed through" instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 14:09:16 +02:00

100 lines
3.5 KiB
Python

"""Mock test."""
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from supervisor.backups.backup import BackupLocation
from supervisor.backups.const import LOCATION_CLOUD_BACKUP, LOCATION_TYPE, BackupType
from supervisor.backups.validate import ALL_FOLDERS
from supervisor.coresys import CoreSys
from supervisor.mounts.mount import Mount
from tests.const import TEST_ADDON_SLUG
@pytest.fixture(name="backup_mock")
def fixture_backup_mock():
"""Backup class mock."""
with patch("supervisor.backups.manager.Backup") as backup_mock:
backup_instance = MagicMock()
backup_mock.return_value = backup_instance
backup_instance.store_apps = AsyncMock(return_value=None)
backup_instance.store_folders = AsyncMock(return_value=None)
backup_instance.store_homeassistant = AsyncMock(return_value=None)
backup_instance.store_apps = AsyncMock(return_value=None)
backup_instance.store_supervisor_config = AsyncMock(return_value=None)
backup_instance.restore_folders = AsyncMock(return_value=True)
backup_instance.restore_homeassistant = AsyncMock(return_value=None)
backup_instance.restore_apps = AsyncMock(return_value=(True, []))
backup_instance.restore_repositories = AsyncMock(return_value=None)
backup_instance.restore_supervisor_config = AsyncMock(return_value=(True, []))
backup_instance.remove_delta_apps = AsyncMock(return_value=True)
yield backup_mock
@pytest.fixture
def partial_backup_mock(backup_mock):
"""Partial backup mock."""
backup_instance = backup_mock.return_value
backup_instance.sys_type = BackupType.PARTIAL
backup_instance.folders = []
backup_instance.app_list = [TEST_ADDON_SLUG]
backup_instance.supervisor_version = "9999.09.9.dev9999"
backup_instance.location = None
backup_instance.all_locations = {
None: BackupLocation(path=Path("/"), protected=False, size_bytes=0)
}
backup_instance.validate_backup = AsyncMock()
return backup_mock
@pytest.fixture
def full_backup_mock(backup_mock):
"""Full backup mock."""
backup_instance = backup_mock.return_value
backup_instance.sys_type = BackupType.FULL
backup_instance.folders = ALL_FOLDERS
backup_instance.app_list = [TEST_ADDON_SLUG]
backup_instance.supervisor_version = "9999.09.9.dev9999"
backup_instance.location = None
backup_instance.all_locations = {
None: BackupLocation(path=Path("/"), protected=False, size_bytes=0)
}
backup_instance.validate_backup = AsyncMock()
return backup_mock
@pytest.fixture(name="backup_locations")
async def fixture_backup_locations(
request: pytest.FixtureRequest, coresys: CoreSys, mount_propagation, mock_is_mount
) -> list[LOCATION_TYPE]:
"""Return a list of processed backup locations."""
locations: list[LOCATION_TYPE] = []
loaded = False
for location in request.param:
if location in {None, LOCATION_CLOUD_BACKUP}:
locations.append(location)
else:
if not loaded:
await coresys.mounts.load()
await coresys.mounts.create_mount(
Mount.from_dict(
coresys,
{
"name": location,
"usage": "backup",
"type": "cifs",
"server": "test.local",
"share": "test",
},
)
)
locations.append(coresys.mounts.get(location))
return locations