From a769a84d13c1e0595ea49be353f31995537342e9 Mon Sep 17 00:00:00 2001 From: Jesse Sopel Date: Fri, 9 Feb 2024 23:13:14 -0500 Subject: [PATCH] feat: Add more tests --- tests/test_data.py | 29 +++++++++++++++++++++++++++++ tests/test_mug_data.py | 22 +++++++++++++--------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/tests/test_data.py b/tests/test_data.py index d103434..4539df7 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -1,6 +1,8 @@ """Tests for `ember_mug.data`.""" from __future__ import annotations +import pytest + from ember_mug.consts import DeviceModel, DeviceType from ember_mug.data import BatteryInfo, Change, Colour, ModelInfo, MugFirmwareInfo, MugMeta @@ -42,6 +44,33 @@ def test_mug_meta() -> None: assert meta.mug_id == "WXc9PT09" assert meta.serial_number == "ABCDEFGHIJ" assert str(meta) == "Mug ID: WXc9PT09, Serial Number: ABCDEFGHIJ" + assert meta.as_dict() == { + "mug_id": "WXc9PT09", + "serial_number": "ABCDEFGHIJ", + } + + +@pytest.mark.parametrize( + ("model", "device_type", "name", "capacity"), + [ + (DeviceModel.CUP_6_OZ, DeviceType.CUP, "Ember Cup", 178), + (DeviceModel.MUG_1_10_OZ, DeviceType.MUG, "Ember Mug (10oz)", 295), + (DeviceModel.MUG_2_14_OZ, DeviceType.MUG, "Ember Mug 2 (14oz)", 414), + (DeviceModel.TRAVEL_MUG_12_OZ, DeviceType.TRAVEL_MUG, "Ember Travel Mug", 355), + (DeviceModel.TUMBLER_16_OZ, DeviceType.TUMBLER, "Ember Tumbler", 473), + (DeviceModel.UNKNOWN_DEVICE, DeviceType.MUG, "Unknown Device", None), + ], +) +def test_mug_model_info( + model: DeviceModel, + device_type: DeviceType, + name: str, + capacity: int | None, +) -> None: + model_info = ModelInfo(model) + assert model_info.name == name + assert model_info.device_type == device_type + assert model_info.capacity == capacity def test_mug_model() -> None: diff --git a/tests/test_mug_data.py b/tests/test_mug_data.py index 82be464..41ce67d 100644 --- a/tests/test_mug_data.py +++ b/tests/test_mug_data.py @@ -3,7 +3,7 @@ from typing import Any -from ember_mug.consts import DeviceModel, DeviceType, LiquidState, TemperatureUnit +from ember_mug.consts import DeviceColour, DeviceModel, DeviceType, LiquidState, TemperatureUnit, VolumeLevel from ember_mug.data import BatteryInfo, Change, Colour, ModelInfo, MugData, MugFirmwareInfo, MugMeta @@ -80,14 +80,18 @@ def test_update_info(mug_data: MugData) -> None: def test_mug_dict(mug_data: MugData) -> None: - mug_data.update_info(meta=MugMeta("test_id", "serial number")) + mug_data.model_info = ModelInfo(DeviceModel.TRAVEL_MUG_12_OZ, DeviceColour.BLACK) + mug_data.update_info( + meta=MugMeta("test_id", "serial number"), + volume_level=VolumeLevel.HIGH, + ) assert mug_data.as_dict() == { "model_info": { - "capacity": None, - "colour": None, - "device_type": DeviceType.MUG, - "model": None, - "name": "Unknown Device", + "capacity": 355, + "colour": DeviceColour.BLACK, + "device_type": DeviceType.TRAVEL_MUG, + "model": DeviceModel.TRAVEL_MUG_12_OZ, + "name": "Ember Travel Mug", }, "use_metric": True, "debug": False, @@ -99,7 +103,6 @@ def test_mug_dict(mug_data: MugData) -> None: "dsk": "", "firmware": None, "led_colour": Colour(red=255, green=255, blue=255), - "led_colour_display": "#ffffff", "liquid_level": 0, "liquid_level_display": "0.00%", "liquid_state": None, @@ -111,5 +114,6 @@ def test_mug_dict(mug_data: MugData) -> None: "target_temp_display": "0.00°C", "temperature_unit": TemperatureUnit.CELSIUS, "udsk": "", - "volume_level": None, + "volume_level": VolumeLevel.HIGH, + "volume_level_display": "High", }