Replacing tempfile with mock_open in tests (#3753)
- test_bootstrap.py - test_config.py - components/test_init.py - components/test_panel_custom.py - components/test_api.py - components/notify/test_file.py - components/notify/test_demo.py - components/camera/test_local_file.py - helpers/test_config_validation.py - util/test_package.py - util/test_yaml.py No changes needed in: - components/cover/test_command_line.py - components/switch/test_command_line.py - components/rollershutter/test_command_line.py - components/test_shell_command.py - components/notify/test_command_line.py Misc changes in: - components/mqtt/test_server.py Also, removed some unused mock parameters in tests/components/mqtt/test_server.py.
This commit is contained in:
parent
7d67017de7
commit
272539105f
12 changed files with 403 additions and 335 deletions
|
@ -1,6 +1,5 @@
|
|||
"""Test the bootstrapping."""
|
||||
# pylint: disable=too-many-public-methods,protected-access
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
import threading
|
||||
import logging
|
||||
|
@ -12,7 +11,8 @@ import homeassistant.util.dt as dt_util
|
|||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
|
||||
|
||||
from tests.common import \
|
||||
get_test_home_assistant, MockModule, MockPlatform, assert_setup_component
|
||||
get_test_home_assistant, MockModule, MockPlatform, \
|
||||
assert_setup_component, patch_yaml_files
|
||||
|
||||
ORIG_TIMEZONE = dt_util.DEFAULT_TIME_ZONE
|
||||
|
||||
|
@ -45,17 +45,27 @@ class TestBootstrap:
|
|||
self.hass.stop()
|
||||
loader._COMPONENT_CACHE = self.backup_cache
|
||||
|
||||
@mock.patch(
|
||||
# prevent .HA_VERISON file from being written
|
||||
'homeassistant.bootstrap.conf_util.process_ha_config_upgrade',
|
||||
mock.Mock()
|
||||
)
|
||||
@mock.patch('homeassistant.util.location.detect_location_info',
|
||||
return_value=None)
|
||||
def test_from_config_file(self, mock_detect):
|
||||
"""Test with configuration file."""
|
||||
components = ['browser', 'conversation', 'script']
|
||||
with tempfile.NamedTemporaryFile() as fp:
|
||||
for comp in components:
|
||||
fp.write('{}:\n'.format(comp).encode('utf-8'))
|
||||
fp.flush()
|
||||
files = {
|
||||
'config.yaml': ''.join(
|
||||
'{}:\n'.format(comp)
|
||||
for comp in components
|
||||
)
|
||||
}
|
||||
|
||||
self.hass = bootstrap.from_config_file(fp.name)
|
||||
with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
|
||||
mock.patch('os.access', mock.Mock(return_value=True)), \
|
||||
patch_yaml_files(files, True):
|
||||
self.hass = bootstrap.from_config_file('config.yaml')
|
||||
|
||||
components.append('group')
|
||||
assert sorted(components) == sorted(self.hass.config.components)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue