Skip to content

Commit 4f1d5cc

Browse files
committed
ValueError not TypeError in post_init
1 parent 34acdc9 commit 4f1d5cc

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

aiohasupervisor/models/backups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class PartialBackupRestoreOptions(ABC): # noqa: B024
120120
def __post_init__(self) -> None:
121121
"""Validate at least one thing to backup/restore is included."""
122122
if not any((self.addons, self.folders, self.homeassistant)):
123-
raise TypeError(
123+
raise ValueError(
124124
"At least one of addons, folders, or homeassistant must have a value"
125125
)
126126

aiohasupervisor/models/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Options(ABC, DataClassDictMixin):
5858
def __post_init__(self) -> None:
5959
"""Validate at least one field is present."""
6060
if not self.to_dict():
61-
raise TypeError("At least one field must have a value")
61+
raise ValueError("At least one field must have a value")
6262

6363
class Config(RequestConfig):
6464
"""Mashumaro config."""

tests/test_backups.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ async def test_partial_backup_options() -> None:
109109
assert PartialBackupOptions(name="good", addons={"a"})
110110
assert PartialBackupOptions(name="good", folders={Folder.SSL})
111111
assert PartialBackupOptions(name="good", homeassistant=True)
112-
with pytest.raises(TypeError):
112+
with pytest.raises(
113+
ValueError,
114+
match="At least one of addons, folders, or homeassistant must have a value",
115+
):
113116
PartialBackupOptions(name="bad")
114117

115118

@@ -118,7 +121,10 @@ async def test_partial_restore_options() -> None:
118121
assert PartialRestoreOptions(addons={"a"})
119122
assert PartialRestoreOptions(folders={Folder.SSL})
120123
assert PartialRestoreOptions(homeassistant=True)
121-
with pytest.raises(TypeError):
124+
with pytest.raises(
125+
ValueError,
126+
match="At least one of addons, folders, or homeassistant must have a value",
127+
):
122128
PartialRestoreOptions(background=True)
123129

124130

0 commit comments

Comments
 (0)