mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-11-06 09:29:31 +00:00
Extract exception message from chain for API errors (#2100)
* Get message from excepiton chain * cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Test exception helpers."""
|
||||
|
||||
from supervisor.utils import check_exception_chain
|
||||
from supervisor.utils import check_exception_chain, get_message_from_exception_chain
|
||||
|
||||
|
||||
def test_simple_chain_exception():
|
||||
@@ -55,3 +55,33 @@ def test_list_nested_chain_exception_not():
|
||||
raise KeyError() from err
|
||||
except KeyError as err:
|
||||
assert not check_exception_chain(err, (AssertionError, OSError))
|
||||
|
||||
|
||||
def test_simple_chain_exception_message():
|
||||
"""Test simple chain of excepiton."""
|
||||
|
||||
try:
|
||||
raise ValueError("error")
|
||||
except ValueError as err:
|
||||
assert get_message_from_exception_chain(err) == "error"
|
||||
|
||||
|
||||
def test_simple_chain_exception_not_message():
|
||||
"""Test simple chain of excepiton."""
|
||||
|
||||
try:
|
||||
raise ValueError()
|
||||
except ValueError as err:
|
||||
assert not get_message_from_exception_chain(err)
|
||||
|
||||
|
||||
def test_simple_nested_chain_exception_message():
|
||||
"""Test simple nested chain of excepiton."""
|
||||
|
||||
try:
|
||||
try:
|
||||
raise ValueError("error")
|
||||
except ValueError as err:
|
||||
raise KeyError() from err
|
||||
except KeyError as err:
|
||||
assert get_message_from_exception_chain(err) == "error"
|
||||
|
||||
Reference in New Issue
Block a user