|
1 | 1 | """Test cases for the containers module.""" |
2 | 2 |
|
| 3 | +import dataclasses |
3 | 4 | from dataclasses import dataclass |
4 | 5 | from typing import Any |
5 | 6 |
|
| 7 | +import pytest |
6 | 8 | from syrupy import SnapshotAssertion |
7 | 9 |
|
8 | 10 | from roborock import CleanRecord, CleanSummary, Consumable, DnDTimer, HomeData, S7MaxVStatus, UserData |
|
13 | 15 | SCWindMapping, |
14 | 16 | WorkStatusMapping, |
15 | 17 | ) |
| 18 | +from roborock.data.containers import _camelize, _decamelize |
16 | 19 | from roborock.data.v1 import ( |
17 | 20 | MultiMapsList, |
18 | 21 | RoborockDockErrorCode, |
@@ -58,6 +61,15 @@ class ComplexObject(RoborockBase): |
58 | 61 | any: Any | None = None |
59 | 62 |
|
60 | 63 |
|
| 64 | +@dataclass |
| 65 | +class BoolFeatures(RoborockBase): |
| 66 | + """Complex object for testing serialization.""" |
| 67 | + |
| 68 | + my_flag_supported: bool | None = None |
| 69 | + my_flag_2_supported: bool | None = None |
| 70 | + is_ces_2022_supported: bool | None = None |
| 71 | + |
| 72 | + |
61 | 73 | def test_simple_object() -> None: |
62 | 74 | """Test serialization and deserialization of a simple object.""" |
63 | 75 |
|
@@ -494,3 +506,37 @@ def test_accurate_map_flag() -> None: |
494 | 506 | } |
495 | 507 | ) |
496 | 508 | assert s.current_map is None |
| 509 | + |
| 510 | + |
| 511 | +def test_boolean_features() -> None: |
| 512 | + """Test serialization and deserialization of BoolFeatures.""" |
| 513 | + obj = BoolFeatures(my_flag_supported=True, my_flag_2_supported=False, is_ces_2022_supported=True) |
| 514 | + serialized = obj.as_dict() |
| 515 | + assert serialized == { |
| 516 | + "myFlagSupported": True, |
| 517 | + "myFlag2Supported": False, |
| 518 | + "isCes2022Supported": True, |
| 519 | + } |
| 520 | + deserialized = BoolFeatures.from_dict(serialized) |
| 521 | + assert dataclasses.asdict(deserialized) == { |
| 522 | + "my_flag_supported": True, |
| 523 | + "my_flag_2_supported": False, |
| 524 | + "is_ces_2022_supported": True, |
| 525 | + } |
| 526 | + |
| 527 | + |
| 528 | +@pytest.mark.parametrize( |
| 529 | + "input_str,expected", |
| 530 | + [ |
| 531 | + ("simpleTest", "simple_test"), |
| 532 | + ("testValue", "test_value"), |
| 533 | + ("anotherExampleHere", "another_example_here"), |
| 534 | + ("isCes2022Supported", "is_ces_2022_supported"), |
| 535 | + ("isThreeDMappingInnerTestSupported", "is_three_d_mapping_inner_test_supported"), |
| 536 | + ], |
| 537 | +) |
| 538 | +def test_decamelize_function(input_str: str, expected: str) -> None: |
| 539 | + """Test the _decamelize function.""" |
| 540 | + |
| 541 | + assert _decamelize(input_str) == expected |
| 542 | + assert _camelize(expected) == input_str |
0 commit comments