WIP Fix pylint and PEP257 issues (tests) (#4120)

* Fix pylint and PEP257 issues

* More PEP257 fixes
This commit is contained in:
Fabian Affolter 2016-12-02 06:45:19 +01:00 committed by Paulus Schoutsen
parent 443553ff16
commit 51e20c92f9
19 changed files with 89 additions and 58 deletions

View File

@ -8,10 +8,11 @@ import homeassistant.components.automation as automation
from tests.common import get_test_home_assistant from tests.common import get_test_home_assistant
# pylint: disable=invalid-name
class TestAutomationEvent(unittest.TestCase): class TestAutomationEvent(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')
@ -24,7 +25,7 @@ class TestAutomationEvent(unittest.TestCase):
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
""""Stop everything that was started.""" """"Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -14,11 +14,10 @@ from tests.common import get_test_home_assistant, assert_setup_component, \
fire_time_changed fire_time_changed
# pylint: disable=invalid-name
class TestAutomation(unittest.TestCase): class TestAutomation(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
# pylint: disable=invalid-name
def setUp(self): def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
@ -27,12 +26,12 @@ class TestAutomation(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Record call.""" """Helper to record calls."""
self.calls.append(service) self.calls.append(service)
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -8,10 +8,11 @@ from tests.common import (
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant) mock_mqtt_component, fire_mqtt_message, get_test_home_assistant)
# pylint: disable=invalid-name
class TestAutomationMQTT(unittest.TestCase): class TestAutomationMQTT(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')
@ -20,11 +21,12 @@ class TestAutomationMQTT(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Helper to record calls."""
self.calls.append(service) self.calls.append(service)
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -8,10 +8,11 @@ import homeassistant.components.automation as automation
from tests.common import get_test_home_assistant from tests.common import get_test_home_assistant
# pylint: disable=invalid-name
class TestAutomationNumericState(unittest.TestCase): class TestAutomationNumericState(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')

View File

@ -1,6 +1,7 @@
"""The test for state automation.""" """The test for state automation."""
import unittest
from datetime import timedelta from datetime import timedelta
import unittest
from unittest.mock import patch from unittest.mock import patch
from homeassistant.core import callback from homeassistant.core import callback
@ -12,10 +13,11 @@ from tests.common import (
fire_time_changed, get_test_home_assistant, assert_setup_component) fire_time_changed, get_test_home_assistant, assert_setup_component)
# pylint: disable=invalid-name
class TestAutomationState(unittest.TestCase): class TestAutomationState(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')
@ -24,11 +26,12 @@ class TestAutomationState(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Call recorder."""
self.calls.append(service) self.calls.append(service)
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -1,5 +1,6 @@
"""The tests for the sun automation.""" """The tests for the sun automation."""
from datetime import datetime from datetime import datetime
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
@ -12,10 +13,11 @@ import homeassistant.util.dt as dt_util
from tests.common import fire_time_changed, get_test_home_assistant from tests.common import fire_time_changed, get_test_home_assistant
# pylint: disable=invalid-name
class TestAutomationSun(unittest.TestCase): class TestAutomationSun(unittest.TestCase):
"""Test the sun automation.""" """Test the sun automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')
@ -25,11 +27,12 @@ class TestAutomationSun(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Call recorder."""
self.calls.append(service) self.calls.append(service)
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -8,10 +8,11 @@ import homeassistant.components.automation as automation
from tests.common import get_test_home_assistant, assert_setup_component from tests.common import get_test_home_assistant, assert_setup_component
# pylint: disable=invalid-name
class TestAutomationTemplate(unittest.TestCase): class TestAutomationTemplate(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')
@ -20,12 +21,12 @@ class TestAutomationTemplate(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""helper for recording calls.""" """Helper to record calls."""
self.calls.append(service) self.calls.append(service)
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -12,10 +12,11 @@ from tests.common import (
fire_time_changed, get_test_home_assistant, assert_setup_component) fire_time_changed, get_test_home_assistant, assert_setup_component)
# pylint: disable=invalid-name
class TestAutomationTime(unittest.TestCase): class TestAutomationTime(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')
@ -23,11 +24,12 @@ class TestAutomationTime(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Helper to record calls."""
self.calls.append(service) self.calls.append(service)
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -8,10 +8,11 @@ from homeassistant.components import automation, zone
from tests.common import get_test_home_assistant from tests.common import get_test_home_assistant
# pylint: disable=invalid-name
class TestAutomationZone(unittest.TestCase): class TestAutomationZone(unittest.TestCase):
"""Test the event automation.""" """Test the event automation."""
def setUp(self): # pylint: disable=invalid-name def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
self.hass.config.components.append('group') self.hass.config.components.append('group')
@ -28,11 +29,12 @@ class TestAutomationZone(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Helper to record calls."""
self.calls.append(service) self.calls.append(service)
self.hass.services.register('test', 'automation', record_call) self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()

View File

@ -179,6 +179,7 @@ class TestNX584Watcher(unittest.TestCase):
@mock.patch.object(watcher, '_process_zone_event') @mock.patch.object(watcher, '_process_zone_event')
def run(fake_process): def run(fake_process):
"""Run a fake process."""
fake_process.side_effect = StopMe fake_process.side_effect = StopMe
self.assertRaises(StopMe, watcher._run) self.assertRaises(StopMe, watcher._run)
self.assertEqual(fake_process.call_count, 1) self.assertEqual(fake_process.call_count, 1)
@ -193,6 +194,7 @@ class TestNX584Watcher(unittest.TestCase):
empty_me = [1, 2] empty_me = [1, 2]
def fake_run(): def fake_run():
"""Fake runner."""
if empty_me: if empty_me:
empty_me.pop() empty_me.pop()
raise requests.exceptions.ConnectionError() raise requests.exceptions.ConnectionError()

View File

@ -121,7 +121,7 @@ class TestUVCSetup(unittest.TestCase):
@mock.patch.object(uvc, 'UnifiVideoCamera') @mock.patch.object(uvc, 'UnifiVideoCamera')
def test_setup_incomplete_config(self, mock_uvc): def test_setup_incomplete_config(self, mock_uvc):
""""Test the setup with incomplete configuration.""" """Test the setup with incomplete configuration."""
assert setup_component( assert setup_component(
self.hass, 'camera', {'platform': 'uvc', 'nvr': 'foo'}) self.hass, 'camera', {'platform': 'uvc', 'nvr': 'foo'})
assert not mock_uvc.called assert not mock_uvc.called
@ -135,7 +135,7 @@ class TestUVCSetup(unittest.TestCase):
@mock.patch.object(uvc, 'UnifiVideoCamera') @mock.patch.object(uvc, 'UnifiVideoCamera')
@mock.patch('uvcclient.nvr.UVCRemote') @mock.patch('uvcclient.nvr.UVCRemote')
def test_setup_nvr_errors(self, mock_remote, mock_uvc): def test_setup_nvr_errors(self, mock_remote, mock_uvc):
""""Test for NVR errors.""" """Test for NVR errors."""
errors = [nvr.NotAuthorized, nvr.NvrError, errors = [nvr.NotAuthorized, nvr.NvrError,
requests.exceptions.ConnectionError] requests.exceptions.ConnectionError]
config = { config = {
@ -223,6 +223,7 @@ class TestUVC(unittest.TestCase):
responses = [0] responses = [0]
def fake_login(*a): def fake_login(*a):
"""Fake login."""
try: try:
responses.pop(0) responses.pop(0)
raise socket.error raise socket.error
@ -277,6 +278,7 @@ class TestUVC(unittest.TestCase):
responses = [0] responses = [0]
def fake_snapshot(): def fake_snapshot():
"""Fake snapshot."""
try: try:
responses.pop() responses.pop()
raise camera.CameraAuthError() raise camera.CameraAuthError()

View File

@ -32,7 +32,7 @@ class TestDemoClimate(unittest.TestCase):
self.hass.stop() self.hass.stop()
def test_setup_params(self): def test_setup_params(self):
"""Test the inititial parameters.""" """Test the initial parameters."""
state = self.hass.states.get(ENTITY_CLIMATE) state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(21, state.attributes.get('temperature')) self.assertEqual(21, state.attributes.get('temperature'))
self.assertEqual('on', state.attributes.get('away_mode')) self.assertEqual('on', state.attributes.get('away_mode'))
@ -93,8 +93,7 @@ class TestDemoClimate(unittest.TestCase):
self.assertEqual(25.0, state.attributes.get('target_temp_high')) self.assertEqual(25.0, state.attributes.get('target_temp_high'))
def test_set_target_temp_range_bad_attr(self): def test_set_target_temp_range_bad_attr(self):
"""Test setting the target temperature range without required """Test setting the target temperature range without attribute."""
attribute."""
state = self.hass.states.get(ENTITY_ECOBEE) state = self.hass.states.get(ENTITY_ECOBEE)
self.assertEqual(None, state.attributes.get('temperature')) self.assertEqual(None, state.attributes.get('temperature'))
self.assertEqual(21.0, state.attributes.get('target_temp_low')) self.assertEqual(21.0, state.attributes.get('target_temp_low'))
@ -163,8 +162,10 @@ class TestDemoClimate(unittest.TestCase):
self.assertEqual("Auto", state.attributes.get('swing_mode')) self.assertEqual("Auto", state.attributes.get('swing_mode'))
def test_set_operation_bad_attr_and_state(self): def test_set_operation_bad_attr_and_state(self):
"""Test setting operation mode without required attribute, and """Test setting operation mode without required attribute.
check the state."""
Also check the state.
"""
state = self.hass.states.get(ENTITY_CLIMATE) state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual("cool", state.attributes.get('operation_mode')) self.assertEqual("cool", state.attributes.get('operation_mode'))
self.assertEqual("cool", state.state) self.assertEqual("cool", state.state)

View File

@ -34,7 +34,6 @@ class TestDemoMediaPlayer(unittest.TestCase):
def test_source_select(self): def test_source_select(self):
"""Test the input source service.""" """Test the input source service."""
entity_id = 'media_player.lounge_room' entity_id = 'media_player.lounge_room'
assert setup_component( assert setup_component(

View File

@ -22,12 +22,17 @@ class socoDiscoverMock():
class AvTransportMock(): class AvTransportMock():
"""Mock class for the avTransport property on soco.SoCo object.""" """Mock class for the avTransport property on soco.SoCo object."""
def __init__(self): def __init__(self):
"""Initialize ethe Transport mock."""
pass pass
def GetMediaInfo(self, _): def GetMediaInfo(self, _):
return {'CurrentURI': '', """Get the media details."""
'CurrentURIMetaData': ''} return {
'CurrentURI': '',
'CurrentURIMetaData': ''
}
class SoCoMock(): class SoCoMock():
@ -102,18 +107,21 @@ def fake_add_device(devices, update_befor_add=False):
class TestSonosMediaPlayer(unittest.TestCase): class TestSonosMediaPlayer(unittest.TestCase):
"""Test the media_player module.""" """Test the media_player module."""
def setUp(self): # pylint: disable=invalid-name # pylint: disable=invalid-name
def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
def monkey_available(self): def monkey_available(self):
"""Make a monkey available."""
return True return True
# Monkey patches # Monkey patches
self.real_available = sonos.SonosDevice.available self.real_available = sonos.SonosDevice.available
sonos.SonosDevice.available = monkey_available sonos.SonosDevice.available = monkey_available
def tearDown(self): # pylint: disable=invalid-name # pylint: disable=invalid-name
def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
# Monkey patches # Monkey patches
sonos.SonosDevice.available = self.real_available sonos.SonosDevice.available = self.real_available

View File

@ -325,6 +325,7 @@ class TestMQTTCallbacks(unittest.TestCase):
self.assertEqual({}, mqtt.MQTT_CLIENT.progress) self.assertEqual({}, mqtt.MQTT_CLIENT.progress)
def test_invalid_mqtt_topics(self): def test_invalid_mqtt_topics(self):
"""Test invalid topics."""
self.assertRaises(vol.Invalid, mqtt.valid_publish_topic, 'bad+topic') self.assertRaises(vol.Invalid, mqtt.valid_publish_topic, 'bad+topic')
self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'bad\0one') self.assertRaises(vol.Invalid, mqtt.valid_subscribe_topic, 'bad\0one')

View File

@ -49,6 +49,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
}}})) }}}))
def test_invalid_config1(self): def test_invalid_config1(self):
"""Test invalid configuration."""
self.assertFalse(setup_component(self.hass, 'switch', { self.assertFalse(setup_component(self.hass, 'switch', {
'switch': {'platform': 'rfxtrx', 'switch': {'platform': 'rfxtrx',
'automatic_add': True, 'automatic_add': True,
@ -60,7 +61,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
}}})) }}}))
def test_invalid_config2(self): def test_invalid_config2(self):
"""Test configuration.""" """Test invalid configuration."""
self.assertFalse(setup_component(self.hass, 'switch', { self.assertFalse(setup_component(self.hass, 'switch', {
'switch': {'platform': 'rfxtrx', 'switch': {'platform': 'rfxtrx',
'automatic_add': True, 'automatic_add': True,
@ -73,6 +74,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
}}})) }}}))
def test_invalid_config3(self): def test_invalid_config3(self):
"""Test invalid configuration."""
self.assertFalse(setup_component(self.hass, 'switch', { self.assertFalse(setup_component(self.hass, 'switch', {
'switch': {'platform': 'rfxtrx', 'switch': {'platform': 'rfxtrx',
'automatic_add': True, 'automatic_add': True,

View File

@ -41,6 +41,7 @@ class TestConversation(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Recorder for a call."""
calls.append(service) calls.append(service)
self.hass.services.register('light', 'turn_on', record_call) self.hass.services.register('light', 'turn_on', record_call)
@ -60,6 +61,7 @@ class TestConversation(unittest.TestCase):
@callback @callback
def record_call(service): def record_call(service):
"""Recorder for a call."""
calls.append(service) calls.append(service)
self.hass.services.register('light', 'turn_off', record_call) self.hass.services.register('light', 'turn_off', record_call)

View File

@ -9,6 +9,7 @@ from tests.common import load_fixture, get_test_home_assistant
def mock_responses(mock): def mock_responses(mock):
"""Mock responses for SleepIQ."""
base_url = 'https://api.sleepiq.sleepnumber.com/rest/' base_url = 'https://api.sleepiq.sleepnumber.com/rest/'
mock.put( mock.put(
base_url + 'login', base_url + 'login',

View File

@ -12,15 +12,14 @@ import homeassistant.components.sun as sun
from tests.common import get_test_home_assistant from tests.common import get_test_home_assistant
# pylint: disable=invalid-name
class TestSun(unittest.TestCase): class TestSun(unittest.TestCase):
"""Test the sun module.""" """Test the sun module."""
# pylint: disable=invalid-name
def setUp(self): def setUp(self):
"""Setup things to be run when tests are started.""" """Setup things to be run when tests are started."""
self.hass = get_test_home_assistant() self.hass = get_test_home_assistant()
# pylint: disable=invalid-name
def tearDown(self): def tearDown(self):
"""Stop everything that was started.""" """Stop everything that was started."""
self.hass.stop() self.hass.stop()