diff --git a/setup.py b/setup.py index d6f4792c186658..4dc8ba9f75f49f 100755 --- a/setup.py +++ b/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, diff --git a/tests/components/automation/test_litejet.py b/tests/components/automation/test_litejet.py index be329487406d9c..d76a0ee19acf69 100644 --- a/tests/components/automation/test_litejet.py +++ b/tests/components/automation/test_litejet.py @@ -71,6 +71,7 @@ def teardown_method(self, method): 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 @@ def simulate_press(self, number): 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 @@ def simulate_release(self, number): 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 @@ def simulate_time(self, delta): _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: [ { diff --git a/tests/components/climate/test_generic_thermostat.py b/tests/components/climate/test_generic_thermostat.py index 7c4ee8db58f664..5fad8e16aeda92 100644 --- a/tests/components/climate/test_generic_thermostat.py +++ b/tests/components/climate/test_generic_thermostat.py @@ -182,9 +182,7 @@ def test_set_target_temp_heater_off(self): 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 @@ def test_temp_change_heater_on_outside_tolerance(self): 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 @@ def test_set_target_temp_ac_on(self): 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 @@ def test_set_temp_change_ac_off_outside_tolerance(self): 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() diff --git a/tests/components/emulated_hue/test_init.py b/tests/components/emulated_hue/test_init.py index ec3cc0a11cbd0d..2ee7c385d8db51 100755 --- a/tests/components/emulated_hue/test_init.py +++ b/tests/components/emulated_hue/test_init.py @@ -1,3 +1,4 @@ +"""Test the Emulated Hue component.""" from unittest.mock import patch from homeassistant.components.emulated_hue import Config, _LOGGER diff --git a/tests/components/http/test_ban.py b/tests/components/http/test_ban.py index b2aeca2917fa5a..c210bc3f0e0a17 100644 --- a/tests/components/http/test_ban.py +++ b/tests/components/http/test_ban.py @@ -75,7 +75,7 @@ def test_access_from_banned_ip(self): 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 @@ def test_access_from_banned_ip_when_ban_is_off(self): 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 diff --git a/tests/components/http/test_init.py b/tests/components/http/test_init.py index e4deb7b60d1dcf..5fa37012c7af56 100644 --- a/tests/components/http/test_init.py +++ b/tests/components/http/test_init.py @@ -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 @@ def test_cors_preflight_allowed(self): 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 diff --git a/tests/components/light/test_litejet.py b/tests/components/light/test_litejet.py index ab10752b14a342..10b205a8c7a063 100644 --- a/tests/components/light/test_litejet.py +++ b/tests/components/light/test_litejet.py @@ -60,9 +60,11 @@ def on_load_deactivated(number, callback): 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 @@ def teardown_method(self, method): 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 @@ def test_on_brightness(self): 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 @@ def test_on_off(self): 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 @@ def test_activated_event(self): def test_deactivated_event(self): """Test handling an event from LiteJet.""" - # Initial state is on. self.mock_lj.get_load_level.return_value = 99 diff --git a/tests/components/media_player/test_soundtouch.py b/tests/components/media_player/test_soundtouch.py index b95b774845a455..16f1065767a719 100644 --- a/tests/components/media_player/test_soundtouch.py +++ b/tests/components/media_player/test_soundtouch.py @@ -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" diff --git a/tests/components/media_player/test_yamaha.py b/tests/components/media_player/test_yamaha.py index 94810a84e3a7be..7484b18a904bf9 100644 --- a/tests/components/media_player/test_yamaha.py +++ b/tests/components/media_player/test_yamaha.py @@ -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 @@ def setUp(self): 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) diff --git a/tests/components/remote/test_demo.py b/tests/components/remote/test_demo.py index 7dc8f2c89767b1..8277ef12c8ed43 100755 --- a/tests/components/remote/test_demo.py +++ b/tests/components/remote/test_demo.py @@ -30,7 +30,6 @@ def tearDown(self): 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 @@ def test_methods(self): def test_services(self): """Test the provided services.""" - # Test turn_on turn_on_calls = mock_service( self.hass, remote.DOMAIN, SERVICE_TURN_ON) diff --git a/tests/components/remote/test_init.py b/tests/components/remote/test_init.py index a5d711f8680754..60a049fa2914e9 100755 --- a/tests/components/remote/test_init.py +++ b/tests/components/remote/test_init.py @@ -28,7 +28,7 @@ def tearDown(self): 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 @@ def test_is_on(self): 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 @@ def test_turn_on(self): 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 @@ def test_turn_off(self): 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) diff --git a/tests/components/scene/test_litejet.py b/tests/components/scene/test_litejet.py index 7596736a567fef..17ba4ce73043aa 100644 --- a/tests/components/scene/test_litejet.py +++ b/tests/components/scene/test_litejet.py @@ -50,14 +50,15 @@ def teardown_method(self, method): 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( diff --git a/tests/components/sensor/test_api_streams.py b/tests/components/sensor/test_api_streams.py index 2154cc3bd49731..e7978ce0fb8605 100644 --- a/tests/components/sensor/test_api_streams.py +++ b/tests/components/sensor/test_api_streams.py @@ -1,3 +1,4 @@ +"""Test cases for the API stream sensor.""" import asyncio import logging diff --git a/tests/components/sensor/test_sonarr.py b/tests/components/sensor/test_sonarr.py index cc9186677dc61c..24a733e6565dee 100644 --- a/tests/components/sensor/test_sonarr.py +++ b/tests/components/sensor/test_sonarr.py @@ -574,7 +574,7 @@ def setUp(self): @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 @@ def test_diskspace_no_paths(self, req_mock): @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 @@ def test_diskspace_paths(self, req_mock): @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 @@ def test_commands(self, req_mock): @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 @@ def test_queue(self, req_mock): @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 @@ def test_series(self, req_mock): @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 @@ def test_wanted(self, req_mock): @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 @@ def test_upcoming_multiple_days(self, req_mock): @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 @@ def test_upcoming_today(self, req_mock): @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 @@ def test_ssl(self, req_mock): @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', diff --git a/tests/components/switch/test_command_line.py b/tests/components/switch/test_command_line.py index bc8e6d6173a11c..de122df047944c 100644 --- a/tests/components/switch/test_command_line.py +++ b/tests/components/switch/test_command_line.py @@ -185,7 +185,7 @@ def test_assumed_state_should_be_true_if_command_state_is_false(self): 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 = [ diff --git a/tests/components/switch/test_litejet.py b/tests/components/switch/test_litejet.py index 55d468bccd452e..3d090fd173d57c 100644 --- a/tests/components/switch/test_litejet.py +++ b/tests/components/switch/test_litejet.py @@ -64,26 +64,25 @@ def teardown_method(self, method): 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 @@ def test_on_off(self): 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 @@ def test_pressed_event(self): 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 @@ def test_pressed_event(self): 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() diff --git a/tests/components/test_litejet.py b/tests/components/test_litejet.py index 6d62e1ab0cda60..dfbcb9d99d88b8 100644 --- a/tests/components/test_litejet.py +++ b/tests/components/test_litejet.py @@ -22,16 +22,19 @@ def teardown_method(self, method): 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'] } diff --git a/tests/components/test_websocket_api.py b/tests/components/test_websocket_api.py index bdad5032a24e12..a6748e7fc165a0 100644 --- a/tests/components/test_websocket_api.py +++ b/tests/components/test_websocket_api.py @@ -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, diff --git a/tests/util/test_async.py b/tests/util/test_async.py index f88887e3c6e3e9..a3da7e7f4e1e3e 100644 --- a/tests/util/test_async.py +++ b/tests/util/test_async.py @@ -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 @@ def test_run_coroutine_threadsafe(self): 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 @@ def test_run_coroutine_threadsafe_with_timeout(self): 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):