Tests should all use test HA

This commit is contained in:
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 import unittest
from unittest.mock import patch from unittest.mock import patch
import homeassistant.core as ha
from homeassistant.const import ( from homeassistant.const import (
STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY, STATE_ALARM_DISARMED, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY,
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED) STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED)
from homeassistant.components import alarm_control_panel from homeassistant.components import alarm_control_panel
import homeassistant.util.dt as dt_util 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' CODE = 'HELLO_CODE'
@ -24,7 +23,7 @@ class TestAlarmControlPanelManual(unittest.TestCase):
""" Test the manual alarm module. """ """ Test the manual alarm module. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """ """ Stop down stuff we started. """

View file

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

View file

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

View file

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

View file

@ -6,16 +6,16 @@ Tests mqtt automation.
""" """
import unittest import unittest
import homeassistant.core as ha
import homeassistant.components.automation as automation 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): class TestAutomationMQTT(unittest.TestCase):
""" Test the event automation. """ """ Test the event automation. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass) mock_mqtt_component(self.hass)
self.calls = [] self.calls = []

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -6,17 +6,18 @@ Tests MQTT binary sensor.
""" """
import unittest import unittest
import homeassistant.core as ha
import homeassistant.components.binary_sensor as binary_sensor import homeassistant.components.binary_sensor as binary_sensor
from tests.common import mock_mqtt_component, fire_mqtt_message from tests.common import mock_mqtt_component, fire_mqtt_message
from homeassistant.const import (STATE_OFF, STATE_ON) from homeassistant.const import (STATE_OFF, STATE_ON)
from tests.common import get_test_home_assistant
class TestSensorMQTT(unittest.TestCase): class TestSensorMQTT(unittest.TestCase):
""" Test the MQTT sensor. """ """ Test the MQTT sensor. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass) mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name 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 = get_component('device_tracker.test').SCANNER
scanner.reset() scanner.reset()
scanner.come_home('DEV1') scanner.come_home('DEV1')
self.assertTrue(device_tracker.setup(self.hass, { self.assertTrue(device_tracker.setup(self.hass, {
device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}})) device_tracker.DOMAIN: {CONF_PLATFORM: 'test'}}))
config = device_tracker.load_config(self.yaml_devices, self.hass, config = device_tracker.load_config(self.yaml_devices, self.hass,
timedelta(seconds=0), 0)[0] timedelta(seconds=0), 0)
self.assertEqual('dev1', config.dev_id) assert len(config) == 1
self.assertEqual(True, config.track) assert config[0].dev_id == 'dev1'
assert config[0].track
def test_discovery(self): def test_discovery(self):
scanner = get_component('device_tracker.test').SCANNER scanner = get_component('device_tracker.test').SCANNER

View file

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

View file

@ -46,16 +46,16 @@ light:
import unittest import unittest
from homeassistant.const import STATE_ON, STATE_OFF from homeassistant.const import STATE_ON, STATE_OFF
import homeassistant.core as ha
import homeassistant.components.light as light 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): class TestLightMQTT(unittest.TestCase):
""" Test the MQTT light. """ """ Test the MQTT light. """
def setUp(self): # pylint: disable=invalid-name 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) self.mock_publish = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self): # pylint: disable=invalid-name

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,16 +7,16 @@ Tests MQTT switch.
import unittest import unittest
from homeassistant.const import STATE_ON, STATE_OFF from homeassistant.const import STATE_ON, STATE_OFF
import homeassistant.core as ha
import homeassistant.components.switch as switch 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): class TestSensorMQTT(unittest.TestCase):
""" Test the MQTT switch. """ """ Test the MQTT switch. """
def setUp(self): # pylint: disable=invalid-name 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) self.mock_publish = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self): # pylint: disable=invalid-name

View file

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

View file

@ -12,10 +12,9 @@ from unittest.mock import patch
import requests import requests
from homeassistant import bootstrap, const from homeassistant import bootstrap, const
import homeassistant.core as ha
from homeassistant.components import alexa, http 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" API_PASSWORD = "test1234"
SERVER_PORT = get_test_instance_port() 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. """ """ Initalize a Home Assistant server for testing this module. """
global hass global hass
hass = ha.HomeAssistant() hass = get_test_home_assistant()
bootstrap.setup_component( bootstrap.setup_component(
hass, http.DOMAIN, hass, http.DOMAIN,

View file

@ -17,7 +17,7 @@ from homeassistant import bootstrap, const
import homeassistant.core as ha import homeassistant.core as ha
import homeassistant.components.http as http 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" API_PASSWORD = "test1234"
SERVER_PORT = get_test_instance_port() 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. """ """ Initializes a Home Assistant server. """
global hass global hass
hass = ha.HomeAssistant() hass = get_test_home_assistant()
hass.bus.listen('test_event', lambda _: _) hass.bus.listen('test_event', lambda _: _)
hass.states.set('test.test', 'a_state') hass.states.set('test.test', 'a_state')

View file

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

View file

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

View file

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

View file

@ -11,12 +11,11 @@ from unittest.mock import patch
import requests import requests
import homeassistant.core as ha
import homeassistant.bootstrap as bootstrap import homeassistant.bootstrap as bootstrap
import homeassistant.components.http as http import homeassistant.components.http as http
from homeassistant.const import HTTP_HEADER_HA_AUTH 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" API_PASSWORD = "test1234"
SERVER_PORT = get_test_instance_port() 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. """ """ Initalizes a Home Assistant server. """
global hass global hass
hass = ha.HomeAssistant() hass = get_test_home_assistant()
hass.bus.listen('test_event', lambda _: _) hass.bus.listen('test_event', lambda _: _)
hass.states.set('test.test', 'a_state') hass.states.set('test.test', 'a_state')

View file

@ -15,10 +15,12 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
STATE_ON, STATE_OFF) STATE_ON, STATE_OFF)
from tests.common import get_test_home_assistant
class TestGraphite(unittest.TestCase): class TestGraphite(unittest.TestCase):
def setup_method(self, method): def setup_method(self, method):
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
self.hass.config.latitude = 32.87336 self.hass.config.latitude = 32.87336
self.hass.config.longitude = 117.22743 self.hass.config.longitude = 117.22743
self.gf = graphite.GraphiteFeeder(self.hass, 'foo', 123, 'ha') 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 # pylint: disable=protected-access,too-many-public-methods
import unittest import unittest
import homeassistant.core as ha
from homeassistant.const import ( from homeassistant.const import (
STATE_ON, STATE_OFF, STATE_HOME, STATE_UNKNOWN, ATTR_ICON, ATTR_HIDDEN) STATE_ON, STATE_OFF, STATE_HOME, STATE_UNKNOWN, ATTR_ICON, ATTR_HIDDEN)
import homeassistant.components.group as group import homeassistant.components.group as group
from tests.common import get_test_home_assistant
class TestComponentsGroup(unittest.TestCase): class TestComponentsGroup(unittest.TestCase):
""" Tests homeassistant.components.group module. """ """ Tests homeassistant.components.group module. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
""" Init needed objects. """ """ 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.Bowl', STATE_ON)
self.hass.states.set('light.Ceiling', STATE_OFF) self.hass.states.set('light.Ceiling', STATE_OFF)

View file

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

View file

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

View file

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

View file

@ -10,15 +10,16 @@ import unittest
from unittest.mock import patch from unittest.mock import patch
from subprocess import SubprocessError from subprocess import SubprocessError
from homeassistant import core
from homeassistant.components import shell_command from homeassistant.components import shell_command
from tests.common import get_test_home_assistant
class TestShellCommand(unittest.TestCase): class TestShellCommand(unittest.TestCase):
""" Test the demo module. """ """ Test the demo module. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = core.HomeAssistant() self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """ """ 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.util.dt as dt_util
import homeassistant.components.sun as sun import homeassistant.components.sun as sun
from tests.common import get_test_home_assistant
class TestSun(unittest.TestCase): class TestSun(unittest.TestCase):
""" Test the sun module. """ """ Test the sun module. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """ """ Stop down stuff we started. """

View file

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

View file

@ -6,21 +6,22 @@ Tests weblink component.
""" """
import unittest import unittest
import homeassistant.core as ha
from homeassistant.components import weblink 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. """ """ Tests homeassistant.components.history module. """
def setUp(self): def setUp(self):
""" Test setup method. """ """ Test setup method. """
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
def tearDown(self): def tearDown(self):
self.hass.stop() self.hass.stop()
def test_setup(self): def test_entities_get_created(self):
self.assertTrue(weblink.setup(self.hass, { self.assertTrue(weblink.setup(self.hass, {
weblink.DOMAIN: { weblink.DOMAIN: {
'entities': [ '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, STATE_OFF,
TEMP_CELCIUS, TEMP_CELCIUS,
) )
import homeassistant.core as ha
from homeassistant.components import thermostat from homeassistant.components import thermostat
from tests.common import get_test_home_assistant
entity = 'thermostat.test' entity = 'thermostat.test'
ent_sensor = 'sensor.test' ent_sensor = 'sensor.test'
@ -30,7 +31,7 @@ class TestThermostatHeatControl(unittest.TestCase):
""" Test the Heat Control thermostat. """ """ Test the Heat Control thermostat. """
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
self.hass.config.temperature_unit = TEMP_CELCIUS self.hass.config.temperature_unit = TEMP_CELCIUS
thermostat.setup(self.hass, {'thermostat': { thermostat.setup(self.hass, {'thermostat': {
'platform': 'heat_control', 'platform': 'heat_control',

View file

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

View file

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

View file

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

View file

@ -9,12 +9,14 @@ import os
import tempfile import tempfile
import unittest import unittest
from homeassistant import core, bootstrap from homeassistant import bootstrap
from homeassistant.const import (__version__, CONF_LATITUDE, CONF_LONGITUDE, from homeassistant.const import (__version__, CONF_LATITUDE, CONF_LONGITUDE,
CONF_NAME, CONF_CUSTOMIZE) CONF_NAME, CONF_CUSTOMIZE)
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from tests.common import get_test_home_assistant
class TestBootstrap(unittest.TestCase): class TestBootstrap(unittest.TestCase):
""" Test the bootstrap utils. """ """ Test the bootstrap utils. """
@ -53,7 +55,7 @@ class TestBootstrap(unittest.TestCase):
with open(check_file, 'w'): with open(check_file, 'w'):
pass pass
hass = core.HomeAssistant() hass = get_test_home_assistant()
hass.config.config_dir = config_dir hass.config.config_dir = config_dir
self.assertTrue(os.path.isfile(check_file)) self.assertTrue(os.path.isfile(check_file))
@ -74,7 +76,7 @@ class TestBootstrap(unittest.TestCase):
with open(check_file, 'w'): with open(check_file, 'w'):
pass pass
hass = core.HomeAssistant() hass = get_test_home_assistant()
hass.config.config_dir = config_dir hass.config.config_dir = config_dir
bootstrap.process_ha_config_upgrade(hass) bootstrap.process_ha_config_upgrade(hass)
@ -88,7 +90,7 @@ class TestBootstrap(unittest.TestCase):
CONF_NAME: 'Test', CONF_NAME: 'Test',
CONF_CUSTOMIZE: {'test.test': {'hidden': True}}} CONF_CUSTOMIZE: {'test.test': {'hidden': True}}}
hass = core.HomeAssistant() hass = get_test_home_assistant()
bootstrap.process_ha_core_config(hass, config) 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, EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, TEMP_CELCIUS,
TEMP_FAHRENHEIT) TEMP_FAHRENHEIT)
from tests.common import get_test_home_assistant
PST = pytz.timezone('America/Los_Angeles') PST = pytz.timezone('America/Los_Angeles')
@ -35,7 +37,7 @@ class TestHomeAssistant(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
""" things to be run when tests are started. """ """ 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("light.Bowl", "on")
self.hass.states.set("switch.AC", "off") self.hass.states.set("switch.AC", "off")

View file

@ -14,7 +14,7 @@ import homeassistant.remote as remote
import homeassistant.components.http as http import homeassistant.components.http as http
from homeassistant.const import HTTP_HEADER_HA_AUTH 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" API_PASSWORD = "test1234"
MASTER_PORT = get_test_instance_port() 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. """ """ Initalizes a Home Assistant server and Slave instance. """
global hass, slave, master_api, broken_api global hass, slave, master_api, broken_api
hass = ha.HomeAssistant() hass = get_test_home_assistant()
hass.bus.listen('test_event', lambda _: _) hass.bus.listen('test_event', lambda _: _)
hass.states.set('test.test', 'a_state') 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 # pylint: disable=too-many-public-methods
import unittest import unittest
import homeassistant.core as ha
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
from homeassistant.util import template from homeassistant.util import template
from tests.common import get_test_home_assistant
class TestUtilTemplate(unittest.TestCase): class TestUtilTemplate(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant() self.hass = get_test_home_assistant()
def tearDown(self): # pylint: disable=invalid-name def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """ """ Stop down stuff we started. """