mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Fix up docstring for tests (#5090)
This commit is contained in:
parent
98efbbc129
commit
f0b1874d2d
1
setup.py
1
setup.py
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Home Assistant setup script."""
|
||||
import os
|
||||
from setuptools import setup, find_packages
|
||||
from homeassistant.const import (__version__, PROJECT_PACKAGE_NAME,
|
||||
|
@ -71,6 +71,7 @@ class TestLiteJetTrigger(unittest.TestCase):
|
||||
self.hass.stop()
|
||||
|
||||
def simulate_press(self, number):
|
||||
"""Test to simulate a press."""
|
||||
_LOGGER.info('*** simulate press of %d', number)
|
||||
callback = self.switch_pressed_callbacks.get(number)
|
||||
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
|
||||
@ -80,6 +81,7 @@ class TestLiteJetTrigger(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
|
||||
def simulate_release(self, number):
|
||||
"""Test to simulate releasing."""
|
||||
_LOGGER.info('*** simulate release of %d', number)
|
||||
callback = self.switch_released_callbacks.get(number)
|
||||
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
|
||||
@ -89,6 +91,7 @@ class TestLiteJetTrigger(unittest.TestCase):
|
||||
self.hass.block_till_done()
|
||||
|
||||
def simulate_time(self, delta):
|
||||
"""Test to simulate time."""
|
||||
_LOGGER.info(
|
||||
'*** simulate time change by %s: %s',
|
||||
delta,
|
||||
@ -102,6 +105,7 @@ class TestLiteJetTrigger(unittest.TestCase):
|
||||
_LOGGER.info('done with now=%s', dt_util.utcnow())
|
||||
|
||||
def setup_automation(self, trigger):
|
||||
"""Test setting up the automation."""
|
||||
assert bootstrap.setup_component(self.hass, automation.DOMAIN, {
|
||||
automation.DOMAIN: [
|
||||
{
|
||||
|
@ -182,9 +182,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_heater_on_within_tolerance(self):
|
||||
"""Test if temperature change doesn't turn heater on within
|
||||
tolerance.
|
||||
"""
|
||||
"""Test if temperature change doesn't turn on within tolerance."""
|
||||
self._setup_switch(False)
|
||||
climate.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
@ -206,9 +204,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_heater_off_within_tolerance(self):
|
||||
"""Test if temperature change doesn't turn heater off within
|
||||
tolerance.
|
||||
"""
|
||||
"""Test if temperature change doesn't turn off within tolerance."""
|
||||
self._setup_switch(True)
|
||||
climate.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
@ -296,9 +292,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_ac_off_within_tolerance(self):
|
||||
"""Test if temperature change doesn't turn ac off within
|
||||
tolerance.
|
||||
"""
|
||||
"""Test if temperature change doesn't turn ac off within tolerance."""
|
||||
self._setup_switch(True)
|
||||
climate.set_temperature(self.hass, 30)
|
||||
self.hass.block_till_done()
|
||||
@ -320,9 +314,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
|
||||
self.assertEqual(ENT_SWITCH, call.data['entity_id'])
|
||||
|
||||
def test_temp_change_ac_on_within_tolerance(self):
|
||||
"""Test if temperature change doesn't turn ac on within
|
||||
tolerance.
|
||||
"""
|
||||
"""Test if temperature change doesn't turn ac on within tolerance."""
|
||||
self._setup_switch(False)
|
||||
climate.set_temperature(self.hass, 25)
|
||||
self.hass.block_till_done()
|
||||
|
@ -1,3 +1,4 @@
|
||||
"""Test the Emulated Hue component."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.emulated_hue import Config, _LOGGER
|
||||
|
@ -75,7 +75,7 @@ class TestHttp:
|
||||
assert req.status_code == 403
|
||||
|
||||
def test_access_from_banned_ip_when_ban_is_off(self):
|
||||
"""Test accessing to server from banned IP when feature is off"""
|
||||
"""Test accessing to server from banned IP when feature is off."""
|
||||
hass.http.app[KEY_BANS_ENABLED] = False
|
||||
for remote_addr in BANNED_IPS:
|
||||
with patch('homeassistant.components.http.'
|
||||
@ -87,7 +87,7 @@ class TestHttp:
|
||||
assert req.status_code == 200
|
||||
|
||||
def test_ip_bans_file_creation(self):
|
||||
"""Testing if banned IP file created"""
|
||||
"""Testing if banned IP file created."""
|
||||
hass.http.app[KEY_BANS_ENABLED] = True
|
||||
hass.http.app[KEY_LOGIN_THRESHOLD] = 1
|
||||
|
||||
|
@ -63,7 +63,6 @@ class TestCors:
|
||||
|
||||
def test_cors_allowed_with_password_in_url(self):
|
||||
"""Test cross origin resource sharing with password in url."""
|
||||
|
||||
req = requests.get(_url(const.URL_API),
|
||||
params={'api_password': API_PASSWORD},
|
||||
headers={const.HTTP_HEADER_ORIGIN: HTTP_BASE_URL})
|
||||
@ -119,6 +118,7 @@ class TestCors:
|
||||
|
||||
|
||||
class TestView(http.HomeAssistantView):
|
||||
"""Test the HTTP views."""
|
||||
|
||||
name = 'test'
|
||||
url = '/hello'
|
||||
@ -159,7 +159,6 @@ def test_registering_view_while_running(hass, test_client):
|
||||
|
||||
def test_api_base_url(loop):
|
||||
"""Test setting api url."""
|
||||
|
||||
hass = MagicMock()
|
||||
hass.loop = loop
|
||||
|
||||
|
@ -60,9 +60,11 @@ class TestLiteJetLight(unittest.TestCase):
|
||||
self.mock_lj.get_load_level.reset_mock()
|
||||
|
||||
def light(self):
|
||||
"""Test for main light entity."""
|
||||
return self.hass.states.get(ENTITY_LIGHT)
|
||||
|
||||
def other_light(self):
|
||||
"""Test the other light."""
|
||||
return self.hass.states.get(ENTITY_OTHER_LIGHT)
|
||||
|
||||
def teardown_method(self, method):
|
||||
@ -71,7 +73,6 @@ class TestLiteJetLight(unittest.TestCase):
|
||||
|
||||
def test_on_brightness(self):
|
||||
"""Test turning the light on with brightness."""
|
||||
|
||||
assert self.light().state == 'off'
|
||||
assert self.other_light().state == 'off'
|
||||
|
||||
@ -84,7 +85,6 @@ class TestLiteJetLight(unittest.TestCase):
|
||||
|
||||
def test_on_off(self):
|
||||
"""Test turning the light on and off."""
|
||||
|
||||
assert self.light().state == 'off'
|
||||
assert self.other_light().state == 'off'
|
||||
|
||||
@ -100,7 +100,6 @@ class TestLiteJetLight(unittest.TestCase):
|
||||
|
||||
def test_activated_event(self):
|
||||
"""Test handling an event from LiteJet."""
|
||||
|
||||
self.mock_lj.get_load_level.return_value = 99
|
||||
|
||||
# Light 1
|
||||
@ -138,7 +137,6 @@ class TestLiteJetLight(unittest.TestCase):
|
||||
|
||||
def test_deactivated_event(self):
|
||||
"""Test handling an event from LiteJet."""
|
||||
|
||||
# Initial state is on.
|
||||
|
||||
self.mock_lj.get_load_level.return_value = 99
|
||||
|
@ -30,6 +30,7 @@ class MockDevice(STD):
|
||||
"""Mock device."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init the class."""
|
||||
self._config = MockConfig
|
||||
|
||||
|
||||
@ -37,6 +38,7 @@ class MockConfig(Config):
|
||||
"""Mock config."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init class."""
|
||||
self._name = "name"
|
||||
|
||||
|
||||
@ -49,6 +51,7 @@ class MockPreset(Preset):
|
||||
"""Mock preset."""
|
||||
|
||||
def __init__(self, id):
|
||||
"""Init the class."""
|
||||
self._id = id
|
||||
self._name = "preset"
|
||||
|
||||
@ -57,6 +60,7 @@ class MockVolume(Volume):
|
||||
"""Mock volume with value."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init class."""
|
||||
self._actual = 12
|
||||
|
||||
|
||||
@ -64,6 +68,7 @@ class MockVolumeMuted(Volume):
|
||||
"""Mock volume muted."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init the class."""
|
||||
self._actual = 12
|
||||
self._muted = True
|
||||
|
||||
@ -72,6 +77,7 @@ class MockStatusStandby(Status):
|
||||
"""Mock status standby."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init the class."""
|
||||
self._source = "STANDBY"
|
||||
|
||||
|
||||
@ -79,6 +85,7 @@ class MockStatusPlaying(Status):
|
||||
"""Mock status playing media."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init the class."""
|
||||
self._source = ""
|
||||
self._play_status = "PLAY_STATE"
|
||||
self._image = "image.url"
|
||||
@ -93,6 +100,7 @@ class MockStatusPlayingRadio(Status):
|
||||
"""Mock status radio."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init the class."""
|
||||
self._source = ""
|
||||
self._play_status = "PLAY_STATE"
|
||||
self._image = "image.url"
|
||||
@ -107,6 +115,7 @@ class MockStatusUnknown(Status):
|
||||
"""Mock status unknown media."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init the class."""
|
||||
self._source = ""
|
||||
self._play_status = "PLAY_STATE"
|
||||
self._image = "image.url"
|
||||
@ -121,6 +130,7 @@ class MockStatusPause(Status):
|
||||
"""Mock status pause."""
|
||||
|
||||
def __init__(self):
|
||||
"""Init the class."""
|
||||
self._source = ""
|
||||
self._play_status = "PAUSE_STATE"
|
||||
|
||||
|
@ -20,6 +20,7 @@ class FakeYamaha(rxv.rxv.RXV):
|
||||
ensure that usage of the rxv library by HomeAssistant is as we'd
|
||||
expect.
|
||||
"""
|
||||
|
||||
_fake_input = 'HDMI1'
|
||||
|
||||
def _discover_features(self):
|
||||
@ -75,7 +76,7 @@ class TestYamaha(unittest.TestCase):
|
||||
self.rec = FakeYamaha('10.0.0.0')
|
||||
|
||||
def test_get_playback_support(self):
|
||||
"""Test the playback"""
|
||||
"""Test the playback."""
|
||||
rec = self.rec
|
||||
support = rec.get_playback_support()
|
||||
self.assertFalse(support.play)
|
||||
|
@ -30,7 +30,6 @@ class TestDemoRemote(unittest.TestCase):
|
||||
|
||||
def test_methods(self):
|
||||
"""Test if methods call the services as expected."""
|
||||
|
||||
self.assertTrue(
|
||||
setup_component(self.hass, remote.DOMAIN,
|
||||
{remote.DOMAIN: {CONF_PLATFORM: 'demo'}}))
|
||||
@ -50,7 +49,6 @@ class TestDemoRemote(unittest.TestCase):
|
||||
|
||||
def test_services(self):
|
||||
"""Test the provided services."""
|
||||
|
||||
# Test turn_on
|
||||
turn_on_calls = mock_service(
|
||||
self.hass, remote.DOMAIN, SERVICE_TURN_ON)
|
||||
|
@ -28,7 +28,7 @@ class TestRemote(unittest.TestCase):
|
||||
self.hass.stop()
|
||||
|
||||
def test_is_on(self):
|
||||
""" Test is_on"""
|
||||
"""Test is_on."""
|
||||
self.hass.states.set('remote.test', STATE_ON)
|
||||
self.assertTrue(remote.is_on(self.hass, 'remote.test'))
|
||||
|
||||
@ -42,7 +42,7 @@ class TestRemote(unittest.TestCase):
|
||||
self.assertFalse(remote.is_on(self.hass))
|
||||
|
||||
def test_turn_on(self):
|
||||
""" Test turn_on"""
|
||||
"""Test turn_on."""
|
||||
turn_on_calls = mock_service(
|
||||
self.hass, remote.DOMAIN, SERVICE_TURN_ON)
|
||||
|
||||
@ -58,7 +58,7 @@ class TestRemote(unittest.TestCase):
|
||||
self.assertEqual(remote.DOMAIN, call.domain)
|
||||
|
||||
def test_turn_off(self):
|
||||
""" Test turn_off"""
|
||||
"""Test turn_off."""
|
||||
turn_off_calls = mock_service(
|
||||
self.hass, remote.DOMAIN, SERVICE_TURN_OFF)
|
||||
|
||||
@ -75,7 +75,7 @@ class TestRemote(unittest.TestCase):
|
||||
self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
|
||||
|
||||
def test_send_command(self):
|
||||
""" Test send_command"""
|
||||
"""Test send_command."""
|
||||
send_command_calls = mock_service(
|
||||
self.hass, remote.DOMAIN, SERVICE_SEND_COMMAND)
|
||||
|
||||
|
@ -50,14 +50,15 @@ class TestLiteJetScene(unittest.TestCase):
|
||||
self.hass.stop()
|
||||
|
||||
def scene(self):
|
||||
"""Get the current scene."""
|
||||
return self.hass.states.get(ENTITY_SCENE)
|
||||
|
||||
def other_scene(self):
|
||||
"""Get the other scene."""
|
||||
return self.hass.states.get(ENTITY_OTHER_SCENE)
|
||||
|
||||
def test_activate(self):
|
||||
"""Test activating the scene."""
|
||||
|
||||
scene.activate(self.hass, ENTITY_SCENE)
|
||||
self.hass.block_till_done()
|
||||
self.mock_lj.activate_scene.assert_called_once_with(
|
||||
|
@ -1,3 +1,4 @@
|
||||
"""Test cases for the API stream sensor."""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
|
@ -574,7 +574,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_diskspace_no_paths(self, req_mock):
|
||||
"""Tests getting all disk space"""
|
||||
"""Test getting all disk space."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -599,7 +599,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_diskspace_paths(self, req_mock):
|
||||
"""Tests getting diskspace for included paths"""
|
||||
"""Test getting diskspace for included paths."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -626,7 +626,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_commands(self, req_mock):
|
||||
"""Tests getting running commands"""
|
||||
"""Test getting running commands."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -653,7 +653,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_queue(self, req_mock):
|
||||
"""Tests getting downloads in the queue"""
|
||||
"""Test getting downloads in the queue."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -680,7 +680,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_series(self, req_mock):
|
||||
"""Tests getting the number of series"""
|
||||
"""Test getting the number of series."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -707,7 +707,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_wanted(self, req_mock):
|
||||
"""Tests getting wanted episodes"""
|
||||
"""Test getting wanted episodes."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -734,7 +734,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_upcoming_multiple_days(self, req_mock):
|
||||
"""Tests upcoming episodes for multiple days"""
|
||||
"""Test the upcoming episodes for multiple days."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -762,8 +762,8 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
@pytest.mark.skip
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_upcoming_today(self, req_mock):
|
||||
"""
|
||||
Tests filtering for a single day.
|
||||
"""Test filtering for a single day.
|
||||
|
||||
Sonarr needs to respond with at least 2 days
|
||||
"""
|
||||
config = {
|
||||
@ -793,7 +793,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
@pytest.mark.skip
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
|
||||
def test_ssl(self, req_mock):
|
||||
"""Tests SSL being enabled"""
|
||||
"""Test SSL being enabled."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
@ -822,7 +822,7 @@ class TestSonarrSetup(unittest.TestCase):
|
||||
|
||||
@unittest.mock.patch('requests.get', side_effect=mocked_exception)
|
||||
def test_exception_handling(self, req_mock):
|
||||
"""Tests exception being handled"""
|
||||
"""Test exception being handled."""
|
||||
config = {
|
||||
'platform': 'sonarr',
|
||||
'api_key': 'foo',
|
||||
|
@ -185,7 +185,7 @@ class TestCommandSwitch(unittest.TestCase):
|
||||
self.assertFalse(state_device.assumed_state)
|
||||
|
||||
def test_entity_id_set_correctly(self):
|
||||
"""Test that entity_id is set correctly from object_id"""
|
||||
"""Test that entity_id is set correctly from object_id."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
init_args = [
|
||||
|
@ -64,26 +64,25 @@ class TestLiteJetSwitch(unittest.TestCase):
|
||||
self.hass.stop()
|
||||
|
||||
def switch(self):
|
||||
"""Return the switch state."""
|
||||
return self.hass.states.get(ENTITY_SWITCH)
|
||||
|
||||
def other_switch(self):
|
||||
"""Return the other switch state."""
|
||||
return self.hass.states.get(ENTITY_OTHER_SWITCH)
|
||||
|
||||
def test_include_switches_unspecified(self):
|
||||
"""Test that switches are ignored by default."""
|
||||
|
||||
self.mock_lj.button_switches.assert_not_called()
|
||||
self.mock_lj.all_switches.assert_not_called()
|
||||
|
||||
def test_include_switches_False(self):
|
||||
"""Test that switches can be explicitly ignored."""
|
||||
|
||||
self.mock_lj.button_switches.assert_not_called()
|
||||
self.mock_lj.all_switches.assert_not_called()
|
||||
|
||||
def test_on_off(self):
|
||||
"""Test turning the switch on and off."""
|
||||
|
||||
assert self.switch().state == 'off'
|
||||
assert self.other_switch().state == 'off'
|
||||
|
||||
@ -99,9 +98,7 @@ class TestLiteJetSwitch(unittest.TestCase):
|
||||
|
||||
def test_pressed_event(self):
|
||||
"""Test handling an event from LiteJet."""
|
||||
|
||||
# Switch 1
|
||||
|
||||
_LOGGER.info(self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER])
|
||||
self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]()
|
||||
self.hass.block_till_done()
|
||||
@ -112,7 +109,6 @@ class TestLiteJetSwitch(unittest.TestCase):
|
||||
assert self.other_switch().state == 'off'
|
||||
|
||||
# Switch 2
|
||||
|
||||
self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]()
|
||||
self.hass.block_till_done()
|
||||
|
||||
@ -123,9 +119,7 @@ class TestLiteJetSwitch(unittest.TestCase):
|
||||
|
||||
def test_released_event(self):
|
||||
"""Test handling an event from LiteJet."""
|
||||
|
||||
# Initial state is on.
|
||||
|
||||
self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]()
|
||||
self.hass.block_till_done()
|
||||
|
||||
|
@ -22,16 +22,19 @@ class TestLiteJet(unittest.TestCase):
|
||||
self.hass.stop()
|
||||
|
||||
def test_is_ignored_unspecified(self):
|
||||
"""Ensure it is ignored when unspecified."""
|
||||
self.hass.data['litejet_config'] = {}
|
||||
assert not litejet.is_ignored(self.hass, 'Test')
|
||||
|
||||
def test_is_ignored_empty(self):
|
||||
"""Ensure it is ignored when empty."""
|
||||
self.hass.data['litejet_config'] = {
|
||||
litejet.CONF_EXCLUDE_NAMES: []
|
||||
}
|
||||
assert not litejet.is_ignored(self.hass, 'Test')
|
||||
|
||||
def test_is_ignored_normal(self):
|
||||
"""Test if usually ignored."""
|
||||
self.hass.data['litejet_config'] = {
|
||||
litejet.CONF_EXCLUDE_NAMES: ['Test', 'Other One']
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
"""Tests for the Home Assistant Websocket API."""
|
||||
import asyncio
|
||||
from unittest.mock import patch
|
||||
|
||||
@ -213,7 +214,7 @@ def test_subscribe_unsubscribe_events(hass, websocket_client):
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_states(hass, websocket_client):
|
||||
""" Test get_states command."""
|
||||
"""Test get_states command."""
|
||||
hass.states.async_set('greeting.hello', 'world')
|
||||
hass.states.async_set('greeting.bye', 'universe')
|
||||
|
||||
@ -239,7 +240,7 @@ def test_get_states(hass, websocket_client):
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_services(hass, websocket_client):
|
||||
""" Test get_services command."""
|
||||
"""Test get_services command."""
|
||||
websocket_client.send_json({
|
||||
'id': 5,
|
||||
'type': wapi.TYPE_GET_SERVICES,
|
||||
@ -254,7 +255,7 @@ def test_get_services(hass, websocket_client):
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_config(hass, websocket_client):
|
||||
""" Test get_config command."""
|
||||
"""Test get_config command."""
|
||||
websocket_client.send_json({
|
||||
'id': 5,
|
||||
'type': wapi.TYPE_GET_CONFIG,
|
||||
@ -269,7 +270,7 @@ def test_get_config(hass, websocket_client):
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_panels(hass, websocket_client):
|
||||
""" Test get_panels command."""
|
||||
"""Test get_panels command."""
|
||||
frontend.register_built_in_panel(hass, 'map', 'Map',
|
||||
'mdi:account-location')
|
||||
|
||||
@ -287,7 +288,7 @@ def test_get_panels(hass, websocket_client):
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_ping(websocket_client):
|
||||
""" Test get_panels command."""
|
||||
"""Test get_panels command."""
|
||||
websocket_client.send_json({
|
||||
'id': 5,
|
||||
'type': wapi.TYPE_PING,
|
||||
|
@ -86,6 +86,7 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
|
||||
"""Test case for asyncio.run_coroutine_threadsafe."""
|
||||
|
||||
def setUp(self):
|
||||
"""Test setup method."""
|
||||
self.loop = asyncio.new_event_loop()
|
||||
self.set_event_loop(self.loop) # Will cleanup properly
|
||||
|
||||
@ -126,16 +127,14 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
|
||||
self.assertEqual(result, 3)
|
||||
|
||||
def test_run_coroutine_threadsafe_with_exception(self):
|
||||
"""Test coroutine submission from a thread to an event loop
|
||||
when an exception is raised."""
|
||||
"""Test coroutine submission from thread to event loop on exception."""
|
||||
future = self.loop.run_in_executor(None, self.target, True)
|
||||
with self.assertRaises(RuntimeError) as exc_context:
|
||||
self.loop.run_until_complete(future)
|
||||
self.assertIn("Fail!", exc_context.exception.args)
|
||||
|
||||
def test_run_coroutine_threadsafe_with_timeout(self):
|
||||
"""Test coroutine submission from a thread to an event loop
|
||||
when a timeout is raised."""
|
||||
"""Test coroutine submission from thread to event loop on timeout."""
|
||||
callback = lambda: self.target(timeout=0) # noqa
|
||||
future = self.loop.run_in_executor(None, callback)
|
||||
with self.assertRaises(asyncio.TimeoutError):
|
||||
@ -146,8 +145,7 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
|
||||
self.assertTrue(task.done())
|
||||
|
||||
def test_run_coroutine_threadsafe_task_cancelled(self):
|
||||
"""Test coroutine submission from a tread to an event loop
|
||||
when the task is cancelled."""
|
||||
"""Test coroutine submission from tread to event loop on cancel."""
|
||||
callback = lambda: self.target(cancel=True) # noqa
|
||||
future = self.loop.run_in_executor(None, callback)
|
||||
with self.assertRaises(asyncio.CancelledError):
|
||||
|
Loading…
x
Reference in New Issue
Block a user