mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add test for bootstrap
This commit is contained in:
parent
27ca611689
commit
60abaa585c
@ -9,6 +9,7 @@ from datetime import timedelta
|
|||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import homeassistant as ha
|
import homeassistant as ha
|
||||||
|
import homeassistant.util.location as location_util
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -40,6 +41,23 @@ def get_test_home_assistant(num_threads=None):
|
|||||||
return hass
|
return hass
|
||||||
|
|
||||||
|
|
||||||
|
def mock_detect_location_info():
|
||||||
|
""" Mock implementation of util.detect_location_info. """
|
||||||
|
return location_util.LocationInfo(
|
||||||
|
ip='1.1.1.1',
|
||||||
|
country_code='US',
|
||||||
|
country_name='United States',
|
||||||
|
region_code='CA',
|
||||||
|
region_name='California',
|
||||||
|
city='San Diego',
|
||||||
|
zip_code='92122',
|
||||||
|
time_zone='America/Los_Angeles',
|
||||||
|
latitude='2.0',
|
||||||
|
longitude='1.0',
|
||||||
|
use_fahrenheit=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def mock_service(hass, domain, service):
|
def mock_service(hass, domain, service):
|
||||||
"""
|
"""
|
||||||
Sets up a fake service.
|
Sets up a fake service.
|
||||||
|
41
tests/test_bootstrap.py
Normal file
41
tests/test_bootstrap.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
"""
|
||||||
|
tests.test_bootstrap
|
||||||
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Tests bootstrap.
|
||||||
|
"""
|
||||||
|
# pylint: disable=too-many-public-methods,protected-access
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
from homeassistant import bootstrap
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
from tests.common import mock_detect_location_info
|
||||||
|
|
||||||
|
|
||||||
|
class TestBootstrap(unittest.TestCase):
|
||||||
|
""" Test the bootstrap utils. """
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.orig_timezone = dt_util.DEFAULT_TIME_ZONE
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
dt_util.DEFAULT_TIME_ZONE = self.orig_timezone
|
||||||
|
|
||||||
|
def test_from_config_file(self):
|
||||||
|
components = ['browser', 'conversation', 'script']
|
||||||
|
with tempfile.NamedTemporaryFile() as fp:
|
||||||
|
for comp in components:
|
||||||
|
fp.write('{}:\n'.format(comp).encode('utf-8'))
|
||||||
|
fp.flush()
|
||||||
|
|
||||||
|
with mock.patch('homeassistant.util.location.detect_location_info',
|
||||||
|
mock_detect_location_info):
|
||||||
|
hass = bootstrap.from_config_file(fp.name)
|
||||||
|
|
||||||
|
components.append('group')
|
||||||
|
|
||||||
|
self.assertEqual(sorted(components),
|
||||||
|
sorted(hass.config.components))
|
@ -10,13 +10,12 @@ import unittest.mock as mock
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from homeassistant import DOMAIN, HomeAssistantError
|
from homeassistant import DOMAIN, HomeAssistantError
|
||||||
import homeassistant.util.location as location_util
|
|
||||||
import homeassistant.config as config_util
|
import homeassistant.config as config_util
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_LATITUDE, CONF_LONGITUDE, CONF_TEMPERATURE_UNIT, CONF_NAME,
|
CONF_LATITUDE, CONF_LONGITUDE, CONF_TEMPERATURE_UNIT, CONF_NAME,
|
||||||
CONF_TIME_ZONE)
|
CONF_TIME_ZONE)
|
||||||
|
|
||||||
from common import get_test_config_dir
|
from common import get_test_config_dir, mock_detect_location_info
|
||||||
|
|
||||||
CONFIG_DIR = get_test_config_dir()
|
CONFIG_DIR = get_test_config_dir()
|
||||||
YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE)
|
YAML_PATH = os.path.join(CONFIG_DIR, config_util.YAML_CONFIG_FILE)
|
||||||
@ -28,23 +27,6 @@ def create_file(path):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def mock_detect_location_info():
|
|
||||||
""" Mock implementation of util.detect_location_info. """
|
|
||||||
return location_util.LocationInfo(
|
|
||||||
ip='1.1.1.1',
|
|
||||||
country_code='US',
|
|
||||||
country_name='United States',
|
|
||||||
region_code='CA',
|
|
||||||
region_name='California',
|
|
||||||
city='San Diego',
|
|
||||||
zip_code='92122',
|
|
||||||
time_zone='America/Los_Angeles',
|
|
||||||
latitude='2.0',
|
|
||||||
longitude='1.0',
|
|
||||||
use_fahrenheit=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(unittest.TestCase):
|
class TestConfig(unittest.TestCase):
|
||||||
""" Test the config utils. """
|
""" Test the config utils. """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user