mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use setup_component in tests v2 (#3537)
* setup_component - sun * setup_component - updater * setup_component - weblink
This commit is contained in:
parent
ea4f49f0a0
commit
cae10cfe26
@ -4,6 +4,7 @@ import unittest
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
|
|
||||||
|
from homeassistant.bootstrap import setup_component
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
import homeassistant.components.sun as sun
|
import homeassistant.components.sun as sun
|
||||||
@ -31,7 +32,8 @@ class TestSun(unittest.TestCase):
|
|||||||
|
|
||||||
def test_setting_rising(self):
|
def test_setting_rising(self):
|
||||||
"""Test retrieving sun setting and rising."""
|
"""Test retrieving sun setting and rising."""
|
||||||
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
setup_component(self.hass, sun.DOMAIN, {
|
||||||
|
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
||||||
|
|
||||||
from astral import Astral
|
from astral import Astral
|
||||||
|
|
||||||
@ -71,7 +73,8 @@ class TestSun(unittest.TestCase):
|
|||||||
|
|
||||||
def test_state_change(self):
|
def test_state_change(self):
|
||||||
"""Test if the state changes at next setting/rising."""
|
"""Test if the state changes at next setting/rising."""
|
||||||
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
setup_component(self.hass, sun.DOMAIN, {
|
||||||
|
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
||||||
|
|
||||||
if sun.is_on(self.hass):
|
if sun.is_on(self.hass):
|
||||||
test_state = sun.STATE_BELOW_HORIZON
|
test_state = sun.STATE_BELOW_HORIZON
|
||||||
@ -98,7 +101,8 @@ class TestSun(unittest.TestCase):
|
|||||||
|
|
||||||
with patch('homeassistant.helpers.condition.dt_util.utcnow',
|
with patch('homeassistant.helpers.condition.dt_util.utcnow',
|
||||||
return_value=june):
|
return_value=june):
|
||||||
assert sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
assert setup_component(self.hass, sun.DOMAIN, {
|
||||||
|
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
||||||
|
|
||||||
state = self.hass.states.get(sun.ENTITY_ID)
|
state = self.hass.states.get(sun.ENTITY_ID)
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from homeassistant.bootstrap import setup_component
|
||||||
from homeassistant.components import updater
|
from homeassistant.components import updater
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from tests.common import fire_time_changed, get_test_home_assistant
|
from tests.common import fire_time_changed, get_test_home_assistant
|
||||||
@ -31,7 +32,7 @@ class TestUpdater(unittest.TestCase):
|
|||||||
mock_get_newest_version.return_value = NEW_VERSION
|
mock_get_newest_version.return_value = NEW_VERSION
|
||||||
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
|
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
|
||||||
|
|
||||||
self.assertTrue(updater.setup(self.hass, {
|
self.assertTrue(setup_component(self.hass, updater.DOMAIN, {
|
||||||
'updater': None
|
'updater': None
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ class TestUpdater(unittest.TestCase):
|
|||||||
mock_get_newest_version.return_value = MOCK_CURRENT_VERSION
|
mock_get_newest_version.return_value = MOCK_CURRENT_VERSION
|
||||||
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
|
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION
|
||||||
|
|
||||||
self.assertTrue(updater.setup(self.hass, {
|
self.assertTrue(setup_component(self.hass, updater.DOMAIN, {
|
||||||
'updater': None
|
'updater': None
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -76,6 +77,6 @@ class TestUpdater(unittest.TestCase):
|
|||||||
"""Test if the updater component is disabled on dev."""
|
"""Test if the updater component is disabled on dev."""
|
||||||
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION + 'dev'
|
updater.CURRENT_VERSION = MOCK_CURRENT_VERSION + 'dev'
|
||||||
|
|
||||||
self.assertFalse(updater.setup(self.hass, {
|
self.assertFalse(setup_component(self.hass, updater.DOMAIN, {
|
||||||
'updater': None
|
'updater': None
|
||||||
}))
|
}))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""The tests for the weblink component."""
|
"""The tests for the weblink component."""
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from homeassistant.bootstrap import setup_component
|
||||||
from homeassistant.components import weblink
|
from homeassistant.components import weblink
|
||||||
from homeassistant import bootstrap
|
from homeassistant import bootstrap
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ class TestComponentWeblink(unittest.TestCase):
|
|||||||
|
|
||||||
def test_entities_get_created(self):
|
def test_entities_get_created(self):
|
||||||
"""Test if new entity is created."""
|
"""Test if new entity is created."""
|
||||||
self.assertTrue(weblink.setup(self.hass, {
|
self.assertTrue(setup_component(self.hass, weblink.DOMAIN, {
|
||||||
weblink.DOMAIN: {
|
weblink.DOMAIN: {
|
||||||
'entities': [
|
'entities': [
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@ from datetime import datetime, timedelta
|
|||||||
|
|
||||||
from astral import Astral
|
from astral import Astral
|
||||||
|
|
||||||
|
from homeassistant.bootstrap import setup_component
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.const import MATCH_ALL
|
from homeassistant.const import MATCH_ALL
|
||||||
from homeassistant.helpers.event import (
|
from homeassistant.helpers.event import (
|
||||||
@ -186,7 +187,8 @@ class TestEventHelpers(unittest.TestCase):
|
|||||||
# Setup sun component
|
# Setup sun component
|
||||||
self.hass.config.latitude = latitude
|
self.hass.config.latitude = latitude
|
||||||
self.hass.config.longitude = longitude
|
self.hass.config.longitude = longitude
|
||||||
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
setup_component(self.hass, sun.DOMAIN, {
|
||||||
|
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
||||||
|
|
||||||
# Get next sunrise/sunset
|
# Get next sunrise/sunset
|
||||||
astral = Astral()
|
astral = Astral()
|
||||||
@ -241,7 +243,8 @@ class TestEventHelpers(unittest.TestCase):
|
|||||||
# Setup sun component
|
# Setup sun component
|
||||||
self.hass.config.latitude = latitude
|
self.hass.config.latitude = latitude
|
||||||
self.hass.config.longitude = longitude
|
self.hass.config.longitude = longitude
|
||||||
sun.setup(self.hass, {sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
setup_component(self.hass, sun.DOMAIN, {
|
||||||
|
sun.DOMAIN: {sun.CONF_ELEVATION: 0}})
|
||||||
|
|
||||||
# Get next sunrise/sunset
|
# Get next sunrise/sunset
|
||||||
astral = Astral()
|
astral = Astral()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user