mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 02:19:31 +00:00
Include filename in exception when loading a json file fails (#111802)
* Include filename in exception when loading a json file fails * fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Test Home Assistant json utility functions."""
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
import orjson
|
||||
import pytest
|
||||
@@ -21,11 +22,11 @@ TEST_BAD_SERIALIED = "THIS IS NOT JSON\n"
|
||||
|
||||
|
||||
def test_load_bad_data(tmp_path: Path) -> None:
|
||||
"""Test error from trying to load unserialisable data."""
|
||||
"""Test error from trying to load unserializable data."""
|
||||
fname = tmp_path / "test5.json"
|
||||
with open(fname, "w") as fh:
|
||||
fh.write(TEST_BAD_SERIALIED)
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
with pytest.raises(HomeAssistantError, match=re.escape(str(fname))) as err:
|
||||
load_json(fname)
|
||||
assert isinstance(err.value.__cause__, ValueError)
|
||||
|
||||
@@ -33,7 +34,7 @@ def test_load_bad_data(tmp_path: Path) -> None:
|
||||
def test_load_json_os_error() -> None:
|
||||
"""Test trying to load JSON data from a directory."""
|
||||
fname = "/"
|
||||
with pytest.raises(HomeAssistantError) as err:
|
||||
with pytest.raises(HomeAssistantError, match=re.escape(str(fname))) as err:
|
||||
load_json(fname)
|
||||
assert isinstance(err.value.__cause__, OSError)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user