Load as many components in parallel as possible (#20806)
* Load as many components in parallel as possible * Lint
This commit is contained in:
1 parent
f3b20d138e
commit
a9672b0d52
6 files changed
+92
-227
No files matched your search
+28
-39
@@ -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):
|
||||
|
||||
@@ -105,67 +105,6 @@ class TestUtil(unittest.TestCase):
|
||||
with pytest.raises(TypeError):
|
||||
TestEnum.FIRST >= 1
|
||||
|
||||
def test_ordered_set(self):
|
||||
"""Test ordering of set."""
|
||||
set1 = util.OrderedSet([1, 2, 3, 4])
|
||||
set2 = util.OrderedSet([3, 4, 5])
|
||||
|
||||
assert 4 == len(set1)
|
||||
assert 3 == len(set2)
|
||||
|
||||
assert 1 in set1
|
||||
assert 2 in set1
|
||||
assert 3 in set1
|
||||
assert 4 in set1
|
||||
assert 5 not in set1
|
||||
|
||||
assert 1 not in set2
|
||||
assert 2 not in set2
|
||||
assert 3 in set2
|
||||
assert 4 in set2
|
||||
assert 5 in set2
|
||||
|
||||
set1.add(5)
|
||||
assert 5 in set1
|
||||
|
||||
set1.discard(5)
|
||||
assert 5 not in set1
|
||||
|
||||
# Try again while key is not in
|
||||
set1.discard(5)
|
||||
assert 5 not in set1
|
||||
|
||||
assert [1, 2, 3, 4] == list(set1)
|
||||
assert [4, 3, 2, 1] == list(reversed(set1))
|
||||
|
||||
assert 1 == set1.pop(False)
|
||||
assert [2, 3, 4] == list(set1)
|
||||
|
||||
assert 4 == set1.pop()
|
||||
assert [2, 3] == list(set1)
|
||||
|
||||
assert 'OrderedSet()' == str(util.OrderedSet())
|
||||
assert 'OrderedSet([2, 3])' == str(set1)
|
||||
|
||||
assert set1 == util.OrderedSet([2, 3])
|
||||
assert set1 != util.OrderedSet([3, 2])
|
||||
assert set1 == set([2, 3])
|
||||
assert set1 == {3, 2}
|
||||
assert set1 == [2, 3]
|
||||
assert set1 == [3, 2]
|
||||
assert set1 != {2}
|
||||
|
||||
set3 = util.OrderedSet(set1)
|
||||
set3.update(set2)
|
||||
|
||||
assert [3, 4, 5, 2] == set3
|
||||
assert [3, 4, 5, 2] == set1 | set2
|
||||
assert [3] == set1 & set2
|
||||
assert [2] == set1 - set2
|
||||
|
||||
set1.update([1, 2], [5, 6])
|
||||
assert [2, 3, 1, 5, 6] == set1
|
||||
|
||||
def test_throttle(self):
|
||||
"""Test the add cooldown decorator."""
|
||||
calls1 = []
|
||||
|
||||
Reference in new issue
Block a user