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

Load as many components in parallel as possible (#20806)

* Load as many components in parallel as possible

* Lint
This commit is contained in:
Paulus Schoutsen
2019-02-07 13:56:40 -08:00
committed by Pascal Vizeli
parent f3b20d138e
commit a9672b0d52
6 changed files with 92 additions and 227 deletions

View File

@@ -1,63 +1,52 @@
"""Test to verify that we can load components."""
# pylint: disable=protected-access
import asyncio
import unittest
import pytest
import homeassistant.loader as loader
import homeassistant.components.http as http
from tests.common import (
get_test_home_assistant, MockModule, async_mock_service)
from tests.common import MockModule, async_mock_service
class TestLoader(unittest.TestCase):
"""Test the loader module."""
def test_set_component(hass):
"""Test if set_component works."""
comp = object()
loader.set_component(hass, 'switch.test_set', comp)
# pylint: disable=invalid-name
def setUp(self):
"""Set up tests."""
self.hass = get_test_home_assistant()
assert loader.get_component(hass, 'switch.test_set') is comp
# pylint: disable=invalid-name
def tearDown(self):
"""Stop everything that was started."""
self.hass.stop()
def test_set_component(self):
"""Test if set_component works."""
comp = object()
loader.set_component(self.hass, 'switch.test_set', comp)
def test_get_component(hass):
"""Test if get_component works."""
assert http == loader.get_component(hass, 'http')
assert loader.get_component(self.hass, 'switch.test_set') is comp
def test_get_component(self):
"""Test if get_component works."""
assert http == loader.get_component(self.hass, 'http')
def test_component_dependencies(hass):
"""Test if we can get the proper load order of components."""
loader.set_component(hass, 'mod1', MockModule('mod1'))
loader.set_component(hass, 'mod2', MockModule('mod2', ['mod1']))
loader.set_component(hass, 'mod3', MockModule('mod3', ['mod2']))
def test_load_order_component(self):
"""Test if we can get the proper load order of components."""
loader.set_component(self.hass, 'mod1', MockModule('mod1'))
loader.set_component(self.hass, 'mod2', MockModule('mod2', ['mod1']))
loader.set_component(self.hass, 'mod3', MockModule('mod3', ['mod2']))
assert {'mod1', 'mod2', 'mod3'} == \
loader.component_dependencies(hass, 'mod3')
assert ['mod1', 'mod2', 'mod3'] == \
loader.load_order_component(self.hass, 'mod3')
# Create circular dependency
loader.set_component(hass, 'mod1', MockModule('mod1', ['mod3']))
# Create circular dependency
loader.set_component(self.hass, 'mod1', MockModule('mod1', ['mod3']))
with pytest.raises(loader.CircularDependency):
print(loader.component_dependencies(hass, 'mod3'))
assert [] == loader.load_order_component(self.hass, 'mod3')
# Depend on non-existing component
loader.set_component(hass, 'mod1',
MockModule('mod1', ['nonexisting']))
# Depend on non-existing component
loader.set_component(self.hass, 'mod1',
MockModule('mod1', ['nonexisting']))
with pytest.raises(loader.ComponentNotFound):
print(loader.component_dependencies(hass, 'mod1'))
assert [] == loader.load_order_component(self.hass, 'mod1')
# Try to get load order for non-existing component
assert [] == loader.load_order_component(self.hass, 'mod1')
# Try to get dependencies for non-existing component
with pytest.raises(loader.ComponentNotFound):
print(loader.component_dependencies(hass, 'nonexisting'))
def test_component_loader(hass):