Remove more test requirements (#7574)
* No longer require pyunify during tests * No longer require cast during tests * No longer required dependency for tests * No longer require pymochad for tests * Astral is a core dependency * Avoid having to install datadog dependency during tests * CMUS test doesn't test anything * Frontier Silicon doesn't test anything * No longer require mutagen * Update requirements_test_all.txt * Remove stale commentpull/7589/head
parent
206d02d531
commit
352cca1037
|
@ -37,18 +37,12 @@ aiohttp_cors==0.5.3
|
|||
# homeassistant.components.notify.apns
|
||||
apns2==0.1.1
|
||||
|
||||
# homeassistant.components.datadog
|
||||
datadog==0.15.0
|
||||
|
||||
# homeassistant.components.sensor.dsmr
|
||||
dsmr_parser==0.8
|
||||
|
||||
# homeassistant.components.climate.honeywell
|
||||
evohomeclient==0.2.5
|
||||
|
||||
# homeassistant.components.media_player.frontier_silicon
|
||||
fsapi==0.0.7
|
||||
|
||||
# homeassistant.components.conversation
|
||||
fuzzywuzzy==0.15.0
|
||||
|
||||
|
@ -75,9 +69,6 @@ libsoundtouch==0.3.0
|
|||
# homeassistant.components.switch.mfi
|
||||
mficlient==0.3.0
|
||||
|
||||
# homeassistant.components.tts
|
||||
mutagen==1.37.0
|
||||
|
||||
# homeassistant.components.mqtt
|
||||
paho-mqtt==1.2.3
|
||||
|
||||
|
@ -94,21 +85,12 @@ pilight==0.1.1
|
|||
# homeassistant.components.sensor.serial_pm
|
||||
pmsensor==0.4
|
||||
|
||||
# homeassistant.components.media_player.cast
|
||||
pychromecast==0.8.1
|
||||
|
||||
# homeassistant.components.media_player.cmus
|
||||
pycmus==0.1.0
|
||||
|
||||
# homeassistant.components.zwave
|
||||
pydispatcher==2.0.5
|
||||
|
||||
# homeassistant.components.litejet
|
||||
pylitejet==0.1
|
||||
|
||||
# homeassistant.components.mochad
|
||||
pymochad==0.1.1
|
||||
|
||||
# homeassistant.components.alarm_control_panel.nx584
|
||||
# homeassistant.components.binary_sensor.nx584
|
||||
pynx584==0.4
|
||||
|
@ -116,9 +98,6 @@ pynx584==0.4
|
|||
# homeassistant.components.sensor.darksky
|
||||
python-forecastio==1.3.5
|
||||
|
||||
# homeassistant.components.device_tracker.unifi
|
||||
pyunifi==2.12
|
||||
|
||||
# homeassistant.components.notify.html5
|
||||
pywebpush==1.0.0
|
||||
|
||||
|
|
|
@ -38,18 +38,15 @@ TEST_REQUIREMENTS = (
|
|||
'uvcclient',
|
||||
'somecomfort',
|
||||
'aioautomatic',
|
||||
'pyunifi',
|
||||
'SoCo',
|
||||
'libsoundtouch',
|
||||
'rxv',
|
||||
'apns2',
|
||||
'sqlalchemy',
|
||||
'forecastio',
|
||||
'astral',
|
||||
'aiohttp_cors',
|
||||
'pilight',
|
||||
'fuzzywuzzy',
|
||||
'datadog',
|
||||
'rflink',
|
||||
'ring_doorbell',
|
||||
'sleepyq',
|
||||
|
@ -59,21 +56,14 @@ TEST_REQUIREMENTS = (
|
|||
'evohomeclient',
|
||||
'pexpect',
|
||||
'hbmqtt',
|
||||
'pychromecast',
|
||||
'pycmus',
|
||||
'fsapi',
|
||||
'paho',
|
||||
'jwt',
|
||||
'dsmr_parser',
|
||||
'mficlient',
|
||||
'pmsensor',
|
||||
'yahoo-finance',
|
||||
'pymochad',
|
||||
'mutagen',
|
||||
'ha-ffmpeg',
|
||||
'gTTS-token',
|
||||
'pywebpush',
|
||||
'pyelliptic',
|
||||
'PyJWT',
|
||||
)
|
||||
|
||||
|
|
|
@ -495,3 +495,38 @@ def mock_restore_cache(hass, states):
|
|||
"Duplicate entity_id? {}".format(states)
|
||||
hass.state = ha.CoreState.starting
|
||||
mock_component(hass, recorder.DOMAIN)
|
||||
|
||||
|
||||
class MockDependency:
|
||||
"""Decorator to mock install a dependency."""
|
||||
|
||||
def __init__(self, root, *args):
|
||||
"""Initialize decorator."""
|
||||
self.root = root
|
||||
self.submodules = args
|
||||
|
||||
def __call__(self, func):
|
||||
"""Apply decorator."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
def resolve(mock, path):
|
||||
"""Resolve a mock."""
|
||||
if not path:
|
||||
return mock
|
||||
|
||||
return resolve(getattr(mock, path[0]), path[1:])
|
||||
|
||||
def run_mocked(*args, **kwargs):
|
||||
"""Run with mocked dependencies."""
|
||||
base = MagicMock()
|
||||
to_mock = {
|
||||
"{}.{}".format(self.root, tom): resolve(base, tom.split('.'))
|
||||
for tom in self.submodules
|
||||
}
|
||||
to_mock[self.root] = base
|
||||
|
||||
with patch.dict('sys.modules', to_mock):
|
||||
args = list(args) + [base]
|
||||
func(*args, **kwargs)
|
||||
|
||||
return run_mocked
|
||||
|
|
|
@ -1,157 +1,155 @@
|
|||
"""The tests for the Unifi WAP device tracker platform."""
|
||||
import unittest
|
||||
from unittest import mock
|
||||
import urllib
|
||||
|
||||
from pyunifi import controller
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
from homeassistant.components.device_tracker import DOMAIN, unifi as unifi
|
||||
from homeassistant.const import (CONF_HOST, CONF_USERNAME, CONF_PASSWORD,
|
||||
CONF_PLATFORM, CONF_VERIFY_SSL)
|
||||
|
||||
|
||||
class TestUnifiScanner(unittest.TestCase):
|
||||
"""Test the Unifiy platform."""
|
||||
@pytest.fixture
|
||||
def mock_ctrl():
|
||||
"""Mock pyunifi."""
|
||||
module = mock.MagicMock()
|
||||
with mock.patch.dict('sys.modules', {
|
||||
'pyunifi.controller': module.controller,
|
||||
}):
|
||||
yield module.controller.Controller
|
||||
|
||||
def setUp(self):
|
||||
"""Initialize values for this testcase class."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
@pytest.fixture
|
||||
def mock_scanner():
|
||||
"""Mock UnifyScanner."""
|
||||
with mock.patch('homeassistant.components.device_tracker'
|
||||
'.unifi.UnifiScanner') as scanner:
|
||||
yield scanner
|
||||
|
||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
||||
@mock.patch.object(controller, 'Controller')
|
||||
def test_config_minimal(self, mock_ctrl, mock_scanner):
|
||||
"""Test the setup with minimal configuration."""
|
||||
config = {
|
||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
})
|
||||
|
||||
def test_config_minimal(hass, mock_scanner, mock_ctrl):
|
||||
"""Test the setup with minimal configuration."""
|
||||
config = {
|
||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
})
|
||||
}
|
||||
result = unifi.get_scanner(hass, config)
|
||||
assert mock_scanner.return_value == result
|
||||
assert mock_ctrl.call_count == 1
|
||||
assert mock_ctrl.mock_calls[0] == \
|
||||
mock.call('localhost', 'foo', 'password', 8443,
|
||||
version='v4', site_id='default', ssl_verify=True)
|
||||
|
||||
assert mock_scanner.call_count == 1
|
||||
assert mock_scanner.call_args == mock.call(mock_ctrl.return_value)
|
||||
|
||||
|
||||
def test_config_full(hass, mock_scanner, mock_ctrl):
|
||||
"""Test the setup with full configuration."""
|
||||
config = {
|
||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_HOST: 'myhost',
|
||||
CONF_VERIFY_SSL: False,
|
||||
'port': 123,
|
||||
'site_id': 'abcdef01',
|
||||
})
|
||||
}
|
||||
result = unifi.get_scanner(hass, config)
|
||||
assert mock_scanner.return_value == result
|
||||
assert mock_ctrl.call_count == 1
|
||||
assert mock_ctrl.call_args == \
|
||||
mock.call('myhost', 'foo', 'password', 123,
|
||||
version='v4', site_id='abcdef01', ssl_verify=False)
|
||||
|
||||
assert mock_scanner.call_count == 1
|
||||
assert mock_scanner.call_args == mock.call(mock_ctrl.return_value)
|
||||
|
||||
|
||||
def test_config_error():
|
||||
"""Test for configuration errors."""
|
||||
with pytest.raises(vol.Invalid):
|
||||
unifi.PLATFORM_SCHEMA({
|
||||
# no username
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 123,
|
||||
})
|
||||
with pytest.raises(vol.Invalid):
|
||||
unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 'foo', # bad port!
|
||||
})
|
||||
|
||||
|
||||
def test_config_controller_failed(hass, mock_ctrl, mock_scanner):
|
||||
"""Test for controller failure."""
|
||||
config = {
|
||||
'device_tracker': {
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
}
|
||||
result = unifi.get_scanner(self.hass, config)
|
||||
self.assertEqual(mock_scanner.return_value, result)
|
||||
self.assertEqual(mock_ctrl.call_count, 1)
|
||||
self.assertEqual(
|
||||
mock_ctrl.call_args,
|
||||
mock.call('localhost', 'foo', 'password', 8443,
|
||||
version='v4', site_id='default', ssl_verify=True)
|
||||
)
|
||||
self.assertEqual(mock_scanner.call_count, 1)
|
||||
self.assertEqual(
|
||||
mock_scanner.call_args,
|
||||
mock.call(mock_ctrl.return_value)
|
||||
)
|
||||
}
|
||||
mock_ctrl.side_effect = urllib.error.HTTPError(
|
||||
'/', 500, 'foo', {}, None)
|
||||
result = unifi.get_scanner(hass, config)
|
||||
assert result is False
|
||||
|
||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
||||
@mock.patch.object(controller, 'Controller')
|
||||
def test_config_full(self, mock_ctrl, mock_scanner):
|
||||
"""Test the setup with full configuration."""
|
||||
config = {
|
||||
DOMAIN: unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_HOST: 'myhost',
|
||||
CONF_VERIFY_SSL: False,
|
||||
'port': 123,
|
||||
'site_id': 'abcdef01',
|
||||
})
|
||||
}
|
||||
result = unifi.get_scanner(self.hass, config)
|
||||
self.assertEqual(mock_scanner.return_value, result)
|
||||
self.assertEqual(mock_ctrl.call_count, 1)
|
||||
self.assertEqual(
|
||||
mock_ctrl.call_args,
|
||||
mock.call('myhost', 'foo', 'password', 123,
|
||||
version='v4', site_id='abcdef01', ssl_verify=False)
|
||||
)
|
||||
self.assertEqual(mock_scanner.call_count, 1)
|
||||
self.assertEqual(
|
||||
mock_scanner.call_args,
|
||||
mock.call(mock_ctrl.return_value)
|
||||
)
|
||||
|
||||
def test_config_error(self):
|
||||
"""Test for configuration errors."""
|
||||
with self.assertRaises(vol.Invalid):
|
||||
unifi.PLATFORM_SCHEMA({
|
||||
# no username
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 123,
|
||||
})
|
||||
with self.assertRaises(vol.Invalid):
|
||||
unifi.PLATFORM_SCHEMA({
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
CONF_HOST: 'myhost',
|
||||
'port': 'foo', # bad port!
|
||||
})
|
||||
def test_scanner_update():
|
||||
"""Test the scanner update."""
|
||||
ctrl = mock.MagicMock()
|
||||
fake_clients = [
|
||||
{'mac': '123'},
|
||||
{'mac': '234'},
|
||||
]
|
||||
ctrl.get_clients.return_value = fake_clients
|
||||
unifi.UnifiScanner(ctrl)
|
||||
assert ctrl.get_clients.call_count == 1
|
||||
assert ctrl.get_clients.call_args == mock.call()
|
||||
|
||||
@mock.patch('homeassistant.components.device_tracker.unifi.UnifiScanner')
|
||||
@mock.patch.object(controller, 'Controller')
|
||||
def test_config_controller_failed(self, mock_ctrl, mock_scanner):
|
||||
"""Test for controller failure."""
|
||||
config = {
|
||||
'device_tracker': {
|
||||
CONF_PLATFORM: unifi.DOMAIN,
|
||||
CONF_USERNAME: 'foo',
|
||||
CONF_PASSWORD: 'password',
|
||||
}
|
||||
}
|
||||
mock_ctrl.side_effect = urllib.error.HTTPError(
|
||||
'/', 500, 'foo', {}, None)
|
||||
result = unifi.get_scanner(self.hass, config)
|
||||
self.assertFalse(result)
|
||||
|
||||
def test_scanner_update(self): # pylint: disable=no-self-use
|
||||
"""Test the scanner update."""
|
||||
ctrl = mock.MagicMock()
|
||||
fake_clients = [
|
||||
{'mac': '123'},
|
||||
{'mac': '234'},
|
||||
]
|
||||
ctrl.get_clients.return_value = fake_clients
|
||||
unifi.UnifiScanner(ctrl)
|
||||
self.assertEqual(ctrl.get_clients.call_count, 1)
|
||||
self.assertEqual(ctrl.get_clients.call_args, mock.call())
|
||||
def test_scanner_update_error():
|
||||
"""Test the scanner update for error."""
|
||||
ctrl = mock.MagicMock()
|
||||
ctrl.get_clients.side_effect = urllib.error.HTTPError(
|
||||
'/', 500, 'foo', {}, None)
|
||||
unifi.UnifiScanner(ctrl)
|
||||
|
||||
def test_scanner_update_error(self): # pylint: disable=no-self-use
|
||||
"""Test the scanner update for error."""
|
||||
ctrl = mock.MagicMock()
|
||||
ctrl.get_clients.side_effect = urllib.error.HTTPError(
|
||||
'/', 500, 'foo', {}, None)
|
||||
unifi.UnifiScanner(ctrl)
|
||||
|
||||
def test_scan_devices(self):
|
||||
"""Test the scanning for devices."""
|
||||
ctrl = mock.MagicMock()
|
||||
fake_clients = [
|
||||
{'mac': '123'},
|
||||
{'mac': '234'},
|
||||
]
|
||||
ctrl.get_clients.return_value = fake_clients
|
||||
scanner = unifi.UnifiScanner(ctrl)
|
||||
self.assertEqual(set(['123', '234']), set(scanner.scan_devices()))
|
||||
def test_scan_devices():
|
||||
"""Test the scanning for devices."""
|
||||
ctrl = mock.MagicMock()
|
||||
fake_clients = [
|
||||
{'mac': '123'},
|
||||
{'mac': '234'},
|
||||
]
|
||||
ctrl.get_clients.return_value = fake_clients
|
||||
scanner = unifi.UnifiScanner(ctrl)
|
||||
assert set(scanner.scan_devices()) == set(['123', '234'])
|
||||
|
||||
def test_get_device_name(self):
|
||||
"""Test the getting of device names."""
|
||||
ctrl = mock.MagicMock()
|
||||
fake_clients = [
|
||||
{'mac': '123', 'hostname': 'foobar'},
|
||||
{'mac': '234', 'name': 'Nice Name'},
|
||||
{'mac': '456'},
|
||||
]
|
||||
ctrl.get_clients.return_value = fake_clients
|
||||
scanner = unifi.UnifiScanner(ctrl)
|
||||
self.assertEqual('foobar', scanner.get_device_name('123'))
|
||||
self.assertEqual('Nice Name', scanner.get_device_name('234'))
|
||||
self.assertEqual(None, scanner.get_device_name('456'))
|
||||
self.assertEqual(None, scanner.get_device_name('unknown'))
|
||||
|
||||
def test_get_device_name():
|
||||
"""Test the getting of device names."""
|
||||
ctrl = mock.MagicMock()
|
||||
fake_clients = [
|
||||
{'mac': '123', 'hostname': 'foobar'},
|
||||
{'mac': '234', 'name': 'Nice Name'},
|
||||
{'mac': '456'},
|
||||
]
|
||||
ctrl.get_clients.return_value = fake_clients
|
||||
scanner = unifi.UnifiScanner(ctrl)
|
||||
assert scanner.get_device_name('123') == 'foobar'
|
||||
assert scanner.get_device_name('234') == 'Nice Name'
|
||||
assert scanner.get_device_name('456') is None
|
||||
assert scanner.get_device_name('unknown') is None
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
"""The tests for the Cast Media player platform."""
|
||||
# pylint: disable=protected-access
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.media_player import cast
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def cast_mock():
|
||||
"""Mock pychromecast."""
|
||||
with patch.dict('sys.modules', {
|
||||
'pychromecast': MagicMock(),
|
||||
}):
|
||||
yield
|
||||
|
||||
|
||||
class FakeChromeCast(object):
|
||||
"""A fake Chrome Cast."""
|
||||
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
"""The tests for the Demo Media player platform."""
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from homeassistant.components.media_player import cmus
|
||||
from homeassistant import const
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
entity_id = 'media_player.cmus'
|
||||
|
||||
|
||||
class TestCmusMediaPlayer(unittest.TestCase):
|
||||
"""Test the media_player module."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@mock.patch('homeassistant.components.media_player.cmus.CmusDevice')
|
||||
def test_password_required_with_host(self, cmus_mock):
|
||||
"""Test that a password is required when specifying a remote host."""
|
||||
fake_config = {
|
||||
const.CONF_HOST: 'a_real_hostname',
|
||||
}
|
||||
self.assertFalse(
|
||||
cmus.setup_platform(self.hass, fake_config, mock.MagicMock()))
|
|
@ -1,42 +0,0 @@
|
|||
"""The tests for the Demo Media player platform."""
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.media_player.frontier_silicon import FSAPIDevice
|
||||
from homeassistant.components.media_player import frontier_silicon
|
||||
from homeassistant import const
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TestFrontierSiliconMediaPlayer(unittest.TestCase):
|
||||
"""Test the media_player module."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_host_required_with_host(self):
|
||||
"""Test that a host with a valid url is set when using a conf."""
|
||||
fake_config = {
|
||||
const.CONF_HOST: 'host_ip',
|
||||
}
|
||||
result = frontier_silicon.setup_platform(self.hass,
|
||||
fake_config, mock.MagicMock())
|
||||
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_invalid_host(self):
|
||||
"""Test that a host with a valid url is set when using a conf."""
|
||||
import requests
|
||||
|
||||
fsapi = FSAPIDevice('INVALID_URL', '1234')
|
||||
self.assertRaises(requests.exceptions.MissingSchema, fsapi.update)
|
|
@ -2,6 +2,8 @@
|
|||
import unittest
|
||||
import unittest.mock as mock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.components import switch
|
||||
from homeassistant.components.switch import mochad
|
||||
|
@ -9,6 +11,15 @@ from homeassistant.components.switch import mochad
|
|||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def pymochad_mock():
|
||||
"""Mock pymochad."""
|
||||
with mock.patch.dict('sys.modules', {
|
||||
'pymochad': mock.MagicMock(),
|
||||
}):
|
||||
yield
|
||||
|
||||
|
||||
class TestMochadSwitchSetup(unittest.TestCase):
|
||||
"""Test the mochad switch."""
|
||||
|
||||
|
@ -18,17 +29,14 @@ class TestMochadSwitchSetup(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
super(TestMochadSwitchSetup, self).setUp()
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everyhing that was started."""
|
||||
self.hass.stop()
|
||||
super(TestMochadSwitchSetup, self).tearDown()
|
||||
|
||||
@mock.patch('pymochad.controller.PyMochad')
|
||||
@mock.patch('homeassistant.components.switch.mochad.MochadSwitch')
|
||||
def test_setup_adds_proper_devices(self, mock_switch, mock_client):
|
||||
def test_setup_adds_proper_devices(self, mock_switch):
|
||||
"""Test if setup adds devices."""
|
||||
good_config = {
|
||||
'mochad': {},
|
||||
|
@ -50,12 +58,8 @@ class TestMochadSwitch(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
super(TestMochadSwitch, self).setUp()
|
||||
self.hass = get_test_home_assistant()
|
||||
controller_mock = mock.MagicMock()
|
||||
device_patch = mock.patch('pymochad.device.Device')
|
||||
device_patch.start()
|
||||
self.addCleanup(device_patch.stop)
|
||||
dev_dict = {'address': 'a1', 'name': 'fake_switch'}
|
||||
self.switch = mochad.MochadSwitch(self.hass, controller_mock,
|
||||
dev_dict)
|
||||
|
|
|
@ -12,7 +12,8 @@ from homeassistant.setup import setup_component
|
|||
import homeassistant.components.datadog as datadog
|
||||
import homeassistant.core as ha
|
||||
|
||||
from tests.common import (assert_setup_component, get_test_home_assistant)
|
||||
from tests.common import (assert_setup_component, get_test_home_assistant,
|
||||
MockDependency)
|
||||
|
||||
|
||||
class TestDatadog(unittest.TestCase):
|
||||
|
@ -35,10 +36,11 @@ class TestDatadog(unittest.TestCase):
|
|||
}
|
||||
})
|
||||
|
||||
@mock.patch('datadog.initialize')
|
||||
def test_datadog_setup_full(self, mock_connection):
|
||||
@MockDependency('datadog', 'beer')
|
||||
def test_datadog_setup_full(self, mock_datadog):
|
||||
"""Test setup with all data."""
|
||||
self.hass.bus.listen = mock.MagicMock()
|
||||
mock_connection = mock_datadog.initialize
|
||||
|
||||
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||
datadog.DOMAIN: {
|
||||
|
@ -61,10 +63,11 @@ class TestDatadog(unittest.TestCase):
|
|||
self.assertEqual(EVENT_STATE_CHANGED,
|
||||
self.hass.bus.listen.call_args_list[1][0][0])
|
||||
|
||||
@mock.patch('datadog.initialize')
|
||||
def test_datadog_setup_defaults(self, mock_connection):
|
||||
@MockDependency('datadog')
|
||||
def test_datadog_setup_defaults(self, mock_datadog):
|
||||
"""Test setup with defaults."""
|
||||
self.hass.bus.listen = mock.MagicMock()
|
||||
mock_connection = mock_datadog.initialize
|
||||
|
||||
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||
datadog.DOMAIN: {
|
||||
|
@ -81,10 +84,11 @@ class TestDatadog(unittest.TestCase):
|
|||
)
|
||||
self.assertTrue(self.hass.bus.listen.called)
|
||||
|
||||
@mock.patch('datadog.statsd')
|
||||
def test_logbook_entry(self, mock_client):
|
||||
@MockDependency('datadog')
|
||||
def test_logbook_entry(self, mock_datadog):
|
||||
"""Test event listener."""
|
||||
self.hass.bus.listen = mock.MagicMock()
|
||||
mock_client = mock_datadog.statsd
|
||||
|
||||
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||
datadog.DOMAIN: {
|
||||
|
@ -119,10 +123,11 @@ class TestDatadog(unittest.TestCase):
|
|||
|
||||
mock_client.event.reset_mock()
|
||||
|
||||
@mock.patch('datadog.statsd')
|
||||
def test_state_changed(self, mock_client):
|
||||
@MockDependency('datadog')
|
||||
def test_state_changed(self, mock_datadog):
|
||||
"""Test event listener."""
|
||||
self.hass.bus.listen = mock.MagicMock()
|
||||
mock_client = mock_datadog.statsd
|
||||
|
||||
assert setup_component(self.hass, datadog.DOMAIN, {
|
||||
datadog.DOMAIN: {
|
||||
|
|
|
@ -12,6 +12,8 @@ from homeassistant.setup import setup_component
|
|||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, mock_service)
|
||||
|
||||
from .test_init import mutagen_mock # noqa
|
||||
|
||||
|
||||
class TestTTSGooglePlatform(object):
|
||||
"""Test the Google speech component."""
|
||||
|
|
|
@ -4,6 +4,7 @@ import os
|
|||
import shutil
|
||||
from unittest.mock import patch, PropertyMock
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import homeassistant.components.http as http
|
||||
|
@ -19,6 +20,14 @@ from tests.common import (
|
|||
mock_service)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mutagen_mock():
|
||||
"""Mock writing tags."""
|
||||
with patch('homeassistant.components.tts.SpeechManager.write_tags',
|
||||
side_effect=lambda *args: args[1]):
|
||||
yield
|
||||
|
||||
|
||||
class TestTTS(object):
|
||||
"""Test the Google speech component."""
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.components.media_player import (
|
|||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, mock_service)
|
||||
|
||||
from .test_init import mutagen_mock # noqa
|
||||
|
||||
|
||||
class TestTTSMaryTTSPlatform(object):
|
||||
"""Test the speech component."""
|
||||
|
|
|
@ -11,6 +11,8 @@ from homeassistant.setup import setup_component
|
|||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, mock_service)
|
||||
|
||||
from .test_init import mutagen_mock # noqa
|
||||
|
||||
|
||||
class TestTTSVoiceRSSPlatform(object):
|
||||
"""Test the voicerss speech component."""
|
||||
|
|
|
@ -10,6 +10,8 @@ from homeassistant.components.media_player import (
|
|||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, mock_service)
|
||||
|
||||
from .test_init import mutagen_mock # noqa
|
||||
|
||||
|
||||
class TestTTSYandexPlatform(object):
|
||||
"""Test the speech component."""
|
||||
|
|
Loading…
Reference in New Issue