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
This commit is contained in:
Martin Hjelmare 2018-08-17 05:28:00 +02:00 committed by Johann Kellerman
parent 45452e510c
commit 07840f5397
2 changed files with 18 additions and 1 deletions

View file

@ -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."""