Skip to content

Commit 1ef9d3f

Browse files
committed
fix: add test coverage for extra keys
1 parent ab945a6 commit 1ef9d3f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/test_containers.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dataclasses import dataclass
44
from typing import Any
55

6-
from roborock import CleanRecord, CleanSummary, Consumable, DnDTimer, HomeData, S7MaxVStatus, SimpleObject, UserData
6+
from roborock import CleanRecord, CleanSummary, Consumable, DnDTimer, HomeData, S7MaxVStatus, UserData
77
from roborock.code_mappings import (
88
RoborockCategory,
99
RoborockDockErrorCode,
@@ -29,6 +29,14 @@
2929
)
3030

3131

32+
@dataclass
33+
class SimpleObject(RoborockBase):
34+
"""Simple object for testing serialization."""
35+
36+
name: str | None = None
37+
value: int | None = None
38+
39+
3240
@dataclass
3341
class ComplexObject(RoborockBase):
3442
"""Complex object for testing serialization."""
@@ -97,6 +105,23 @@ def test_complex_object() -> None:
97105
assert deserialized.any == "This can be anything"
98106

99107

108+
109+
def test_ignore_unknown_keys() -> None:
110+
"""Test that we don't fail on unknown keys."""
111+
data = {
112+
"ignored_key": "This key should be ignored",
113+
"simple": {"name": "Nested", "value": 100},
114+
"items": ["item1", "item2"],
115+
116+
}
117+
deserialized = ComplexObject.from_dict(data)
118+
assert deserialized.simple.name == "Nested"
119+
assert deserialized.simple.value == 100
120+
assert deserialized.items == ["item1", "item2"]
121+
assert deserialized.value is None
122+
assert deserialized.any is None
123+
124+
100125
def test_user_data():
101126
ud = UserData.from_dict(USER_DATA)
102127
assert ud.uid == 123456

0 commit comments

Comments
 (0)