Tests should all use test HA

pull/1260/head
Paulus Schoutsen 2016-02-14 15:08:23 -08:00
parent bade0e0d71
commit 09ab3e95c0
52 changed files with 170 additions and 125 deletions

View File

@ -8,14 +8,13 @@ from datetime import timedelta
import unittest
from unittest.mock import patch
import homeassistant.core as ha
from homeassistant.const import (
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY,
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED)
from homeassistant.components import alarm_control_panel
import homeassistant.util.dt as dt_util
from tests.common import fire_time_changed
from tests.common import fire_time_changed, get_test_home_assistant
CODE = 'HELLO_CODE'
@ -24,7 +23,7 @@ class TestAlarmControlPanelManual(unittest.TestCase):
""" Test the manual alarm module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -7,13 +7,13 @@ Tests manual alarm control panel component.
import unittest
from unittest.mock import patch
import homeassistant.core as ha
from homeassistant.const import (
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY,
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED, STATE_UNKNOWN)
from homeassistant.components import alarm_control_panel
from tests.common import mock_mqtt_component, fire_mqtt_message
from tests.common import (
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant)
CODE = 'HELLO_CODE'
@ -22,7 +22,7 @@ class TestAlarmControlPanelMQTT(unittest.TestCase):
""" Test the manual alarm module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name

View File

@ -6,15 +6,16 @@ Tests event automation.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation
from tests.common import get_test_home_assistant
class TestAutomationEvent(unittest.TestCase):
""" Test the event automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.calls = []
def record_call(service):

View File

@ -6,16 +6,17 @@ Tests automation component.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation
from homeassistant.const import ATTR_ENTITY_ID
from tests.common import get_test_home_assistant
class TestAutomation(unittest.TestCase):
""" Test the event automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.calls = []
def record_call(service):

View File

@ -6,16 +6,16 @@ Tests mqtt automation.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation
from tests.common import mock_mqtt_component, fire_mqtt_message
from tests.common import (
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant)
class TestAutomationMQTT(unittest.TestCase):
""" Test the event automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.calls = []

View File

@ -6,15 +6,16 @@ Tests numeric state automation.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation
from tests.common import get_test_home_assistant
class TestAutomationNumericState(unittest.TestCase):
""" Test the event automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.calls = []
def record_call(service):

View File

@ -6,16 +6,17 @@ Tests state automation.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation
import homeassistant.components.automation.state as state
from tests.common import get_test_home_assistant
class TestAutomationState(unittest.TestCase):
""" Test the event automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.states.set('test.entity', 'hello')
self.calls = []

View File

@ -8,19 +8,18 @@ from datetime import datetime
import unittest
from unittest.mock import patch
import homeassistant.core as ha
from homeassistant.components import sun
import homeassistant.components.automation as automation
import homeassistant.util.dt as dt_util
from tests.common import fire_time_changed
from tests.common import fire_time_changed, get_test_home_assistant
class TestAutomationSun(unittest.TestCase):
""" Test the sun automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.config.components.append('sun')
self.calls = []

View File

@ -6,15 +6,16 @@ Tests template automation.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation
from tests.common import get_test_home_assistant
class TestAutomationTemplate(unittest.TestCase):
""" Test the event automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.states.set('test.entity', 'hello')
self.calls = []

View File

@ -8,20 +8,19 @@ from datetime import timedelta
import unittest
from unittest.mock import patch
import homeassistant.core as ha
import homeassistant.util.dt as dt_util
import homeassistant.components.automation as automation
from homeassistant.components.automation import time, event
from homeassistant.const import CONF_PLATFORM
from tests.common import fire_time_changed
from tests.common import fire_time_changed, get_test_home_assistant
class TestAutomationTime(unittest.TestCase):
""" Test the event automation. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.calls = []
def record_call(service):

View File

@ -6,16 +6,17 @@ Tests command binary sensor.
"""
import unittest
import homeassistant.core as ha
from homeassistant.const import (STATE_ON, STATE_OFF)
from homeassistant.components.binary_sensor import command_sensor
from tests.common import get_test_home_assistant
class TestCommandSensorBinarySensor(unittest.TestCase):
""" Test the Template sensor. """
def setUp(self):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self):
""" Stop down stuff we started. """

View File

@ -6,17 +6,18 @@ Tests MQTT binary sensor.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.binary_sensor as binary_sensor
from tests.common import mock_mqtt_component, fire_mqtt_message
from homeassistant.const import (STATE_OFF, STATE_ON)
from tests.common import get_test_home_assistant
class TestSensorMQTT(unittest.TestCase):
""" Test the MQTT sensor. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name

View File

@ -123,12 +123,14 @@ class TestComponentsDeviceTracker(unittest.TestCase):
scanner = get_component('device_tracker.test').SCANNER
scanner.reset()
scanner.come_home('DEV1')
self.assertTrue(device_tracker.setup(self.hass, {
device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}}))
config = device_tracker.load_config(self.yaml_devices, self.hass,
timedelta(seconds=0), 0)[0]
self.assertEqual('dev1', config.dev_id)
self.assertEqual(True, config.track)
timedelta(seconds=0), 0)
assert len(config) == 1
assert config[0].dev_id == 'dev1'
assert config[0].track
def test_discovery(self):
scanner = get_component('device_tracker.test').SCANNER

View File

@ -6,9 +6,10 @@ Tests demo garage door component.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.garage_door as gd
from tests.common import get_test_home_assistant
LEFT = 'garage_door.left_garage_door'
RIGHT = 'garage_door.right_garage_door'
@ -18,7 +19,7 @@ class TestGarageDoorDemo(unittest.TestCase):
""" Test the demo garage door. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.assertTrue(gd.setup(self.hass, {
'garage_door': {
'platform': 'demo'

View File

@ -46,16 +46,16 @@ light:
import unittest
from homeassistant.const import STATE_ON, STATE_OFF
import homeassistant.core as ha
import homeassistant.components.light as light
from tests.common import mock_mqtt_component, fire_mqtt_message
from tests.common import (
get_test_home_assistant, mock_mqtt_component, fire_mqtt_message)
class TestLightMQTT(unittest.TestCase):
""" Test the MQTT light. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name

View File

@ -6,9 +6,10 @@ Tests demo lock component.
"""
import unittest
import homeassistant.core as ha
from homeassistant.components import lock
from tests.common import get_test_home_assistant
FRONT = 'lock.front_door'
KITCHEN = 'lock.kitchen_door'
@ -18,7 +19,7 @@ class TestLockDemo(unittest.TestCase):
""" Test the demo lock. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.assertTrue(lock.setup(self.hass, {
'lock': {
'platform': 'demo'

View File

@ -6,9 +6,10 @@ Tests demo media_player component.
"""
import unittest
from unittest.mock import patch
import homeassistant.core as ha
import homeassistant.components.media_player as mp
from tests.common import get_test_home_assistant
entity_id = 'media_player.walkman'
@ -16,7 +17,7 @@ class TestDemoMediaPlayer(unittest.TestCase):
""" Test the media_player module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -7,14 +7,13 @@ Tests universal media_player component.
from copy import copy
import unittest
import homeassistant.core as ha
from homeassistant.const import (
STATE_OFF, STATE_ON, STATE_UNKNOWN, STATE_PLAYING, STATE_PAUSED)
import homeassistant.components.switch as switch
import homeassistant.components.media_player as media_player
import homeassistant.components.media_player.universal as universal
from tests.common import mock_service
from tests.common import mock_service, get_test_home_assistant
class MockMediaPlayer(media_player.MediaPlayerDevice):
@ -87,7 +86,7 @@ class TestMediaPlayer(unittest.TestCase):
""" Test the media_player module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.mock_mp_1 = MockMediaPlayer(self.hass, 'mock1')
self.mock_mp_1.update_ha_state()

View File

@ -6,16 +6,17 @@ Tests notify demo component.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.notify as notify
from homeassistant.components.notify import demo
from tests.common import get_test_home_assistant
class TestNotifyDemo(unittest.TestCase):
""" Test the demo notify. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.assertTrue(notify.setup(self.hass, {
'notify': {
'platform': 'demo'

View File

@ -7,16 +7,17 @@ Tests MQTT rollershutter.
import unittest
from homeassistant.const import STATE_OPEN, STATE_CLOSED, STATE_UNKNOWN
import homeassistant.core as ha
import homeassistant.components.rollershutter as rollershutter
from tests.common import mock_mqtt_component, fire_mqtt_message
from tests.common import get_test_home_assistant
class TestRollershutterMQTT(unittest.TestCase):
""" Test the MQTT rollershutter. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name

View File

@ -6,15 +6,16 @@ Tests command sensor.
"""
import unittest
import homeassistant.core as ha
from homeassistant.components.sensor import command_sensor
from tests.common import get_test_home_assistant
class TestCommandSensorSensor(unittest.TestCase):
""" Test the Command line sensor. """
def setUp(self):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self):
""" Stop down stuff we started. """

View File

@ -7,11 +7,12 @@ Tests mFi sensor.
import unittest
import unittest.mock as mock
import homeassistant.core as ha
import homeassistant.components.sensor as sensor
import homeassistant.components.sensor.mfi as mfi
from homeassistant.const import TEMP_CELCIUS
from tests.common import get_test_home_assistant
class TestMfiSensorSetup(unittest.TestCase):
PLATFORM = mfi
@ -28,7 +29,7 @@ class TestMfiSensorSetup(unittest.TestCase):
}
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
@ -87,7 +88,7 @@ class TestMfiSensorSetup(unittest.TestCase):
class TestMfiSensor(unittest.TestCase):
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
self.port = mock.MagicMock()

View File

@ -6,16 +6,17 @@ Tests MQTT sensor.
"""
import unittest
import homeassistant.core as ha
import homeassistant.components.sensor as sensor
from tests.common import mock_mqtt_component, fire_mqtt_message
from tests.common import get_test_home_assistant
class TestSensorMQTT(unittest.TestCase):
""" Test the MQTT sensor. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name

View File

@ -4,15 +4,16 @@ tests.components.sensor.test_template
Tests template sensor.
"""
import homeassistant.core as ha
import homeassistant.components.sensor as sensor
from tests.common import get_test_home_assistant
class TestTemplateSensor:
""" Test the Template sensor. """
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def teardown_method(self, method):
""" Stop down stuff we started. """

View File

@ -9,17 +9,18 @@ from unittest.mock import patch
import pytest
import homeassistant.core as ha
import homeassistant.components.sensor as sensor
import homeassistant.util.dt as dt_util
from tests.common import get_test_home_assistant
@pytest.mark.usefixtures('betamax_session')
class TestSensorYr:
""" Test the Yr sensor. """
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743

View File

@ -9,16 +9,17 @@ import os
import tempfile
import unittest
from homeassistant import core
from homeassistant.const import STATE_ON, STATE_OFF
import homeassistant.components.switch as switch
from tests.common import get_test_home_assistant
class TestCommandSwitch(unittest.TestCase):
""" Test the command switch. """
def setUp(self): # pylint: disable=invalid-name
self.hass = core.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -7,11 +7,12 @@ Tests mFi switch.
import unittest
import unittest.mock as mock
import homeassistant.core as ha
import homeassistant.components.switch as switch
import homeassistant.components.switch.mfi as mfi
from tests.components.sensor import test_mfi as test_mfi_sensor
from tests.common import get_test_home_assistant
class TestMfiSwitchSetup(test_mfi_sensor.TestMfiSensorSetup):
PLATFORM = mfi
@ -45,7 +46,7 @@ class TestMfiSwitchSetup(test_mfi_sensor.TestMfiSensorSetup):
class TestMfiSwitch(unittest.TestCase):
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
self.port = mock.MagicMock()

View File

@ -7,16 +7,16 @@ Tests MQTT switch.
import unittest
from homeassistant.const import STATE_ON, STATE_OFF
import homeassistant.core as ha
import homeassistant.components.switch as switch
from tests.common import mock_mqtt_component, fire_mqtt_message
from tests.common import (
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant)
class TestSensorMQTT(unittest.TestCase):
""" Test the MQTT switch. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name

View File

@ -4,7 +4,6 @@ tests.components.switch.template
Tests template switch.
"""
import homeassistant.core as ha
import homeassistant.components as core
import homeassistant.components.switch as switch
@ -12,12 +11,14 @@ from homeassistant.const import (
STATE_ON,
STATE_OFF)
from tests.common import get_test_home_assistant
class TestTemplateSwitch:
""" Test the Template switch. """
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.calls = []

View File

@ -12,10 +12,9 @@ from unittest.mock import patch
import requests
from homeassistant import bootstrap, const
import homeassistant.core as ha
from homeassistant.components import alexa, http
from tests.common import get_test_instance_port
from tests.common import get_test_instance_port, get_test_home_assistant
API_PASSWORD = "test1234"
SERVER_PORT = get_test_instance_port()
@ -36,7 +35,7 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initalize a Home Assistant server for testing this module. """
global hass
hass = ha.HomeAssistant()
hass = get_test_home_assistant()
bootstrap.setup_component(
hass, http.DOMAIN,

View File

@ -17,7 +17,7 @@ from homeassistant import bootstrap, const
import homeassistant.core as ha
import homeassistant.components.http as http
from tests.common import get_test_instance_port
from tests.common import get_test_instance_port, get_test_home_assistant
API_PASSWORD = "test1234"
SERVER_PORT = get_test_instance_port()
@ -38,7 +38,7 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initializes a Home Assistant server. """
global hass
hass = ha.HomeAssistant()
hass = get_test_home_assistant()
hass.bus.listen('test_event', lambda _: _)
hass.states.set('test.test', 'a_state')

View File

@ -7,16 +7,17 @@ Tests Configurator component.
# pylint: disable=too-many-public-methods,protected-access
import unittest
import homeassistant.core as ha
import homeassistant.components.configurator as configurator
from homeassistant.const import EVENT_TIME_CHANGED
from tests.common import get_test_home_assistant
class TestConfigurator(unittest.TestCase):
""" Test the chromecast module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -5,14 +5,14 @@ tests.test_component_demo
Tests demo component.
"""
import json
import os
import unittest
from unittest.mock import patch
import homeassistant.core as ha
import homeassistant.components.demo as demo
from homeassistant.components import demo, device_tracker
from homeassistant.remote import JSONEncoder
from tests.common import mock_http_component
from tests.common import mock_http_component, get_test_home_assistant
@patch('homeassistant.components.sun.setup')
@ -20,13 +20,18 @@ class TestDemo(unittest.TestCase):
""" Test the demo module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
mock_http_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass.stop()
try:
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
except FileNotFoundError:
pass
def test_if_demo_state_shows_by_default(self, mock_sun_setup):
""" Test if demo state shows if we give no configuration. """
demo.setup(self.hass, {demo.DOMAIN: {}})

View File

@ -19,17 +19,15 @@ from tests.common import (
ensure_sun_set)
KNOWN_DEV_PATH = None
KNOWN_DEV_CSV_PATH = os.path.join(get_test_config_dir(),
device_tracker.CSV_DEVICES)
KNOWN_DEV_YAML_PATH = os.path.join(get_test_config_dir(),
device_tracker.YAML_DEVICES)
def setUpModule(): # pylint: disable=invalid-name
""" Initalizes a Home Assistant server. """
global KNOWN_DEV_PATH
KNOWN_DEV_PATH = os.path.join(get_test_config_dir(),
device_tracker.CSV_DEVICES)
with open(KNOWN_DEV_PATH, 'w') as fil:
with open(KNOWN_DEV_CSV_PATH, 'w') as fil:
fil.write('device,name,track,picture\n')
fil.write('DEV1,device 1,1,http://example.com/dev1.jpg\n')
fil.write('DEV2,device 2,1,http://example.com/dev2.jpg\n')
@ -37,8 +35,9 @@ def setUpModule(): # pylint: disable=invalid-name
def tearDownModule(): # pylint: disable=invalid-name
""" Stops the Home Assistant server. """
os.remove(os.path.join(get_test_config_dir(),
device_tracker.YAML_DEVICES))
for fil in (KNOWN_DEV_CSV_PATH, KNOWN_DEV_YAML_PATH):
if os.path.isfile(fil):
os.remove(fil)
class TestDeviceSunLightTrigger(unittest.TestCase):

View File

@ -11,12 +11,11 @@ from unittest.mock import patch
import requests
import homeassistant.core as ha
import homeassistant.bootstrap as bootstrap
import homeassistant.components.http as http
from homeassistant.const import HTTP_HEADER_HA_AUTH
from tests.common import get_test_instance_port
from tests.common import get_test_instance_port, get_test_home_assistant
API_PASSWORD = "test1234"
SERVER_PORT = get_test_instance_port()
@ -37,7 +36,7 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initalizes a Home Assistant server. """
global hass
hass = ha.HomeAssistant()
hass = get_test_home_assistant()
hass.bus.listen('test_event', lambda _: _)
hass.states.set('test.test', 'a_state')

View File

@ -15,10 +15,12 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
STATE_ON, STATE_OFF)
from tests.common import get_test_home_assistant
class TestGraphite(unittest.TestCase):
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743
self.gf = graphite.GraphiteFeeder(self.hass, 'foo', 123, 'ha')

View File

@ -7,18 +7,19 @@ Tests the group compoments.
# pylint: disable=protected-access,too-many-public-methods
import unittest
import homeassistant.core as ha
from homeassistant.const import (
STATE_ON, STATE_OFF, STATE_HOME, STATE_UNKNOWN, ATTR_ICON, ATTR_HIDDEN)
import homeassistant.components.group as group
from tests.common import get_test_home_assistant
class TestComponentsGroup(unittest.TestCase):
""" Tests homeassistant.components.group module. """
def setUp(self): # pylint: disable=invalid-name
""" Init needed objects. """
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.states.set('light.Bowl', STATE_ON)
self.hass.states.set('light.Ceiling', STATE_OFF)

View File

@ -6,15 +6,16 @@ Test introduction.
"""
import unittest
import homeassistant.core as ha
from homeassistant.components import introduction
from tests.common import get_test_home_assistant
class TestIntroduction(unittest.TestCase):
""" Test Introduction. """
def setUp(self):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self):
""" Stop down stuff we started. """

View File

@ -14,7 +14,7 @@ from homeassistant.const import (
import homeassistant.util.dt as dt_util
from homeassistant.components import logbook
from tests.common import mock_http_component
from tests.common import mock_http_component, get_test_home_assistant
class TestComponentHistory(unittest.TestCase):
@ -22,7 +22,7 @@ class TestComponentHistory(unittest.TestCase):
def setUp(self):
""" Test setup method. """
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
mock_http_component(self.hass)
self.assertTrue(logbook.setup(self.hass, {}))

View File

@ -4,15 +4,16 @@ tests.components.test_proximity
Tests proximity component.
"""
import homeassistant.core as ha
from homeassistant.components import proximity
from tests.common import get_test_home_assistant
class TestProximity:
""" Test the Proximity component. """
def setup_method(self, method):
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.states.set(
'zone.home', 'zoning',
{

View File

@ -10,15 +10,16 @@ import unittest
from unittest.mock import patch
from subprocess import SubprocessError
from homeassistant import core
from homeassistant.components import shell_command
from tests.common import get_test_home_assistant
class TestShellCommand(unittest.TestCase):
""" Test the demo module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = core.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -14,12 +14,14 @@ import homeassistant.core as ha
import homeassistant.util.dt as dt_util
import homeassistant.components.sun as sun
from tests.common import get_test_home_assistant
class TestSun(unittest.TestCase):
""" Test the sun module. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -9,11 +9,10 @@ from unittest.mock import patch
import requests
import homeassistant.core as ha
from homeassistant.const import __version__ as CURRENT_VERSION
from homeassistant.components import updater
import homeassistant.util.dt as dt_util
from tests.common import fire_time_changed
from tests.common import fire_time_changed, get_test_home_assistant
NEW_VERSION = '10000.0'
@ -22,7 +21,7 @@ class TestUpdater(unittest.TestCase):
""" Test the demo lock. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -6,21 +6,22 @@ Tests weblink component.
"""
import unittest
import homeassistant.core as ha
from homeassistant.components import weblink
from tests.common import get_test_home_assistant
class TestComponentHistory(unittest.TestCase):
class TestComponentWeblink(unittest.TestCase):
""" Tests homeassistant.components.history module. """
def setUp(self):
""" Test setup method. """
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self):
self.hass.stop()
def test_setup(self):
def test_entities_get_created(self):
self.assertTrue(weblink.setup(self.hass, {
weblink.DOMAIN: {
'entities': [
@ -32,3 +33,8 @@ class TestComponentHistory(unittest.TestCase):
]
}
}))
state = self.hass.states.get('weblink.my_router')
assert state is not None
assert state.state == 'http://127.0.0.1/'

View File

@ -14,9 +14,10 @@ from homeassistant.const import (
STATE_OFF,
TEMP_CELCIUS,
)
import homeassistant.core as ha
from homeassistant.components import thermostat
from tests.common import get_test_home_assistant
entity = 'thermostat.test'
ent_sensor = 'sensor.test'
@ -30,7 +31,7 @@ class TestThermostatHeatControl(unittest.TestCase):
""" Test the Heat Control thermostat. """
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.config.temperature_unit = TEMP_CELCIUS
thermostat.setup(self.hass, {'thermostat': {
'platform': 'heat_control',

View File

@ -7,10 +7,11 @@ Tests the entity helper.
# pylint: disable=protected-access,too-many-public-methods
import unittest
import homeassistant.core as ha
import homeassistant.helpers.entity as entity
from homeassistant.const import ATTR_HIDDEN
from tests.common import get_test_home_assistant
class TestHelpersEntity(unittest.TestCase):
""" Tests homeassistant.helpers.entity module. """
@ -19,7 +20,7 @@ class TestHelpersEntity(unittest.TestCase):
""" Init needed objects. """
self.entity = entity.Entity()
self.entity.entity_id = 'test.overwrite_hidden_true'
self.hass = self.entity.hass = ha.HomeAssistant()
self.hass = self.entity.hass = get_test_home_assistant()
self.entity.update_ha_state()
def tearDown(self): # pylint: disable=invalid-name

View File

@ -24,6 +24,8 @@ from homeassistant.helpers.event import (
from homeassistant.components import sun
import homeassistant.util.dt as dt_util
from tests.common import get_test_home_assistant
class TestEventHelpers(unittest.TestCase):
"""
@ -32,7 +34,7 @@ class TestEventHelpers(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
""" things to be run when tests are started. """
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """

View File

@ -19,6 +19,8 @@ from homeassistant.helpers.event_decorators import (
track_sunrise, track_sunset)
from homeassistant.components import sun
from tests.common import get_test_home_assistant
class TestEventDecoratorHelpers(unittest.TestCase):
"""
@ -27,7 +29,7 @@ class TestEventDecoratorHelpers(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
""" things to be run when tests are started. """
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.states.set("light.Bowl", "on")
self.hass.states.set("switch.AC", "off")

View File

@ -9,12 +9,14 @@ import os
import tempfile
import unittest
from homeassistant import core, bootstrap
from homeassistant import bootstrap
from homeassistant.const import (__version__, CONF_LATITUDE, CONF_LONGITUDE,
CONF_NAME, CONF_CUSTOMIZE)
import homeassistant.util.dt as dt_util
from homeassistant.helpers.entity import Entity
from tests.common import get_test_home_assistant
class TestBootstrap(unittest.TestCase):
""" Test the bootstrap utils. """
@ -53,7 +55,7 @@ class TestBootstrap(unittest.TestCase):
with open(check_file, 'w'):
pass
hass = core.HomeAssistant()
hass = get_test_home_assistant()
hass.config.config_dir = config_dir
self.assertTrue(os.path.isfile(check_file))
@ -74,7 +76,7 @@ class TestBootstrap(unittest.TestCase):
with open(check_file, 'w'):
pass
hass = core.HomeAssistant()
hass = get_test_home_assistant()
hass.config.config_dir = config_dir
bootstrap.process_ha_config_upgrade(hass)
@ -88,7 +90,7 @@ class TestBootstrap(unittest.TestCase):
CONF_NAME: 'Test',
CONF_CUSTOMIZE: {'test.test': {'hidden': True}}}
hass = core.HomeAssistant()
hass = get_test_home_assistant()
bootstrap.process_ha_core_config(hass, config)

View File

@ -25,6 +25,8 @@ from homeassistant.const import (
EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, TEMP_CELCIUS,
TEMP_FAHRENHEIT)
from tests.common import get_test_home_assistant
PST = pytz.timezone('America/Los_Angeles')
@ -35,7 +37,7 @@ class TestHomeAssistant(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
""" things to be run when tests are started. """
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
self.hass.states.set("light.Bowl", "on")
self.hass.states.set("switch.AC", "off")

View File

@ -14,7 +14,7 @@ import homeassistant.remote as remote
import homeassistant.components.http as http
from homeassistant.const import HTTP_HEADER_HA_AUTH
from tests.common import get_test_instance_port
from tests.common import get_test_instance_port, get_test_home_assistant
API_PASSWORD = "test1234"
MASTER_PORT = get_test_instance_port()
@ -38,7 +38,7 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
""" Initalizes a Home Assistant server and Slave instance. """
global hass, slave, master_api, broken_api
hass = ha.HomeAssistant()
hass = get_test_home_assistant()
hass.bus.listen('test_event', lambda _: _)
hass.states.set('test.test', 'a_state')

View File

@ -6,15 +6,16 @@ Tests Home Assistant template util methods.
"""
# pylint: disable=too-many-public-methods
import unittest
import homeassistant.core as ha
from homeassistant.exceptions import TemplateError
from homeassistant.util import template
from tests.common import get_test_home_assistant
class TestUtilTemplate(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """