Fix mypy issues in backups and dbus (#5792)

* Fix mypy issues in backups module

* Fix mypy issues in dbus module

* Fix mypy issues in api after rebase

* TypedDict to dataclass and other small fixes

* Finish fixing mypy errors in dbus

* local_where must exist

* Fix references to name in tests
This commit is contained in:
Mike Degatano
2025-03-31 17:03:54 -04:00
committed by GitHub
parent 67b9a44160
commit 01a682cfaa
48 changed files with 683 additions and 420 deletions

View File

@@ -12,7 +12,7 @@ from awesomeversion import AwesomeVersion
import pytest
from supervisor.addons.addon import Addon
from supervisor.backups.backup import Backup
from supervisor.backups.backup import Backup, BackupLocation
from supervisor.const import CoreState
from supervisor.coresys import CoreSys
from supervisor.docker.manager import DockerAPI
@@ -505,7 +505,9 @@ async def test_restore_immediate_errors(
with (
patch.object(
Backup, "all_locations", new={None: {"path": None, "protected": True}}
Backup,
"all_locations",
new={None: BackupLocation(path=Path("/"), protected=True, size_bytes=0)},
),
patch.object(
Backup,
@@ -586,7 +588,9 @@ async def test_cloud_backup_core_only(api_client: TestClient, mock_full_backup:
# pylint: disable-next=protected-access
mock_full_backup._locations = {
".cloud_backup": {"path": None, "protected": False, "size_bytes": 10240}
".cloud_backup": BackupLocation(
path=Path("/"), protected=False, size_bytes=10240
)
}
assert mock_full_backup.location == ".cloud_backup"
@@ -672,8 +676,10 @@ async def test_backup_to_multiple_locations(
assert orig_backup.exists()
assert copy_backup.exists()
assert coresys.backups.get(slug).all_locations == {
None: {"path": orig_backup, "protected": False, "size_bytes": 10240},
".cloud_backup": {"path": copy_backup, "protected": False, "size_bytes": 10240},
None: BackupLocation(path=orig_backup, protected=False, size_bytes=10240),
".cloud_backup": BackupLocation(
path=copy_backup, protected=False, size_bytes=10240
),
}
assert coresys.backups.get(slug).location is None
@@ -709,7 +715,7 @@ async def test_backup_to_multiple_locations_error_on_copy(
orig_backup = coresys.config.path_backup / f"{slug}.tar"
assert await coresys.run_in_executor(orig_backup.exists)
assert coresys.backups.get(slug).all_locations == {
None: {"path": orig_backup, "protected": False, "size_bytes": 10240},
None: BackupLocation(path=orig_backup, protected=False, size_bytes=10240),
}
assert coresys.backups.get(slug).location is None
@@ -783,8 +789,10 @@ async def test_upload_to_multiple_locations(
assert orig_backup.exists()
assert copy_backup.exists()
assert coresys.backups.get("7fed74c8").all_locations == {
None: {"path": orig_backup, "protected": False, "size_bytes": 10240},
".cloud_backup": {"path": copy_backup, "protected": False, "size_bytes": 10240},
None: BackupLocation(path=orig_backup, protected=False, size_bytes=10240),
".cloud_backup": BackupLocation(
path=copy_backup, protected=False, size_bytes=10240
),
}
assert coresys.backups.get("7fed74c8").location is None
@@ -798,7 +806,7 @@ async def test_upload_duplicate_backup_new_location(
orig_backup = Path(copy(backup_file, coresys.config.path_backup))
await coresys.backups.reload()
assert coresys.backups.get("7fed74c8").all_locations == {
None: {"path": orig_backup, "protected": False, "size_bytes": 10240}
None: BackupLocation(path=orig_backup, protected=False, size_bytes=10240),
}
with backup_file.open("rb") as file, MultipartWriter("form-data") as mp:
@@ -815,8 +823,10 @@ async def test_upload_duplicate_backup_new_location(
assert orig_backup.exists()
assert copy_backup.exists()
assert coresys.backups.get("7fed74c8").all_locations == {
None: {"path": orig_backup, "protected": False, "size_bytes": 10240},
".cloud_backup": {"path": copy_backup, "protected": False, "size_bytes": 10240},
None: BackupLocation(path=orig_backup, protected=False, size_bytes=10240),
".cloud_backup": BackupLocation(
path=copy_backup, protected=False, size_bytes=10240
),
}
assert coresys.backups.get("7fed74c8").location is None
@@ -853,7 +863,7 @@ async def test_upload_with_filename(
orig_backup = coresys.config.path_backup / filename
assert orig_backup.exists()
assert coresys.backups.get("7fed74c8").all_locations == {
None: {"path": orig_backup, "protected": False, "size_bytes": 10240}
None: BackupLocation(path=orig_backup, protected=False, size_bytes=10240),
}
assert coresys.backups.get("7fed74c8").location is None
@@ -886,8 +896,10 @@ async def test_remove_backup_from_location(api_client: TestClient, coresys: Core
await coresys.backups.reload()
assert (backup := coresys.backups.get("7fed74c8"))
assert backup.all_locations == {
None: {"path": location_1, "protected": False, "size_bytes": 10240},
".cloud_backup": {"path": location_2, "protected": False, "size_bytes": 10240},
None: BackupLocation(path=location_1, protected=False, size_bytes=10240),
".cloud_backup": BackupLocation(
path=location_2, protected=False, size_bytes=10240
),
}
resp = await api_client.delete(
@@ -899,7 +911,7 @@ async def test_remove_backup_from_location(api_client: TestClient, coresys: Core
assert not location_2.exists()
assert coresys.backups.get("7fed74c8")
assert backup.all_locations == {
None: {"path": location_1, "protected": False, "size_bytes": 10240}
None: BackupLocation(path=location_1, protected=False, size_bytes=10240),
}
@@ -912,7 +924,7 @@ async def test_remove_backup_file_not_found(api_client: TestClient, coresys: Cor
await coresys.backups.reload()
assert (backup := coresys.backups.get("7fed74c8"))
assert backup.all_locations == {
None: {"path": location, "protected": False, "size_bytes": 10240},
None: BackupLocation(path=location, protected=False, size_bytes=10240),
}
location.unlink()
@@ -940,8 +952,10 @@ async def test_download_backup_from_location(
await coresys.backups.reload()
assert (backup := coresys.backups.get("7fed74c8"))
assert backup.all_locations == {
None: {"path": location_1, "protected": False, "size_bytes": 10240},
".cloud_backup": {"path": location_2, "protected": False, "size_bytes": 10240},
None: BackupLocation(path=location_1, protected=False, size_bytes=10240),
".cloud_backup": BackupLocation(
path=location_2, protected=False, size_bytes=10240
),
}
# The use case of this is user might want to pick a particular mount if one is flaky
@@ -1019,7 +1033,7 @@ async def test_restore_backup_from_location(
# The use case of this is user might want to pick a particular mount if one is flaky
# To simulate this, remove the file from one location and show one works and the other doesn't
assert backup.location is None
(backup_local_path := backup.all_locations[None]["path"]).unlink()
(backup_local_path := backup.all_locations[None].path).unlink()
test_file.unlink()
resp = await api_client.post(
@@ -1055,12 +1069,12 @@ async def test_restore_backup_unencrypted_after_encrypted(
backup = coresys.backups.get("d9c48f8b")
assert backup.all_locations == {
None: {"path": Path(enc_tar), "protected": True, "size_bytes": 10240},
".cloud_backup": {
"path": Path(unc_tar),
"protected": False,
"size_bytes": 10240,
},
None: BackupLocation(path=Path(enc_tar), protected=True, size_bytes=10240),
".cloud_backup": BackupLocation(
path=Path(unc_tar),
protected=False,
size_bytes=10240,
),
}
# pylint: disable=fixme
@@ -1173,12 +1187,12 @@ async def test_backup_mixed_encryption(api_client: TestClient, coresys: CoreSys)
backup = coresys.backups.get("d9c48f8b")
assert backup.all_locations == {
None: {"path": Path(enc_tar), "protected": True, "size_bytes": 10240},
".cloud_backup": {
"path": Path(unc_tar),
"protected": False,
"size_bytes": 10240,
},
None: BackupLocation(path=Path(enc_tar), protected=True, size_bytes=10240),
".cloud_backup": BackupLocation(
path=Path(unc_tar),
protected=False,
size_bytes=10240,
),
}
resp = await api_client.get("/backups")