Fix up docstring for tests (#5090)

This commit is contained in:
Johann Kellerman 2016-12-28 20:04:59 +02:00 committed by GitHub
parent 98efbbc129
commit f0b1874d2d
19 changed files with 61 additions and 59 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Home Assistant setup script."""
import os import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
from homeassistant.const import (__version__, PROJECT_PACKAGE_NAME, from homeassistant.const import (__version__, PROJECT_PACKAGE_NAME,

View file

@ -71,6 +71,7 @@ class TestLiteJetTrigger(unittest.TestCase):
self.hass.stop() self.hass.stop()
def simulate_press(self, number): def simulate_press(self, number):
"""Test to simulate a press."""
_LOGGER.info('*** simulate press of %d', number) _LOGGER.info('*** simulate press of %d', number)
callback = self.switch_pressed_callbacks.get(number) callback = self.switch_pressed_callbacks.get(number)
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow', with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
@ -80,6 +81,7 @@ class TestLiteJetTrigger(unittest.TestCase):
self.hass.block_till_done() self.hass.block_till_done()
def simulate_release(self, number): def simulate_release(self, number):
"""Test to simulate releasing."""
_LOGGER.info('*** simulate release of %d', number) _LOGGER.info('*** simulate release of %d', number)
callback = self.switch_released_callbacks.get(number) callback = self.switch_released_callbacks.get(number)
with mock.patch('homeassistant.helpers.condition.dt_util.utcnow', with mock.patch('homeassistant.helpers.condition.dt_util.utcnow',
@ -89,6 +91,7 @@ class TestLiteJetTrigger(unittest.TestCase):
self.hass.block_till_done() self.hass.block_till_done()
def simulate_time(self, delta): def simulate_time(self, delta):
"""Test to simulate time."""
_LOGGER.info( _LOGGER.info(
'*** simulate time change by %s: %s', '*** simulate time change by %s: %s',
delta, delta,
@ -102,6 +105,7 @@ class TestLiteJetTrigger(unittest.TestCase):
_LOGGER.info('done with now=%s', dt_util.utcnow()) _LOGGER.info('done with now=%s', dt_util.utcnow())
def setup_automation(self, trigger): def setup_automation(self, trigger):
"""Test setting up the automation."""
assert bootstrap.setup_component(self.hass, automation.DOMAIN, { assert bootstrap.setup_component(self.hass, automation.DOMAIN, {
automation.DOMAIN: [ automation.DOMAIN: [
{ {

View file

@ -182,9 +182,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
self.assertEqual(ENT_SWITCH, call.data['entity_id']) self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_temp_change_heater_on_within_tolerance(self): def test_temp_change_heater_on_within_tolerance(self):
"""Test if temperature change doesn't turn heater on within """Test if temperature change doesn't turn on within tolerance."""
tolerance.
"""
self._setup_switch(False) self._setup_switch(False)
climate.set_temperature(self.hass, 30) climate.set_temperature(self.hass, 30)
self.hass.block_till_done() self.hass.block_till_done()
@ -206,9 +204,7 @@ class TestClimateGenericThermostat(unittest.TestCase):
self.assertEqual(ENT_SWITCH, call.data['entity_id']) self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_temp_change_heater_off_within_tolerance(self): def test_temp_change_heater_off_within_tolerance(self):
"""Test if temperature change doesn't turn heater off within """Test if temperature change doesn't turn off within tolerance."""
tolerance.
"""
self._setup_switch(True) self._setup_switch(True)
climate.set_temperature(self.hass, 30) climate.set_temperature(self.hass, 30)
self.hass.block_till_done() self.hass.block_till_done()
@ -296,9 +292,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
self.assertEqual(ENT_SWITCH, call.data['entity_id']) self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_temp_change_ac_off_within_tolerance(self): def test_temp_change_ac_off_within_tolerance(self):
"""Test if temperature change doesn't turn ac off within """Test if temperature change doesn't turn ac off within tolerance."""
tolerance.
"""
self._setup_switch(True) self._setup_switch(True)
climate.set_temperature(self.hass, 30) climate.set_temperature(self.hass, 30)
self.hass.block_till_done() self.hass.block_till_done()
@ -320,9 +314,7 @@ class TestClimateGenericThermostatACMode(unittest.TestCase):
self.assertEqual(ENT_SWITCH, call.data['entity_id']) self.assertEqual(ENT_SWITCH, call.data['entity_id'])
def test_temp_change_ac_on_within_tolerance(self): def test_temp_change_ac_on_within_tolerance(self):
"""Test if temperature change doesn't turn ac on within """Test if temperature change doesn't turn ac on within tolerance."""
tolerance.
"""
self._setup_switch(False) self._setup_switch(False)
climate.set_temperature(self.hass, 25) climate.set_temperature(self.hass, 25)
self.hass.block_till_done() self.hass.block_till_done()

View file

@ -1,3 +1,4 @@
"""Test the Emulated Hue component."""
from unittest.mock import patch from unittest.mock import patch
from homeassistant.components.emulated_hue import Config, _LOGGER from homeassistant.components.emulated_hue import Config, _LOGGER

View file

@ -75,7 +75,7 @@ class TestHttp:
assert req.status_code == 403 assert req.status_code == 403
def test_access_from_banned_ip_when_ban_is_off(self): 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 hass.http.app[KEY_BANS_ENABLED] = False
for remote_addr in BANNED_IPS: for remote_addr in BANNED_IPS:
with patch('homeassistant.components.http.' with patch('homeassistant.components.http.'
@ -87,7 +87,7 @@ class TestHttp:
assert req.status_code == 200 assert req.status_code == 200
def test_ip_bans_file_creation(self): 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_BANS_ENABLED] = True
hass.http.app[KEY_LOGIN_THRESHOLD] = 1 hass.http.app[KEY_LOGIN_THRESHOLD] = 1

View file

@ -63,7 +63,6 @@ class TestCors:
def test_cors_allowed_with_password_in_url(self): def test_cors_allowed_with_password_in_url(self):
"""Test cross origin resource sharing with password in url.""" """Test cross origin resource sharing with password in url."""
req = requests.get(_url(const.URL_API), req = requests.get(_url(const.URL_API),
params={'api_password': API_PASSWORD}, params={'api_password': API_PASSWORD},
headers={const.HTTP_HEADER_ORIGIN: HTTP_BASE_URL}) headers={const.HTTP_HEADER_ORIGIN: HTTP_BASE_URL})
@ -119,6 +118,7 @@ class TestCors:
class TestView(http.HomeAssistantView): class TestView(http.HomeAssistantView):
"""Test the HTTP views."""
name = 'test' name = 'test'
url = '/hello' url = '/hello'
@ -159,7 +159,6 @@ def test_registering_view_while_running(hass, test_client):
def test_api_base_url(loop): def test_api_base_url(loop):
"""Test setting api url.""" """Test setting api url."""
hass = MagicMock() hass = MagicMock()
hass.loop = loop hass.loop = loop

View file

@ -60,9 +60,11 @@ class TestLiteJetLight(unittest.TestCase):
self.mock_lj.get_load_level.reset_mock() self.mock_lj.get_load_level.reset_mock()
def light(self): def light(self):
"""Test for main light entity."""
return self.hass.states.get(ENTITY_LIGHT) return self.hass.states.get(ENTITY_LIGHT)
def other_light(self): def other_light(self):
"""Test the other light."""
return self.hass.states.get(ENTITY_OTHER_LIGHT) return self.hass.states.get(ENTITY_OTHER_LIGHT)
def teardown_method(self, method): def teardown_method(self, method):
@ -71,7 +73,6 @@ class TestLiteJetLight(unittest.TestCase):
def test_on_brightness(self): def test_on_brightness(self):
"""Test turning the light on with brightness.""" """Test turning the light on with brightness."""
assert self.light().state == 'off' assert self.light().state == 'off'
assert self.other_light().state == 'off' assert self.other_light().state == 'off'
@ -84,7 +85,6 @@ class TestLiteJetLight(unittest.TestCase):
def test_on_off(self): def test_on_off(self):
"""Test turning the light on and off.""" """Test turning the light on and off."""
assert self.light().state == 'off' assert self.light().state == 'off'
assert self.other_light().state == 'off' assert self.other_light().state == 'off'
@ -100,7 +100,6 @@ class TestLiteJetLight(unittest.TestCase):
def test_activated_event(self): def test_activated_event(self):
"""Test handling an event from LiteJet.""" """Test handling an event from LiteJet."""
self.mock_lj.get_load_level.return_value = 99 self.mock_lj.get_load_level.return_value = 99
# Light 1 # Light 1
@ -138,7 +137,6 @@ class TestLiteJetLight(unittest.TestCase):
def test_deactivated_event(self): def test_deactivated_event(self):
"""Test handling an event from LiteJet.""" """Test handling an event from LiteJet."""
# Initial state is on. # Initial state is on.
self.mock_lj.get_load_level.return_value = 99 self.mock_lj.get_load_level.return_value = 99

View file

@ -30,6 +30,7 @@ class MockDevice(STD):
"""Mock device.""" """Mock device."""
def __init__(self): def __init__(self):
"""Init the class."""
self._config = MockConfig self._config = MockConfig
@ -37,6 +38,7 @@ class MockConfig(Config):
"""Mock config.""" """Mock config."""
def __init__(self): def __init__(self):
"""Init class."""
self._name = "name" self._name = "name"
@ -49,6 +51,7 @@ class MockPreset(Preset):
"""Mock preset.""" """Mock preset."""
def __init__(self, id): def __init__(self, id):
"""Init the class."""
self._id = id self._id = id
self._name = "preset" self._name = "preset"
@ -57,6 +60,7 @@ class MockVolume(Volume):
"""Mock volume with value.""" """Mock volume with value."""
def __init__(self): def __init__(self):
"""Init class."""
self._actual = 12 self._actual = 12
@ -64,6 +68,7 @@ class MockVolumeMuted(Volume):
"""Mock volume muted.""" """Mock volume muted."""
def __init__(self): def __init__(self):
"""Init the class."""
self._actual = 12 self._actual = 12
self._muted = True self._muted = True
@ -72,6 +77,7 @@ class MockStatusStandby(Status):
"""Mock status standby.""" """Mock status standby."""
def __init__(self): def __init__(self):
"""Init the class."""
self._source = "STANDBY" self._source = "STANDBY"
@ -79,6 +85,7 @@ class MockStatusPlaying(Status):
"""Mock status playing media.""" """Mock status playing media."""
def __init__(self): def __init__(self):
"""Init the class."""
self._source = "" self._source = ""
self._play_status = "PLAY_STATE" self._play_status = "PLAY_STATE"
self._image = "image.url" self._image = "image.url"
@ -93,6 +100,7 @@ class MockStatusPlayingRadio(Status):
"""Mock status radio.""" """Mock status radio."""
def __init__(self): def __init__(self):
"""Init the class."""
self._source = "" self._source = ""
self._play_status = "PLAY_STATE" self._play_status = "PLAY_STATE"
self._image = "image.url" self._image = "image.url"
@ -107,6 +115,7 @@ class MockStatusUnknown(Status):
"""Mock status unknown media.""" """Mock status unknown media."""
def __init__(self): def __init__(self):
"""Init the class."""
self._source = "" self._source = ""
self._play_status = "PLAY_STATE" self._play_status = "PLAY_STATE"
self._image = "image.url" self._image = "image.url"
@ -121,6 +130,7 @@ class MockStatusPause(Status):
"""Mock status pause.""" """Mock status pause."""
def __init__(self): def __init__(self):
"""Init the class."""
self._source = "" self._source = ""
self._play_status = "PAUSE_STATE" self._play_status = "PAUSE_STATE"

View file

@ -20,6 +20,7 @@ class FakeYamaha(rxv.rxv.RXV):
ensure that usage of the rxv library by HomeAssistant is as we'd ensure that usage of the rxv library by HomeAssistant is as we'd
expect. expect.
""" """
_fake_input = 'HDMI1' _fake_input = 'HDMI1'
def _discover_features(self): def _discover_features(self):
@ -75,7 +76,7 @@ class TestYamaha(unittest.TestCase):
self.rec = FakeYamaha('10.0.0.0') self.rec = FakeYamaha('10.0.0.0')
def test_get_playback_support(self): def test_get_playback_support(self):
"""Test the playback""" """Test the playback."""
rec = self.rec rec = self.rec
support = rec.get_playback_support() support = rec.get_playback_support()
self.assertFalse(support.play) self.assertFalse(support.play)

View file

@ -30,7 +30,6 @@ class TestDemoRemote(unittest.TestCase):
def test_methods(self): def test_methods(self):
"""Test if methods call the services as expected.""" """Test if methods call the services as expected."""
self.assertTrue( self.assertTrue(
setup_component(self.hass, remote.DOMAIN, setup_component(self.hass, remote.DOMAIN,
{remote.DOMAIN: {CONF_PLATFORM: 'demo'}})) {remote.DOMAIN: {CONF_PLATFORM: 'demo'}}))
@ -50,7 +49,6 @@ class TestDemoRemote(unittest.TestCase):
def test_services(self): def test_services(self):
"""Test the provided services.""" """Test the provided services."""
# Test turn_on # Test turn_on
turn_on_calls = mock_service( turn_on_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_TURN_ON) self.hass, remote.DOMAIN, SERVICE_TURN_ON)

View file

@ -28,7 +28,7 @@ class TestRemote(unittest.TestCase):
self.hass.stop() self.hass.stop()
def test_is_on(self): def test_is_on(self):
""" Test is_on""" """Test is_on."""
self.hass.states.set('remote.test', STATE_ON) self.hass.states.set('remote.test', STATE_ON)
self.assertTrue(remote.is_on(self.hass, 'remote.test')) self.assertTrue(remote.is_on(self.hass, 'remote.test'))
@ -42,7 +42,7 @@ class TestRemote(unittest.TestCase):
self.assertFalse(remote.is_on(self.hass)) self.assertFalse(remote.is_on(self.hass))
def test_turn_on(self): def test_turn_on(self):
""" Test turn_on""" """Test turn_on."""
turn_on_calls = mock_service( turn_on_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_TURN_ON) self.hass, remote.DOMAIN, SERVICE_TURN_ON)
@ -58,7 +58,7 @@ class TestRemote(unittest.TestCase):
self.assertEqual(remote.DOMAIN, call.domain) self.assertEqual(remote.DOMAIN, call.domain)
def test_turn_off(self): def test_turn_off(self):
""" Test turn_off""" """Test turn_off."""
turn_off_calls = mock_service( turn_off_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_TURN_OFF) 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]) self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
def test_send_command(self): def test_send_command(self):
""" Test send_command""" """Test send_command."""
send_command_calls = mock_service( send_command_calls = mock_service(
self.hass, remote.DOMAIN, SERVICE_SEND_COMMAND) self.hass, remote.DOMAIN, SERVICE_SEND_COMMAND)

View file

@ -50,14 +50,15 @@ class TestLiteJetScene(unittest.TestCase):
self.hass.stop() self.hass.stop()
def scene(self): def scene(self):
"""Get the current scene."""
return self.hass.states.get(ENTITY_SCENE) return self.hass.states.get(ENTITY_SCENE)
def other_scene(self): def other_scene(self):
"""Get the other scene."""
return self.hass.states.get(ENTITY_OTHER_SCENE) return self.hass.states.get(ENTITY_OTHER_SCENE)
def test_activate(self): def test_activate(self):
"""Test activating the scene.""" """Test activating the scene."""
scene.activate(self.hass, ENTITY_SCENE) scene.activate(self.hass, ENTITY_SCENE)
self.hass.block_till_done() self.hass.block_till_done()
self.mock_lj.activate_scene.assert_called_once_with( self.mock_lj.activate_scene.assert_called_once_with(

View file

@ -1,3 +1,4 @@
"""Test cases for the API stream sensor."""
import asyncio import asyncio
import logging import logging

View file

@ -574,7 +574,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_diskspace_no_paths(self, req_mock): def test_diskspace_no_paths(self, req_mock):
"""Tests getting all disk space""" """Test getting all disk space."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -599,7 +599,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_diskspace_paths(self, req_mock): def test_diskspace_paths(self, req_mock):
"""Tests getting diskspace for included paths""" """Test getting diskspace for included paths."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -626,7 +626,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_commands(self, req_mock): def test_commands(self, req_mock):
"""Tests getting running commands""" """Test getting running commands."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -653,7 +653,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_queue(self, req_mock): def test_queue(self, req_mock):
"""Tests getting downloads in the queue""" """Test getting downloads in the queue."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -680,7 +680,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_series(self, req_mock): def test_series(self, req_mock):
"""Tests getting the number of series""" """Test getting the number of series."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -707,7 +707,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_wanted(self, req_mock): def test_wanted(self, req_mock):
"""Tests getting wanted episodes""" """Test getting wanted episodes."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -734,7 +734,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_upcoming_multiple_days(self, req_mock): def test_upcoming_multiple_days(self, req_mock):
"""Tests upcoming episodes for multiple days""" """Test the upcoming episodes for multiple days."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -762,8 +762,8 @@ class TestSonarrSetup(unittest.TestCase):
@pytest.mark.skip @pytest.mark.skip
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_upcoming_today(self, req_mock): def test_upcoming_today(self, req_mock):
""" """Test filtering for a single day.
Tests filtering for a single day.
Sonarr needs to respond with at least 2 days Sonarr needs to respond with at least 2 days
""" """
config = { config = {
@ -793,7 +793,7 @@ class TestSonarrSetup(unittest.TestCase):
@pytest.mark.skip @pytest.mark.skip
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get) @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_ssl(self, req_mock): def test_ssl(self, req_mock):
"""Tests SSL being enabled""" """Test SSL being enabled."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',
@ -822,7 +822,7 @@ class TestSonarrSetup(unittest.TestCase):
@unittest.mock.patch('requests.get', side_effect=mocked_exception) @unittest.mock.patch('requests.get', side_effect=mocked_exception)
def test_exception_handling(self, req_mock): def test_exception_handling(self, req_mock):
"""Tests exception being handled""" """Test exception being handled."""
config = { config = {
'platform': 'sonarr', 'platform': 'sonarr',
'api_key': 'foo', 'api_key': 'foo',

View file

@ -185,7 +185,7 @@ class TestCommandSwitch(unittest.TestCase):
self.assertFalse(state_device.assumed_state) self.assertFalse(state_device.assumed_state)
def test_entity_id_set_correctly(self): 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() self.hass = get_test_home_assistant()
init_args = [ init_args = [

View file

@ -64,26 +64,25 @@ class TestLiteJetSwitch(unittest.TestCase):
self.hass.stop() self.hass.stop()
def switch(self): def switch(self):
"""Return the switch state."""
return self.hass.states.get(ENTITY_SWITCH) return self.hass.states.get(ENTITY_SWITCH)
def other_switch(self): def other_switch(self):
"""Return the other switch state."""
return self.hass.states.get(ENTITY_OTHER_SWITCH) return self.hass.states.get(ENTITY_OTHER_SWITCH)
def test_include_switches_unspecified(self): def test_include_switches_unspecified(self):
"""Test that switches are ignored by default.""" """Test that switches are ignored by default."""
self.mock_lj.button_switches.assert_not_called() self.mock_lj.button_switches.assert_not_called()
self.mock_lj.all_switches.assert_not_called() self.mock_lj.all_switches.assert_not_called()
def test_include_switches_False(self): def test_include_switches_False(self):
"""Test that switches can be explicitly ignored.""" """Test that switches can be explicitly ignored."""
self.mock_lj.button_switches.assert_not_called() self.mock_lj.button_switches.assert_not_called()
self.mock_lj.all_switches.assert_not_called() self.mock_lj.all_switches.assert_not_called()
def test_on_off(self): def test_on_off(self):
"""Test turning the switch on and off.""" """Test turning the switch on and off."""
assert self.switch().state == 'off' assert self.switch().state == 'off'
assert self.other_switch().state == 'off' assert self.other_switch().state == 'off'
@ -99,9 +98,7 @@ class TestLiteJetSwitch(unittest.TestCase):
def test_pressed_event(self): def test_pressed_event(self):
"""Test handling an event from LiteJet.""" """Test handling an event from LiteJet."""
# Switch 1 # Switch 1
_LOGGER.info(self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]) _LOGGER.info(self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER])
self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]() self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]()
self.hass.block_till_done() self.hass.block_till_done()
@ -112,7 +109,6 @@ class TestLiteJetSwitch(unittest.TestCase):
assert self.other_switch().state == 'off' assert self.other_switch().state == 'off'
# Switch 2 # Switch 2
self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]()
self.hass.block_till_done() self.hass.block_till_done()
@ -123,9 +119,7 @@ class TestLiteJetSwitch(unittest.TestCase):
def test_released_event(self): def test_released_event(self):
"""Test handling an event from LiteJet.""" """Test handling an event from LiteJet."""
# Initial state is on. # Initial state is on.
self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]() self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]()
self.hass.block_till_done() self.hass.block_till_done()

View file

@ -22,16 +22,19 @@ class TestLiteJet(unittest.TestCase):
self.hass.stop() self.hass.stop()
def test_is_ignored_unspecified(self): def test_is_ignored_unspecified(self):
"""Ensure it is ignored when unspecified."""
self.hass.data['litejet_config'] = {} self.hass.data['litejet_config'] = {}
assert not litejet.is_ignored(self.hass, 'Test') assert not litejet.is_ignored(self.hass, 'Test')
def test_is_ignored_empty(self): def test_is_ignored_empty(self):
"""Ensure it is ignored when empty."""
self.hass.data['litejet_config'] = { self.hass.data['litejet_config'] = {
litejet.CONF_EXCLUDE_NAMES: [] litejet.CONF_EXCLUDE_NAMES: []
} }
assert not litejet.is_ignored(self.hass, 'Test') assert not litejet.is_ignored(self.hass, 'Test')
def test_is_ignored_normal(self): def test_is_ignored_normal(self):
"""Test if usually ignored."""
self.hass.data['litejet_config'] = { self.hass.data['litejet_config'] = {
litejet.CONF_EXCLUDE_NAMES: ['Test', 'Other One'] litejet.CONF_EXCLUDE_NAMES: ['Test', 'Other One']
} }

View file

@ -1,3 +1,4 @@
"""Tests for the Home Assistant Websocket API."""
import asyncio import asyncio
from unittest.mock import patch from unittest.mock import patch
@ -213,7 +214,7 @@ def test_subscribe_unsubscribe_events(hass, websocket_client):
@asyncio.coroutine @asyncio.coroutine
def test_get_states(hass, websocket_client): 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.hello', 'world')
hass.states.async_set('greeting.bye', 'universe') hass.states.async_set('greeting.bye', 'universe')
@ -239,7 +240,7 @@ def test_get_states(hass, websocket_client):
@asyncio.coroutine @asyncio.coroutine
def test_get_services(hass, websocket_client): def test_get_services(hass, websocket_client):
""" Test get_services command.""" """Test get_services command."""
websocket_client.send_json({ websocket_client.send_json({
'id': 5, 'id': 5,
'type': wapi.TYPE_GET_SERVICES, 'type': wapi.TYPE_GET_SERVICES,
@ -254,7 +255,7 @@ def test_get_services(hass, websocket_client):
@asyncio.coroutine @asyncio.coroutine
def test_get_config(hass, websocket_client): def test_get_config(hass, websocket_client):
""" Test get_config command.""" """Test get_config command."""
websocket_client.send_json({ websocket_client.send_json({
'id': 5, 'id': 5,
'type': wapi.TYPE_GET_CONFIG, 'type': wapi.TYPE_GET_CONFIG,
@ -269,7 +270,7 @@ def test_get_config(hass, websocket_client):
@asyncio.coroutine @asyncio.coroutine
def test_get_panels(hass, websocket_client): def test_get_panels(hass, websocket_client):
""" Test get_panels command.""" """Test get_panels command."""
frontend.register_built_in_panel(hass, 'map', 'Map', frontend.register_built_in_panel(hass, 'map', 'Map',
'mdi:account-location') 'mdi:account-location')
@ -287,7 +288,7 @@ def test_get_panels(hass, websocket_client):
@asyncio.coroutine @asyncio.coroutine
def test_ping(websocket_client): def test_ping(websocket_client):
""" Test get_panels command.""" """Test get_panels command."""
websocket_client.send_json({ websocket_client.send_json({
'id': 5, 'id': 5,
'type': wapi.TYPE_PING, 'type': wapi.TYPE_PING,

View file

@ -86,6 +86,7 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
"""Test case for asyncio.run_coroutine_threadsafe.""" """Test case for asyncio.run_coroutine_threadsafe."""
def setUp(self): def setUp(self):
"""Test setup method."""
self.loop = asyncio.new_event_loop() self.loop = asyncio.new_event_loop()
self.set_event_loop(self.loop) # Will cleanup properly self.set_event_loop(self.loop) # Will cleanup properly
@ -126,16 +127,14 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
self.assertEqual(result, 3) self.assertEqual(result, 3)
def test_run_coroutine_threadsafe_with_exception(self): def test_run_coroutine_threadsafe_with_exception(self):
"""Test coroutine submission from a thread to an event loop """Test coroutine submission from thread to event loop on exception."""
when an exception is raised."""
future = self.loop.run_in_executor(None, self.target, True) future = self.loop.run_in_executor(None, self.target, True)
with self.assertRaises(RuntimeError) as exc_context: with self.assertRaises(RuntimeError) as exc_context:
self.loop.run_until_complete(future) self.loop.run_until_complete(future)
self.assertIn("Fail!", exc_context.exception.args) self.assertIn("Fail!", exc_context.exception.args)
def test_run_coroutine_threadsafe_with_timeout(self): def test_run_coroutine_threadsafe_with_timeout(self):
"""Test coroutine submission from a thread to an event loop """Test coroutine submission from thread to event loop on timeout."""
when a timeout is raised."""
callback = lambda: self.target(timeout=0) # noqa callback = lambda: self.target(timeout=0) # noqa
future = self.loop.run_in_executor(None, callback) future = self.loop.run_in_executor(None, callback)
with self.assertRaises(asyncio.TimeoutError): with self.assertRaises(asyncio.TimeoutError):
@ -146,8 +145,7 @@ class RunCoroutineThreadsafeTests(test_utils.TestCase):
self.assertTrue(task.done()) self.assertTrue(task.done())
def test_run_coroutine_threadsafe_task_cancelled(self): def test_run_coroutine_threadsafe_task_cancelled(self):
"""Test coroutine submission from a tread to an event loop """Test coroutine submission from tread to event loop on cancel."""
when the task is cancelled."""
callback = lambda: self.target(cancel=True) # noqa callback = lambda: self.target(cancel=True) # noqa
future = self.loop.run_in_executor(None, callback) future = self.loop.run_in_executor(None, callback)
with self.assertRaises(asyncio.CancelledError): with self.assertRaises(asyncio.CancelledError):