mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
parent
fafd0d4e4c
commit
da2521a299
@ -20,18 +20,20 @@ _SECRET_YAML = 'secrets.yaml'
|
|||||||
__SECRET_CACHE = {} # type: Dict
|
__SECRET_CACHE = {} # type: Dict
|
||||||
|
|
||||||
|
|
||||||
def _add_reference(obj, loader, node):
|
|
||||||
"""Add file reference information to an object."""
|
|
||||||
class NodeListClass(list):
|
class NodeListClass(list):
|
||||||
"""Wrapper class to be able to add attributes on a list."""
|
"""Wrapper class to be able to add attributes on a list."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NodeStrClass(str):
|
class NodeStrClass(str):
|
||||||
"""Wrapper class to be able to add attributes on a string."""
|
"""Wrapper class to be able to add attributes on a string."""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _add_reference(obj, loader, node):
|
||||||
|
"""Add file reference information to an object."""
|
||||||
if isinstance(obj, list):
|
if isinstance(obj, list):
|
||||||
obj = NodeListClass(obj)
|
obj = NodeListClass(obj)
|
||||||
if isinstance(obj, str):
|
if isinstance(obj, str):
|
||||||
@ -305,4 +307,9 @@ def represent_odict(dump, tag, mapping, flow_style=None):
|
|||||||
yaml.SafeDumper.add_representer(
|
yaml.SafeDumper.add_representer(
|
||||||
OrderedDict,
|
OrderedDict,
|
||||||
lambda dumper, value:
|
lambda dumper, value:
|
||||||
represent_odict(dumper, u'tag:yaml.org,2002:map', value))
|
represent_odict(dumper, 'tag:yaml.org,2002:map', value))
|
||||||
|
|
||||||
|
yaml.SafeDumper.add_representer(
|
||||||
|
NodeListClass,
|
||||||
|
lambda dumper, value:
|
||||||
|
dumper.represent_sequence('tag:yaml.org,2002:seq', value))
|
||||||
|
@ -385,3 +385,11 @@ class TestSecrets(unittest.TestCase):
|
|||||||
load_yaml(self._yaml_path, 'api_password: !secret pw')
|
load_yaml(self._yaml_path, 'api_password: !secret pw')
|
||||||
assert mock_error.call_count == 1, \
|
assert mock_error.call_count == 1, \
|
||||||
"Expected an error about logger: value"
|
"Expected an error about logger: value"
|
||||||
|
|
||||||
|
|
||||||
|
def test_representing_yaml_loaded_data():
|
||||||
|
"""Test we can represent YAML loaded data."""
|
||||||
|
files = {YAML_CONFIG_FILE: 'key: [1, "2", 3]'}
|
||||||
|
with patch_yaml_files(files):
|
||||||
|
data = load_yaml_config_file(YAML_CONFIG_FILE)
|
||||||
|
assert yaml.dump(data) == "key:\n- 1\n- '2'\n- 3\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user