1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Async bootstrap / component init (#3991)

* Async bootstrap

* Adress comments

* Fix tests

* More fixes

* Tests fixes
This commit is contained in:
Pascal Vizeli
2016-10-27 09:16:23 +02:00
committed by Paulus Schoutsen
parent d9999f36e8
commit d5368f6f78
54 changed files with 1431 additions and 1131 deletions

View File

@@ -3,7 +3,6 @@ import asyncio
import logging
import os
import unittest
from unittest.mock import patch
import homeassistant.scripts.check_config as check_config
from tests.common import patch_yaml_files, get_test_config_dir
@@ -45,12 +44,22 @@ def tearDownModule(self): # pylint: disable=invalid-name
os.remove(path)
@patch('asyncio.get_event_loop', return_value=asyncio.new_event_loop())
class TestCheckConfig(unittest.TestCase):
"""Tests for the homeassistant.scripts.check_config module."""
def setUp(self):
"""Prepare the test."""
# Somewhere in the tests our event loop gets killed,
# this ensures we have one.
try:
asyncio.get_event_loop()
except (RuntimeError, AssertionError):
# Py35: RuntimeError
# Py34: AssertionError
asyncio.set_event_loop(asyncio.new_event_loop())
# pylint: disable=no-self-use,invalid-name
def test_config_platform_valid(self, mock_get_loop):
def test_config_platform_valid(self):
"""Test a valid platform setup."""
files = {
'light.yaml': BASE_CONFIG + 'light:\n platform: demo',
@@ -66,7 +75,7 @@ class TestCheckConfig(unittest.TestCase):
'yaml_files': ['.../light.yaml']
}, res)
def test_config_component_platform_fail_validation(self, mock_get_loop):
def test_config_component_platform_fail_validation(self):
"""Test errors if component & platform not found."""
files = {
'component.yaml': BASE_CONFIG + 'http:\n password: err123',
@@ -104,7 +113,7 @@ class TestCheckConfig(unittest.TestCase):
self.assertDictEqual({}, res['secrets'])
self.assertListEqual(['.../platform.yaml'], res['yaml_files'])
def test_component_platform_not_found(self, mock_get_loop):
def test_component_platform_not_found(self):
"""Test errors if component or platform not found."""
files = {
'badcomponent.yaml': BASE_CONFIG + 'beer:',
@@ -131,7 +140,7 @@ class TestCheckConfig(unittest.TestCase):
self.assertDictEqual({}, res['secrets'])
self.assertListEqual(['.../badplatform.yaml'], res['yaml_files'])
def test_secrets(self, mock_get_loop):
def test_secrets(self):
"""Test secrets config checking method."""
files = {
get_test_config_dir('secret.yaml'): (