Warn instead of raise on duplicate YAML key (#8834)
* Warn instead of raise on duplicate key * Update test_yaml.py * Lint * Change to error
This commit is contained in:
1 parent
c6aaacbb08
commit
5696e38dd6
2 files changed
+21
-13
No files matched your search
+18
-7
@@ -5,12 +5,22 @@ import unittest
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.util import yaml
|
||||
from homeassistant.config import YAML_CONFIG_FILE, load_yaml_config_file
|
||||
from tests.common import get_test_config_dir, patch_yaml_files
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_credstash():
|
||||
"""Mock credstash so it doesn't connect to the internet."""
|
||||
with patch.object(yaml, 'credstash') as mock_credstash:
|
||||
mock_credstash.getSecret.return_value = None
|
||||
yield mock_credstash
|
||||
|
||||
|
||||
class TestYaml(unittest.TestCase):
|
||||
"""Test util.yaml loader."""
|
||||
|
||||
@@ -30,13 +40,6 @@ class TestYaml(unittest.TestCase):
|
||||
doc = yaml.yaml.safe_load(file)
|
||||
assert doc['key'] == 'value'
|
||||
|
||||
def test_duplicate_key(self):
|
||||
"""Test duplicate dict keys."""
|
||||
files = {YAML_CONFIG_FILE: 'key: thing1\nkey: thing2'}
|
||||
with self.assertRaises(HomeAssistantError):
|
||||
with patch_yaml_files(files):
|
||||
load_yaml_config_file(YAML_CONFIG_FILE)
|
||||
|
||||
def test_unhashable_key(self):
|
||||
"""Test an unhasable key."""
|
||||
files = {YAML_CONFIG_FILE: 'message:\n {{ states.state }}'}
|
||||
@@ -411,3 +414,11 @@ def test_representing_yaml_loaded_data():
|
||||
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"
|
||||
|
||||
|
||||
def test_duplicate_key(caplog):
|
||||
"""Test duplicate dict keys."""
|
||||
files = {YAML_CONFIG_FILE: 'key: thing1\nkey: thing2'}
|
||||
with patch_yaml_files(files):
|
||||
load_yaml_config_file(YAML_CONFIG_FILE)
|
||||
assert 'contains duplicate key' in caplog.text
|
||||
Reference in new issue
Block a user