Skip to content

Commit

Permalink
feat: Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sopelj committed Feb 10, 2024
1 parent 6135ce1 commit a769a84
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
29 changes: 29 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down
22 changes: 13 additions & 9 deletions tests/test_mug_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
}

0 comments on commit a769a84

Please sign in to comment.