mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 16:57:19 +00:00
Fix load_yaml default value (#5383)
This commit is contained in:
parent
836eed2a15
commit
28e5659eee
@ -60,7 +60,7 @@ def load_yaml(fname: str) -> Union[List, Dict]:
|
|||||||
with open(fname, encoding='utf-8') as conf_file:
|
with open(fname, encoding='utf-8') as conf_file:
|
||||||
# If configuration file is empty YAML returns None
|
# If configuration file is empty YAML returns None
|
||||||
# We convert that to an empty dict
|
# We convert that to an empty dict
|
||||||
return yaml.load(conf_file, Loader=SafeLineLoader) or {}
|
return yaml.load(conf_file, Loader=SafeLineLoader) or OrderedDict()
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
_LOGGER.error(exc)
|
_LOGGER.error(exc)
|
||||||
raise HomeAssistantError(exc)
|
raise HomeAssistantError(exc)
|
||||||
|
@ -74,6 +74,12 @@ class TestYaml(unittest.TestCase):
|
|||||||
doc = yaml.yaml.safe_load(file)
|
doc = yaml.yaml.safe_load(file)
|
||||||
assert doc["key"] == "value"
|
assert doc["key"] == "value"
|
||||||
|
|
||||||
|
with patch_yaml_files({'test.yaml': None}):
|
||||||
|
conf = 'key: !include test.yaml'
|
||||||
|
with io.StringIO(conf) as file:
|
||||||
|
doc = yaml.yaml.safe_load(file)
|
||||||
|
assert doc["key"] == {}
|
||||||
|
|
||||||
@patch('homeassistant.util.yaml.os.walk')
|
@patch('homeassistant.util.yaml.os.walk')
|
||||||
def test_include_dir_list(self, mock_walk):
|
def test_include_dir_list(self, mock_walk):
|
||||||
"""Test include dir list yaml."""
|
"""Test include dir list yaml."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user