Fix PEP257 issues

This commit is contained in:
Fabian Affolter committed 2016-03-09 11:15:04 +01:00
1 parent 986c9c55bf
commit f22a40c3e8
22 files changed
+95 -79

No files matched your search

+8 -2
View File
@@ -102,6 +102,7 @@ def ensure_sun_set(hass):
def mock_state_change_event(hass, new_state, old_state=None):
"""Mock state change envent."""
event_data = {
'entity_id': new_state.entity_id,
'new_state': new_state,
@@ -133,14 +134,17 @@ def mock_mqtt_component(hass, mock_mqtt):
class MockHTTP(object):
"""Mock the HTTP module."""
def register_path(self, method, url, callback, require_auth=True):
"""Register a path."""
pass
class MockModule(object):
""" Provides a fake module. """
"""Representation of a fake module."""
def __init__(self, domain=None, dependencies=[], setup=None):
"""Initialize the mock module."""
self.DOMAIN = domain
self.DEPENDENCIES = dependencies
# Setup a mock setup if none given.
@@ -166,7 +170,9 @@ class MockPlatform(object):
class MockToggleDevice(ToggleEntity):
"""Provide a mock toggle device."""
def __init__(self, name, state):
"""Initialize the mock device."""
self._name = name or DEVICE_DEFAULT_NAME
self._state = state
self.calls = []
@@ -179,7 +185,7 @@ class MockToggleDevice(ToggleEntity):
@property
def state(self):
"""Returns the name of the device if any."""
"""Return the name of the device if any."""
self.calls.append(('state', {}))
return self._state
@@ -2,7 +2,7 @@
def get_scanner(hass, config):
"""Returns a mock scanner."""
"""Return a mock scanner."""
return SCANNER
+1
View File
@@ -0,0 +1 @@
"""The tests for the helpers."""
+1 -1
View File
@@ -12,7 +12,7 @@ class TestHelpersEntity(unittest.TestCase):
"""Test homeassistant.helpers.entity module."""
def setUp(self): # pylint: disable=invalid-name
"""Init needed objects."""
"""Setup things to be run when tests are started."""
self.entity = entity.Entity()
self.entity.entity_id = 'test.overwrite_hidden_true'
self.hass = self.entity.hass = get_test_home_assistant()
+22 -2
View File
@@ -1,4 +1,4 @@
"""Test the entity component helper."""
"""The tests for the Entity component helper."""
# pylint: disable=protected-access,too-many-public-methods
from collections import OrderedDict
import logging
@@ -20,7 +20,10 @@ DOMAIN = "test_domain"
class EntityTest(Entity):
"""Test for the Entity component."""
def __init__(self, **values):
"""Initialize an entity."""
self._values = values
if 'entity_id' in values:
@@ -28,24 +31,28 @@ class EntityTest(Entity):
@property
def name(self):
"""Return the name of the entity."""
return self._handle('name')
@property
def should_poll(self):
"""Return the ste of the polling."""
return self._handle('should_poll')
@property
def unique_id(self):
"""Return the unique ID of the entity."""
return self._handle('unique_id')
def _handle(self, attr):
"""Helper for the attributes."""
if attr in self._values:
return self._values[attr]
return getattr(super(), attr)
class TestHelpersEntityComponent(unittest.TestCase):
""" Tests homeassistant.helpers.entity_component module. """
"""Test homeassistant.helpers.entity_component module."""
def setUp(self): # pylint: disable=invalid-name
"""Initialize a test Home Assistant instance."""
@@ -56,6 +63,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
self.hass.stop()
def test_setting_up_group(self):
"""Setup the setting of a group."""
component = EntityComponent(_LOGGER, DOMAIN, self.hass,
group_name='everyone')
@@ -82,6 +90,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
sorted(group.attributes.get('entity_id'))
def test_polling_only_updates_entities_it_should_poll(self):
"""Test the polling of only updated entities."""
component = EntityComponent(_LOGGER, DOMAIN, self.hass, 20)
no_poll_ent = EntityTest(should_poll=False)
@@ -117,6 +126,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
assert 2 == len(self.hass.states.entity_ids())
def test_not_adding_duplicate_entities(self):
"""Test for not adding duplicate entities."""
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
assert 0 == len(self.hass.states.entity_ids())
@@ -130,6 +140,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
assert 1 == len(self.hass.states.entity_ids())
def test_not_assigning_entity_id_if_prescribes_one(self):
"""Test for not assigning an entity ID."""
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
assert 'hello.world' not in self.hass.states.entity_ids()
@@ -139,6 +150,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
assert 'hello.world' in self.hass.states.entity_ids()
def test_extract_from_service_returns_all_if_no_entity_id(self):
"""Test the extraction of everything from service."""
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
component.add_entities([
EntityTest(name='test_1'),
@@ -152,6 +164,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
component.extract_from_service(call))
def test_extract_from_service_filter_out_non_existing_entities(self):
"""Test the extraction of non existing entities from service."""
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
component.add_entities([
EntityTest(name='test_1'),
@@ -166,6 +179,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
[ent.entity_id for ent in component.extract_from_service(call)]
def test_setup_loads_platforms(self):
"""Test the loading of the platforms."""
component_setup = Mock(return_value=True)
platform_setup = Mock(return_value=None)
loader.set_component(
@@ -189,6 +203,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
assert platform_setup.called
def test_setup_recovers_when_setup_raises(self):
"""Test the setup if exceptions are happening."""
platform1_setup = Mock(side_effect=Exception('Broken'))
platform2_setup = Mock(return_value=None)
@@ -212,6 +227,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
@patch('homeassistant.helpers.entity_component.EntityComponent'
'._setup_platform')
def test_setup_does_discovery(self, mock_setup):
"""Test setup for discovery."""
component = EntityComponent(
_LOGGER, DOMAIN, self.hass, discovery_platforms={
'discovery.test': 'platform_test',
@@ -232,7 +248,9 @@ class TestHelpersEntityComponent(unittest.TestCase):
@patch('homeassistant.helpers.entity_component.track_utc_time_change')
def test_set_scan_interval_via_config(self, mock_track):
"""Test the setting of the scan interval via configuration."""
def platform_setup(hass, config, add_devices, discovery_info=None):
"""Test the platform setup."""
add_devices([EntityTest(should_poll=True)])
loader.set_component('test_domain.platform',
@@ -252,7 +270,9 @@ class TestHelpersEntityComponent(unittest.TestCase):
@patch('homeassistant.helpers.entity_component.track_utc_time_change')
def test_set_scan_interval_via_platform(self, mock_track):
"""Test the setting of the scan interval via platform."""
def platform_setup(hass, config, add_devices, discovery_info=None):
"""Test the platform setup."""
add_devices([EntityTest(should_poll=True)])
platform = MockPlatform(platform_setup)
+2 -2
View File
@@ -21,7 +21,7 @@ class TestEventDecoratorHelpers(unittest.TestCase):
"""Test the Home Assistant event helpers."""
def setUp(self): # pylint: disable=invalid-name
"""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.states.set("light.Bowl", "on")
self.hass.states.set("switch.AC", "off")
@@ -29,7 +29,7 @@ class TestEventDecoratorHelpers(unittest.TestCase):
event_decorators.HASS = self.hass
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
"""Stop everything that was started."""
self.hass.stop()
event_decorators.HASS = None
+2 -2
View File
@@ -23,7 +23,7 @@ def create_file(path):
class TestConfig(unittest.TestCase):
"""Test the configutils. """
"""Test the configutils."""
def tearDown(self): # pylint: disable=invalid-name
"""Clean up."""
@@ -65,7 +65,7 @@ class TestConfig(unittest.TestCase):
self.assertEqual('', content)
def test_load_yaml_config_converts_empty_files_to_dict(self):
""" Test that loading an empty file returns an empty dict. """
"""Test that loading an empty file returns an empty dict."""
create_file(YAML_PATH)
self.assertIsInstance(
+5 -5
View File
@@ -35,7 +35,7 @@ class TestHomeAssistant(unittest.TestCase):
self.hass.states.set("switch.AC", "off")
def tearDown(self): # pylint: disable=invalid-name
"""Stop down stuff we started."""
"""Stop everything that was started."""
try:
self.hass.stop()
except HomeAssistantError:
@@ -106,7 +106,7 @@ class TestEvent(unittest.TestCase):
self.assertEqual(event1, event2)
def test_repr(self):
"""Test that repr method works. #MoreCoverage"""
"""Test that repr method works."""
self.assertEqual(
"<Event TestEvent[L]>",
str(ha.Event("TestEvent")))
@@ -237,7 +237,7 @@ class TestState(unittest.TestCase):
class TestStateMachine(unittest.TestCase):
"""Test State machine methods. """
"""Test State machine methods."""
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
@@ -349,7 +349,7 @@ class TestServiceCall(unittest.TestCase):
class TestServiceRegistry(unittest.TestCase):
""" Test ServicerRegistry methods. """
"""Test ServicerRegistry methods."""
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
@@ -419,7 +419,7 @@ class TestConfig(unittest.TestCase):
"""Test configuration methods."""
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started. """
"""Setup things to be run when tests are started."""
self.config = ha.Config()
def test_config_dir_set_correct(self):
+1 -1
View File
@@ -216,7 +216,7 @@ class TestRemoteClasses(unittest.TestCase):
remote.API('127.0.0.1', API_PASSWORD, BROKEN_PORT))
def test_statemachine_init(self):
""" Tests if remote.StateMachine copies all states on init. """
"""Test if remote.StateMachine copies all states on init."""
self.assertEqual(sorted(hass.states.all()),
sorted(slave.states.all()))
+1
View File
@@ -0,0 +1 @@
"""The tests for the utilities."""
+1 -4
View File
@@ -62,9 +62,9 @@ class TestUtil(unittest.TestCase):
def test_ordered_enum(self):
"""Test the ordered enum class."""
class TestEnum(util.OrderedEnum):
"""Test enum that can be ordered."""
FIRST = 1
SECOND = 2
THIRD = 3
@@ -214,7 +214,6 @@ class TestUtil(unittest.TestCase):
def test_throttle_per_instance(self):
"""Test that the throttle method is done per instance of a class."""
class Tester(object):
"""A tester class for the throttle."""
@@ -228,7 +227,6 @@ class TestUtil(unittest.TestCase):
def test_throttle_on_method(self):
"""Test that throttle works when wrapping a method."""
class Tester(object):
"""A tester class for the throttle."""
@@ -244,7 +242,6 @@ class TestUtil(unittest.TestCase):
def test_throttle_on_two_method(self):
"""Test that throttle works when wrapping two methods."""
class Tester(object):
"""A test class for the throttle."""