Revert custom component loading logic (#14327)

* Revert custom component loading logic

* Lint

* Fix tests

* Guard for infinite inserts into sys.path
This commit is contained in:
Paulus Schoutsen authored and Paulus Schoutsen committed 2018-05-07 10:01:22 -04:00
1 parent c4ec2e3434
commit 6a74fa344d
8 files changed
+84 -101

No files matched your search

+22 -24
View File
@@ -35,28 +35,30 @@ class TestNotifyFile(unittest.TestCase):
assert setup_component(self.hass, notify.DOMAIN, config)
assert not handle_config[notify.DOMAIN]
def _test_notify_file(self, timestamp, mock_utcnow, mock_stat):
def _test_notify_file(self, timestamp):
"""Test the notify file output."""
mock_utcnow.return_value = dt_util.as_utc(dt_util.now())
mock_stat.return_value.st_size = 0
filename = 'mock_file'
message = 'one, two, testing, testing'
with assert_setup_component(1) as handle_config:
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
'notify': {
'name': 'test',
'platform': 'file',
'filename': filename,
'timestamp': timestamp,
}
}))
assert handle_config[notify.DOMAIN]
m_open = mock_open()
with patch(
'homeassistant.components.notify.file.open',
m_open, create=True
):
filename = 'mock_file'
message = 'one, two, testing, testing'
with assert_setup_component(1) as handle_config:
self.assertTrue(setup_component(self.hass, notify.DOMAIN, {
'notify': {
'name': 'test',
'platform': 'file',
'filename': filename,
'timestamp': timestamp,
}
}))
assert handle_config[notify.DOMAIN]
), patch('homeassistant.components.notify.file.os.stat') as mock_st, \
patch('homeassistant.util.dt.utcnow',
return_value=dt_util.utcnow()):
mock_st.return_value.st_size = 0
title = '{} notifications (Log started: {})\n{}\n'.format(
ATTR_TITLE_DEFAULT,
dt_util.utcnow().isoformat(),
@@ -82,14 +84,10 @@ class TestNotifyFile(unittest.TestCase):
dt_util.utcnow().isoformat(), message))]
)
@patch('homeassistant.components.notify.file.os.stat')
@patch('homeassistant.util.dt.utcnow')
def test_notify_file(self, mock_utcnow, mock_stat):
def test_notify_file(self):
"""Test the notify file output without timestamp."""
self._test_notify_file(False, mock_utcnow, mock_stat)
self._test_notify_file(False)
@patch('homeassistant.components.notify.file.os.stat')
@patch('homeassistant.util.dt.utcnow')
def test_notify_file_timestamp(self, mock_utcnow, mock_stat):
def test_notify_file_timestamp(self):
"""Test the notify file output with timestamp."""
self._test_notify_file(True, mock_utcnow, mock_stat)
self._test_notify_file(True)
+4
View File
@@ -120,3 +120,7 @@ async def test_custom_component_name(hass):
comp = loader.get_component(hass, 'light.test')
assert comp.__name__ == 'custom_components.light.test'
assert comp.__package__ == 'custom_components.light'
# Test custom components is mounted
from custom_components.test_package import TEST
assert TEST == 5
@@ -3,9 +3,11 @@
from homeassistant.components.image_processing import ImageProcessingEntity
def setup_platform(hass, config, add_devices, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices_callback,
discovery_info=None):
"""Set up the test image_processing platform."""
add_devices([TestImageProcessing('camera.demo_camera', "Test")])
async_add_devices_callback([
TestImageProcessing('camera.demo_camera', "Test")])
class TestImageProcessing(ImageProcessingEntity):
@@ -21,6 +21,7 @@ def init(empty=False):
]
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices_callback,
discovery_info=None):
"""Return mock devices."""
add_devices_callback(DEVICES)
async_add_devices_callback(DEVICES)
@@ -21,6 +21,7 @@ def init(empty=False):
]
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
async def async_setup_platform(hass, config, async_add_devices_callback,
discovery_info=None):
"""Find and return test switches."""
add_devices_callback(DEVICES)
async_add_devices_callback(DEVICES)
@@ -1,4 +1,7 @@
"""Provide a mock package component."""
from .const import TEST # noqa
DOMAIN = 'test_package'
@@ -0,0 +1,2 @@
"""Constants for test_package custom component."""
TEST = 5