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)