mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 10:18:11 +02:00
Refine printing of ConditionError (#46838)
* Refine printing of ConditionError * Improve coverage * name -> type
This commit is contained in:
committed by
GitHub
parent
e2fd255a96
commit
d33a1a5ff8
46
tests/test_exceptions.py
Normal file
46
tests/test_exceptions.py
Normal file
@ -0,0 +1,46 @@
|
||||
"""Test to verify that Home Assistant exceptions work."""
|
||||
from homeassistant.exceptions import (
|
||||
ConditionErrorContainer,
|
||||
ConditionErrorIndex,
|
||||
ConditionErrorMessage,
|
||||
)
|
||||
|
||||
|
||||
def test_conditionerror_format():
|
||||
"""Test ConditionError stringifiers."""
|
||||
error1 = ConditionErrorMessage("test", "A test error")
|
||||
assert str(error1) == "In 'test' condition: A test error"
|
||||
|
||||
error2 = ConditionErrorMessage("test", "Another error")
|
||||
assert str(error2) == "In 'test' condition: Another error"
|
||||
|
||||
error_pos1 = ConditionErrorIndex("box", index=0, total=2, error=error1)
|
||||
assert (
|
||||
str(error_pos1)
|
||||
== """In 'box' (item 1 of 2):
|
||||
In 'test' condition: A test error"""
|
||||
)
|
||||
|
||||
error_pos2 = ConditionErrorIndex("box", index=1, total=2, error=error2)
|
||||
assert (
|
||||
str(error_pos2)
|
||||
== """In 'box' (item 2 of 2):
|
||||
In 'test' condition: Another error"""
|
||||
)
|
||||
|
||||
error_container1 = ConditionErrorContainer("box", errors=[error_pos1, error_pos2])
|
||||
print(error_container1)
|
||||
assert (
|
||||
str(error_container1)
|
||||
== """In 'box' (item 1 of 2):
|
||||
In 'test' condition: A test error
|
||||
In 'box' (item 2 of 2):
|
||||
In 'test' condition: Another error"""
|
||||
)
|
||||
|
||||
error_pos3 = ConditionErrorIndex("box", index=0, total=1, error=error1)
|
||||
assert (
|
||||
str(error_pos3)
|
||||
== """In 'box':
|
||||
In 'test' condition: A test error"""
|
||||
)
|
Reference in New Issue
Block a user