WIP Fix pylint and PEP257 issues (tests) (#4120)
* Fix pylint and PEP257 issues * More PEP257 fixes
This commit is contained in:
parent
443553ff16
commit
51e20c92f9
19 changed files with 89 additions and 58 deletions
|
@ -8,10 +8,11 @@ import homeassistant.components.automation as automation
|
|||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationEvent(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -24,7 +25,7 @@ class TestAutomationEvent(unittest.TestCase):
|
|||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
""""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
|
|
@ -14,11 +14,10 @@ from tests.common import get_test_home_assistant, assert_setup_component, \
|
|||
fire_time_changed
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomation(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
@ -27,12 +26,12 @@ class TestAutomation(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Record call."""
|
||||
"""Helper to record calls."""
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
@ -438,20 +437,20 @@ class TestAutomation(unittest.TestCase):
|
|||
|
||||
@patch('homeassistant.config.load_yaml_config_file', autospec=True,
|
||||
return_value={
|
||||
automation.DOMAIN: {
|
||||
'alias': 'bye',
|
||||
'trigger': {
|
||||
'platform': 'event',
|
||||
'event_type': 'test_event2',
|
||||
},
|
||||
'action': {
|
||||
'service': 'test.automation',
|
||||
'data_template': {
|
||||
'event': '{{ trigger.event.event_type }}'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
automation.DOMAIN: {
|
||||
'alias': 'bye',
|
||||
'trigger': {
|
||||
'platform': 'event',
|
||||
'event_type': 'test_event2',
|
||||
},
|
||||
'action': {
|
||||
'service': 'test.automation',
|
||||
'data_template': {
|
||||
'event': '{{ trigger.event.event_type }}'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
def test_reload_config_service(self, mock_load_yaml):
|
||||
"""Test the reload config service."""
|
||||
assert setup_component(self.hass, automation.DOMAIN, {
|
||||
|
|
|
@ -8,10 +8,11 @@ from tests.common import (
|
|||
mock_mqtt_component, fire_mqtt_message, get_test_home_assistant)
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationMQTT(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -20,11 +21,12 @@ class TestAutomationMQTT(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Helper to record calls."""
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ import homeassistant.components.automation as automation
|
|||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationNumericState(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -451,8 +452,8 @@ class TestAutomationNumericState(unittest.TestCase):
|
|||
'service': 'test.automation',
|
||||
'data_template': {
|
||||
'some': '{{ trigger.%s }}' % '}} - {{ trigger.'.join((
|
||||
'platform', 'entity_id', 'below', 'above',
|
||||
'from_state.state', 'to_state.state'))
|
||||
'platform', 'entity_id', 'below', 'above',
|
||||
'from_state.state', 'to_state.state'))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""The test for state automation."""
|
||||
import unittest
|
||||
from datetime import timedelta
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.core import callback
|
||||
|
@ -12,10 +13,11 @@ from tests.common import (
|
|||
fire_time_changed, get_test_home_assistant, assert_setup_component)
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationState(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -24,11 +26,12 @@ class TestAutomationState(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Call recorder."""
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
@ -47,9 +50,9 @@ class TestAutomationState(unittest.TestCase):
|
|||
'service': 'test.automation',
|
||||
'data_template': {
|
||||
'some': '{{ trigger.%s }}' % '}} - {{ trigger.'.join((
|
||||
'platform', 'entity_id',
|
||||
'from_state.state', 'to_state.state',
|
||||
'for'))
|
||||
'platform', 'entity_id',
|
||||
'from_state.state', 'to_state.state',
|
||||
'for'))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""The tests for the sun automation."""
|
||||
from datetime import datetime
|
||||
|
||||
import unittest
|
||||
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
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationSun(unittest.TestCase):
|
||||
"""Test the sun automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -25,11 +27,12 @@ class TestAutomationSun(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Call recorder."""
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ import homeassistant.components.automation as automation
|
|||
from tests.common import get_test_home_assistant, assert_setup_component
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationTemplate(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -20,12 +21,12 @@ class TestAutomationTemplate(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""helper for recording calls."""
|
||||
"""Helper to record calls."""
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
|
|
@ -12,10 +12,11 @@ from tests.common import (
|
|||
fire_time_changed, get_test_home_assistant, assert_setup_component)
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationTime(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -23,11 +24,12 @@ class TestAutomationTime(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Helper to record calls."""
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
|
|
@ -8,10 +8,11 @@ from homeassistant.components import automation, zone
|
|||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestAutomationZone(unittest.TestCase):
|
||||
"""Test the event automation."""
|
||||
|
||||
def setUp(self): # pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.components.append('group')
|
||||
|
@ -28,11 +29,12 @@ class TestAutomationZone(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Helper to record calls."""
|
||||
self.calls.append(service)
|
||||
|
||||
self.hass.services.register('test', 'automation', record_call)
|
||||
|
||||
def tearDown(self): # pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
|
@ -56,9 +58,9 @@ class TestAutomationZone(unittest.TestCase):
|
|||
'service': 'test.automation',
|
||||
'data_template': {
|
||||
'some': '{{ trigger.%s }}' % '}} - {{ trigger.'.join((
|
||||
'platform', 'entity_id',
|
||||
'from_state.state', 'to_state.state',
|
||||
'zone.name'))
|
||||
'platform', 'entity_id',
|
||||
'from_state.state', 'to_state.state',
|
||||
'zone.name'))
|
||||
},
|
||||
|
||||
}
|
||||
|
|
|
@ -179,6 +179,7 @@ class TestNX584Watcher(unittest.TestCase):
|
|||
|
||||
@mock.patch.object(watcher, '_process_zone_event')
|
||||
def run(fake_process):
|
||||
"""Run a fake process."""
|
||||
fake_process.side_effect = StopMe
|
||||
self.assertRaises(StopMe, watcher._run)
|
||||
self.assertEqual(fake_process.call_count, 1)
|
||||
|
@ -193,6 +194,7 @@ class TestNX584Watcher(unittest.TestCase):
|
|||
empty_me = [1, 2]
|
||||
|
||||
def fake_run():
|
||||
"""Fake runner."""
|
||||
if empty_me:
|
||||
empty_me.pop()
|
||||
raise requests.exceptions.ConnectionError()
|
||||
|
|
|
@ -121,7 +121,7 @@ class TestUVCSetup(unittest.TestCase):
|
|||
|
||||
@mock.patch.object(uvc, 'UnifiVideoCamera')
|
||||
def test_setup_incomplete_config(self, mock_uvc):
|
||||
""""Test the setup with incomplete configuration."""
|
||||
"""Test the setup with incomplete configuration."""
|
||||
assert setup_component(
|
||||
self.hass, 'camera', {'platform': 'uvc', 'nvr': 'foo'})
|
||||
assert not mock_uvc.called
|
||||
|
@ -135,7 +135,7 @@ class TestUVCSetup(unittest.TestCase):
|
|||
@mock.patch.object(uvc, 'UnifiVideoCamera')
|
||||
@mock.patch('uvcclient.nvr.UVCRemote')
|
||||
def test_setup_nvr_errors(self, mock_remote, mock_uvc):
|
||||
""""Test for NVR errors."""
|
||||
"""Test for NVR errors."""
|
||||
errors = [nvr.NotAuthorized, nvr.NvrError,
|
||||
requests.exceptions.ConnectionError]
|
||||
config = {
|
||||
|
@ -223,6 +223,7 @@ class TestUVC(unittest.TestCase):
|
|||
responses = [0]
|
||||
|
||||
def fake_login(*a):
|
||||
"""Fake login."""
|
||||
try:
|
||||
responses.pop(0)
|
||||
raise socket.error
|
||||
|
@ -277,6 +278,7 @@ class TestUVC(unittest.TestCase):
|
|||
responses = [0]
|
||||
|
||||
def fake_snapshot():
|
||||
"""Fake snapshot."""
|
||||
try:
|
||||
responses.pop()
|
||||
raise camera.CameraAuthError()
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestDemoClimate(unittest.TestCase):
|
|||
self.hass.stop()
|
||||
|
||||
def test_setup_params(self):
|
||||
"""Test the inititial parameters."""
|
||||
"""Test the initial parameters."""
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
self.assertEqual(21, state.attributes.get('temperature'))
|
||||
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'))
|
||||
|
||||
def test_set_target_temp_range_bad_attr(self):
|
||||
"""Test setting the target temperature range without required
|
||||
attribute."""
|
||||
"""Test setting the target temperature range without attribute."""
|
||||
state = self.hass.states.get(ENTITY_ECOBEE)
|
||||
self.assertEqual(None, state.attributes.get('temperature'))
|
||||
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'))
|
||||
|
||||
def test_set_operation_bad_attr_and_state(self):
|
||||
"""Test setting operation mode without required attribute, and
|
||||
check the state."""
|
||||
"""Test setting operation mode without required attribute.
|
||||
|
||||
Also check the state.
|
||||
"""
|
||||
state = self.hass.states.get(ENTITY_CLIMATE)
|
||||
self.assertEqual("cool", state.attributes.get('operation_mode'))
|
||||
self.assertEqual("cool", state.state)
|
||||
|
|
|
@ -34,7 +34,6 @@ class TestDemoMediaPlayer(unittest.TestCase):
|
|||
|
||||
def test_source_select(self):
|
||||
"""Test the input source service."""
|
||||
|
||||
entity_id = 'media_player.lounge_room'
|
||||
|
||||
assert setup_component(
|
||||
|
|
|
@ -22,12 +22,17 @@ class socoDiscoverMock():
|
|||
|
||||
class AvTransportMock():
|
||||
"""Mock class for the avTransport property on soco.SoCo object."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize ethe Transport mock."""
|
||||
pass
|
||||
|
||||
def GetMediaInfo(self, _):
|
||||
return {'CurrentURI': '',
|
||||
'CurrentURIMetaData': ''}
|
||||
"""Get the media details."""
|
||||
return {
|
||||
'CurrentURI': '',
|
||||
'CurrentURIMetaData': ''
|
||||
}
|
||||
|
||||
|
||||
class SoCoMock():
|
||||
|
@ -102,18 +107,21 @@ def fake_add_device(devices, update_befor_add=False):
|
|||
class TestSonosMediaPlayer(unittest.TestCase):
|
||||
"""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."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def monkey_available(self):
|
||||
"""Make a monkey available."""
|
||||
return True
|
||||
|
||||
# Monkey patches
|
||||
self.real_available = sonos.SonosDevice.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."""
|
||||
# Monkey patches
|
||||
sonos.SonosDevice.available = self.real_available
|
||||
|
|
|
@ -325,6 +325,7 @@ class TestMQTTCallbacks(unittest.TestCase):
|
|||
self.assertEqual({}, mqtt.MQTT_CLIENT.progress)
|
||||
|
||||
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_subscribe_topic, 'bad\0one')
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
|||
}}}))
|
||||
|
||||
def test_invalid_config1(self):
|
||||
"""Test invalid configuration."""
|
||||
self.assertFalse(setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
|
@ -60,7 +61,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
|||
}}}))
|
||||
|
||||
def test_invalid_config2(self):
|
||||
"""Test configuration."""
|
||||
"""Test invalid configuration."""
|
||||
self.assertFalse(setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
|
@ -73,6 +74,7 @@ class TestSwitchRfxtrx(unittest.TestCase):
|
|||
}}}))
|
||||
|
||||
def test_invalid_config3(self):
|
||||
"""Test invalid configuration."""
|
||||
self.assertFalse(setup_component(self.hass, 'switch', {
|
||||
'switch': {'platform': 'rfxtrx',
|
||||
'automatic_add': True,
|
||||
|
|
|
@ -41,6 +41,7 @@ class TestConversation(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Recorder for a call."""
|
||||
calls.append(service)
|
||||
|
||||
self.hass.services.register('light', 'turn_on', record_call)
|
||||
|
@ -60,6 +61,7 @@ class TestConversation(unittest.TestCase):
|
|||
|
||||
@callback
|
||||
def record_call(service):
|
||||
"""Recorder for a call."""
|
||||
calls.append(service)
|
||||
|
||||
self.hass.services.register('light', 'turn_off', record_call)
|
||||
|
|
|
@ -9,6 +9,7 @@ from tests.common import load_fixture, get_test_home_assistant
|
|||
|
||||
|
||||
def mock_responses(mock):
|
||||
"""Mock responses for SleepIQ."""
|
||||
base_url = 'https://api.sleepiq.sleepnumber.com/rest/'
|
||||
mock.put(
|
||||
base_url + 'login',
|
||||
|
|
|
@ -12,15 +12,14 @@ import homeassistant.components.sun as sun
|
|||
from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
class TestSun(unittest.TestCase):
|
||||
"""Test the sun module."""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def setUp(self):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
|
Loading…
Add table
Reference in a new issue