core/tests/test_loader.py

57 lines
1.8 KiB
Python
Raw Normal View History

2016-03-09 09:25:50 +00:00
"""Test to verify that we can load components."""
# pylint: disable=protected-access
2014-11-23 17:51:16 +00:00
import unittest
import homeassistant.loader as loader
import homeassistant.components.http as http
2015-09-13 05:56:49 +00:00
from tests.common import get_test_home_assistant, MockModule
2014-11-25 08:20:36 +00:00
2014-11-23 17:51:16 +00:00
class TestLoader(unittest.TestCase):
2016-03-09 09:25:50 +00:00
"""Test the loader module."""
# pylint: disable=invalid-name
def setUp(self):
2016-03-09 09:25:50 +00:00
"""Setup tests."""
self.hass = get_test_home_assistant()
2014-11-23 17:51:16 +00:00
# pylint: disable=invalid-name
def tearDown(self):
2016-03-09 09:25:50 +00:00
"""Stop everything that was started."""
2014-11-29 04:22:08 +00:00
self.hass.stop()
2014-11-23 20:57:29 +00:00
2014-11-25 08:20:36 +00:00
def test_set_component(self):
2016-03-09 09:25:50 +00:00
"""Test if set_component works."""
2015-09-13 05:56:49 +00:00
loader.set_component('switch.test_set', http)
2014-11-25 08:20:36 +00:00
2015-09-13 05:56:49 +00:00
self.assertEqual(http, loader.get_component('switch.test_set'))
2014-11-25 08:20:36 +00:00
2014-11-23 17:51:16 +00:00
def test_get_component(self):
2016-03-09 09:25:50 +00:00
"""Test if get_component works."""
2014-11-23 17:51:16 +00:00
self.assertEqual(http, loader.get_component('http'))
self.assertIsNotNone(loader.get_component('switch.test'))
2014-11-28 23:34:42 +00:00
def test_load_order_component(self):
2016-03-09 09:25:50 +00:00
"""Test if we can get the proper load order of components."""
2014-11-28 23:34:42 +00:00
loader.set_component('mod1', MockModule('mod1'))
loader.set_component('mod2', MockModule('mod2', ['mod1']))
loader.set_component('mod3', MockModule('mod3', ['mod2']))
self.assertEqual(
['mod1', 'mod2', 'mod3'], loader.load_order_component('mod3'))
# Create circular dependency
loader.set_component('mod1', MockModule('mod1', ['mod3']))
self.assertEqual([], loader.load_order_component('mod3'))
# Depend on non-existing component
loader.set_component('mod1', MockModule('mod1', ['nonexisting']))
self.assertEqual([], loader.load_order_component('mod1'))
# Try to get load order for non-existing component
self.assertEqual([], loader.load_order_component('mod1'))