From 07840f539793ed975c428f202e3104f50ac138cc Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Fri, 17 Aug 2018 05:28:00 +0200 Subject: [PATCH] Fix check config packages key error (#15840) * Fix packages deletion in check_config script * The config key for packages is not present if core config validation failed. We need to do a safe dict deletion using dict.pop. * Add check_config test for bad core config --- homeassistant/scripts/check_config.py | 2 +- tests/scripts/test_check_config.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/homeassistant/scripts/check_config.py b/homeassistant/scripts/check_config.py index d7be5b1a91c..e0c933df5bb 100644 --- a/homeassistant/scripts/check_config.py +++ b/homeassistant/scripts/check_config.py @@ -325,7 +325,7 @@ def check_ha_config_file(hass): # Merge packages merge_packages_config( hass, config, core_config.get(CONF_PACKAGES, {}), _pack_error) - del core_config[CONF_PACKAGES] + core_config.pop(CONF_PACKAGES, None) # Ensure we have no None values after merge for key, value in config.items(): diff --git a/tests/scripts/test_check_config.py b/tests/scripts/test_check_config.py index 532197b4072..28438a5e4b3 100644 --- a/tests/scripts/test_check_config.py +++ b/tests/scripts/test_check_config.py @@ -22,6 +22,12 @@ BASE_CONFIG = ( '\n\n' ) +BAD_CORE_CONFIG = ( + 'homeassistant:\n' + ' unit_system: bad\n' + '\n\n' +) + def normalize_yaml_files(check_dict): """Remove configuration path from ['yaml_files'].""" @@ -47,6 +53,17 @@ class TestCheckConfig(unittest.TestCase): self.maxDiff = None # pylint: disable=invalid-name # pylint: disable=no-self-use,invalid-name + @patch('os.path.isfile', return_value=True) + def test_bad_core_config(self, isfile_patch): + """Test a bad core config setup.""" + files = { + YAML_CONFIG_FILE: BAD_CORE_CONFIG, + } + with patch_yaml_files(files): + res = check_config.check(get_test_config_dir()) + assert res['except'].keys() == {'homeassistant'} + assert res['except']['homeassistant'][1] == {'unit_system': 'bad'} + @patch('os.path.isfile', return_value=True) def test_config_platform_valid(self, isfile_patch): """Test a valid platform setup."""