Skip to content

Commit

Permalink
Add test for Number
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMikeSimon committed Sep 4, 2023
1 parent 4a2a540 commit c0a01e2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import random
import string
import pytest
from ha_mqtt_discoverable import Settings
from ha_mqtt_discoverable.sensors import Number, NumberInfo


@pytest.fixture()
def number() -> Number:
mqtt_settings = Settings.MQTT(host="localhost")
number_info = NumberInfo(name="test", min=5.0, max=90.0)
settings = Settings(mqtt=mqtt_settings, entity=number_info)
# Define empty callback
return Number(settings, lambda *_: None)


def test_required_config():
mqtt_settings = Settings.MQTT(host="localhost")
number_info = NumberInfo(name="test")
settings = Settings(mqtt=mqtt_settings, entity=number_info)
# Define empty callback
number = Number(settings, lambda *_: None)
assert number is not None


def test_set_number(number: Number):
number.set_number(42.0)


def test_number_too_small(number: Number):
with pytest.raises(RuntimeError):
number.set_number(4.0)


def test_number_too_large(number: Number):
with pytest.raises(RuntimeError):
number.set_number(91.0)

0 comments on commit c0a01e2

Please sign in to comment.