1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Fix PEP257 issues

This commit is contained in:
Fabian Affolter
2016-03-09 10:25:50 +01:00
parent d6eab03a61
commit 9838697d2b
120 changed files with 1447 additions and 1297 deletions

View File

@@ -1,9 +1,4 @@
"""
tests.components.automation.test_state
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests state automation.
"""
"""The test for state automation."""
import unittest
from datetime import timedelta
from unittest.mock import patch
@@ -16,9 +11,10 @@ from tests.common import fire_time_changed, get_test_home_assistant
class TestAutomationState(unittest.TestCase):
""" Test the event automation. """
"""Test the event automation."""
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.states.set('test.entity', 'hello')
self.calls = []
@@ -29,10 +25,11 @@ class TestAutomationState(unittest.TestCase):
self.hass.services.register('test', 'automation', record_call)
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
"""Stop everything that was started."""
self.hass.stop()
def test_old_config_if_fires_on_entity_change(self):
"""Test for firing if entity change ."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'state',
@@ -46,6 +43,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_old_config_if_fires_on_entity_change_with_from_filter(self):
"""Test for firing on entity change with filter."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'state',
@@ -60,6 +58,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_old_config_if_fires_on_entity_change_with_to_filter(self):
"""Test for firing on entity change no filter."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'state',
@@ -74,6 +73,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_old_config_if_fires_on_entity_change_with_both_filters(self):
"""Test for firing on entity change with both filters."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'state',
@@ -89,6 +89,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_old_config_if_not_fires_if_to_filter_not_match(self):
"""Test for not firing if no match."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'state',
@@ -104,6 +105,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(0, len(self.calls))
def test_old_config_if_not_fires_if_from_filter_not_match(self):
"""Test for no firing if no match."""
self.hass.states.set('test.entity', 'bye')
self.assertTrue(automation.setup(self.hass, {
@@ -121,6 +123,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(0, len(self.calls))
def test_old_config_if_not_fires_if_entity_not_match(self):
"""Test for not firing if no match."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'platform': 'state',
@@ -134,6 +137,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(0, len(self.calls))
def test_old_config_if_action(self):
"""Test for if action."""
entity_id = 'domain.test_entity'
test_state = 'new_state'
automation.setup(self.hass, {
@@ -162,6 +166,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entity_change(self):
"""Test for firing on entity change."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -179,6 +184,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entity_change_with_from_filter(self):
"""Test for firing on entity change with filter."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -197,6 +203,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entity_change_with_to_filter(self):
"""Test for firing on entity change with no filter."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -215,6 +222,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entity_change_with_state_filter(self):
"""Test for firing on entity change with state filter."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -233,6 +241,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fires_on_entity_change_with_both_filters(self):
"""Test for firing if both filters are a non match."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -252,6 +261,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_not_fires_if_to_filter_not_match(self):
"""Test for not firing if to filter is not a match."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -271,6 +281,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(0, len(self.calls))
def test_if_not_fires_if_from_filter_not_match(self):
"""Test for not firing if from filter is not a match."""
self.hass.states.set('test.entity', 'bye')
self.assertTrue(automation.setup(self.hass, {
@@ -292,6 +303,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(0, len(self.calls))
def test_if_not_fires_if_entity_not_match(self):
"""Test for not firing if entity is not matching."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -309,6 +321,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(0, len(self.calls))
def test_if_action(self):
"""Test for to action."""
entity_id = 'domain.test_entity'
test_state = 'new_state'
automation.setup(self.hass, {
@@ -341,6 +354,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fails_setup_if_to_boolean_value(self):
"""Test for setup failure for boolean to."""
self.assertFalse(state.trigger(
self.hass, {
'platform': 'state',
@@ -349,6 +363,7 @@ class TestAutomationState(unittest.TestCase):
}, lambda x: x))
def test_if_fails_setup_if_from_boolean_value(self):
"""Test for setup failure for boolean from."""
self.assertFalse(state.trigger(
self.hass, {
'platform': 'state',
@@ -357,6 +372,7 @@ class TestAutomationState(unittest.TestCase):
}, lambda x: x))
def test_if_fails_setup_bad_for(self):
"""Test for setup failure for bad for."""
self.assertFalse(state.trigger(
self.hass, {
'platform': 'state',
@@ -368,6 +384,7 @@ class TestAutomationState(unittest.TestCase):
}, lambda x: x))
def test_if_fails_setup_for_without_to(self):
"""Test for setup failures for missing to."""
self.assertFalse(state.trigger(
self.hass, {
'platform': 'state',
@@ -378,6 +395,7 @@ class TestAutomationState(unittest.TestCase):
}, lambda x: x))
def test_if_not_fires_on_entity_change_with_for(self):
"""Test for not firing on entity change with for."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -403,6 +421,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(0, len(self.calls))
def test_if_fires_on_entity_change_with_for(self):
"""Test for firing on entity change with for."""
self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: {
'trigger': {
@@ -426,6 +445,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fires_on_for_condition(self):
"""Test for firing if contition is on."""
point1 = dt_util.utcnow()
point2 = point1 + timedelta(seconds=10)
with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
@@ -464,6 +484,7 @@ class TestAutomationState(unittest.TestCase):
self.assertEqual(1, len(self.calls))
def test_if_fails_setup_for_without_time(self):
"""Test for setup failure if no time is provided."""
self.assertIsNone(state.if_action(
self.hass, {
'platform': 'state',
@@ -473,6 +494,7 @@ class TestAutomationState(unittest.TestCase):
}))
def test_if_fails_setup_for_without_entity(self):
"""Test for setup failure if no entity is provided."""
self.assertIsNone(state.if_action(
self.hass, {
'platform': 'state',