Make tests pass flake8

This commit is contained in:
Paulus Schoutsen 2016-02-14 13:07:21 -08:00
parent dd2aec0a08
commit bade0e0d71
10 changed files with 51 additions and 25 deletions

View File

@ -5,7 +5,7 @@ universal = 1
testpaths = tests testpaths = tests
[flake8] [flake8]
exclude = .venv,.git,.tox,docs,www_static,tests,venv,bin,lib exclude = .venv,.git,.tox,docs,www_static,venv,bin,lib
[pep257] [pep257]
ignore = D203,D105 ignore = D203,D105

View File

@ -365,7 +365,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(0, len(self.calls)) self.assertEqual(0, len(self.calls))
def test_if_fires_on_attribute_change_with_attribute_below_multiple_attributes(self): def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
'trigger': { 'trigger': {
@ -380,7 +380,8 @@ class TestAutomationNumericState(unittest.TestCase):
} }
})) }))
# 9 is not below 10 # 9 is not below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': 9, 'not_test_attribute': 11}) self.hass.states.set('test.entity', 'entity',
{'test_attribute': 9, 'not_test_attribute': 11})
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls)) self.assertEqual(1, len(self.calls))
@ -390,7 +391,8 @@ class TestAutomationNumericState(unittest.TestCase):
'trigger': { 'trigger': {
'platform': 'numeric_state', 'platform': 'numeric_state',
'entity_id': 'test.entity', 'entity_id': 'test.entity',
'value_template': '{{ state.attributes.test_attribute[2] }}', 'value_template':
'{{ state.attributes.test_attribute[2] }}',
'below': 10, 'below': 10,
}, },
'action': { 'action': {
@ -399,7 +401,8 @@ class TestAutomationNumericState(unittest.TestCase):
} }
})) }))
# 3 is below 10 # 3 is below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': [11, 15, 3]}) self.hass.states.set('test.entity', 'entity',
{'test_attribute': [11, 15, 3]})
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls)) self.assertEqual(1, len(self.calls))
@ -409,7 +412,8 @@ class TestAutomationNumericState(unittest.TestCase):
'trigger': { 'trigger': {
'platform': 'numeric_state', 'platform': 'numeric_state',
'entity_id': 'test.entity', 'entity_id': 'test.entity',
'value_template': '{{ state.attributes.test_attribute | multiply(10) }}', 'value_template':
'{{ state.attributes.test_attribute | multiply(10) }}',
'below': 10, 'below': 10,
}, },
'action': { 'action': {
@ -418,11 +422,12 @@ class TestAutomationNumericState(unittest.TestCase):
} }
})) }))
# 9 is below 10 # 9 is below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': '0.9'}) self.hass.states.set('test.entity', 'entity',
{'test_attribute': '0.9'})
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls)) self.assertEqual(1, len(self.calls))
def test_if_not_fires_on_attribute_change_with_attribute_not_below_multiple_attributes(self): def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr(self):
self.assertTrue(automation.setup(self.hass, { self.assertTrue(automation.setup(self.hass, {
automation.DOMAIN: { automation.DOMAIN: {
'trigger': { 'trigger': {
@ -437,7 +442,8 @@ class TestAutomationNumericState(unittest.TestCase):
} }
})) }))
# 11 is not below 10 # 11 is not below 10
self.hass.states.set('test.entity', 'entity', {'test_attribute': 11, 'not_test_attribute': 9}) self.hass.states.set('test.entity', 'entity',
{'test_attribute': 11, 'not_test_attribute': 9})
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
self.assertEqual(0, len(self.calls)) self.assertEqual(0, len(self.calls))

View File

@ -256,7 +256,8 @@ class TestAutomationTemplate(unittest.TestCase):
automation.DOMAIN: { automation.DOMAIN: {
'trigger': { 'trigger': {
'platform': 'template', 'platform': 'template',
'value_template': '{{ not is_state("test.entity", "world") }}', 'value_template':
'{{ not is_state("test.entity", "world") }}',
}, },
'action': { 'action': {
'service': 'test.automation' 'service': 'test.automation'

View File

@ -114,7 +114,8 @@ class TestDemoMediaPlayer(unittest.TestCase):
assert 0 < (mp.SUPPORT_PREVIOUS_TRACK & assert 0 < (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands')) state.attributes.get('supported_media_commands'))
@patch('homeassistant.components.media_player.demo.DemoYoutubePlayer.media_seek') @patch('homeassistant.components.media_player.demo.DemoYoutubePlayer.'
'media_seek')
def test_play_media(self, mock_seek): def test_play_media(self, mock_seek):
assert mp.setup(self.hass, {'media_player': {'platform': 'demo'}}) assert mp.setup(self.hass, {'media_player': {'platform': 'demo'}})
ent_id = 'media_player.living_room' ent_id = 'media_player.living_room'

View File

@ -162,7 +162,8 @@ class TestProximity:
self.hass.pool.block_till_done() self.hass.pool.block_till_done()
state = self.hass.states.get('proximity.home') state = self.hass.states.get('proximity.home')
assert state.state == '0' assert state.state == '0'
assert (state.attributes.get('nearest') == 'test1, test2') or (state.attributes.get('nearest') == 'test2, test1') assert ((state.attributes.get('nearest') == 'test1, test2') or
(state.attributes.get('nearest') == 'test2, test1'))
assert state.attributes.get('dir_of_travel') == 'arrived' assert state.attributes.get('dir_of_travel') == 'arrived'
def test_device_tracker_test1_away(self): def test_device_tracker_test1_away(self):
@ -447,7 +448,7 @@ class TestProximity:
assert state.attributes.get('nearest') == 'test1' assert state.attributes.get('nearest') == 'test1'
assert state.attributes.get('dir_of_travel') == 'unknown' assert state.attributes.get('dir_of_travel') == 'unknown'
def test_device_tracker_test1_awayfurther_than_test2_first_test1_than_test2_than_test1(self): def test_device_tracker_test1_awayfurther_test2_first(self):
self.hass.states.set( self.hass.states.set(
'device_tracker.test1', 'not_home', 'device_tracker.test1', 'not_home',
{ {

View File

@ -131,7 +131,6 @@ class TestHoneywell(unittest.TestCase):
devices = [x[0][1].deviceid for x in result] devices = [x[0][1].deviceid for x in result]
self.assertEqual([mock.sentinel.loc2dev1], devices) self.assertEqual([mock.sentinel.loc2dev1], devices)
@mock.patch('evohomeclient.EvohomeClient') @mock.patch('evohomeclient.EvohomeClient')
@mock.patch('homeassistant.components.thermostat.honeywell.' @mock.patch('homeassistant.components.thermostat.honeywell.'
'RoundThermostat') 'RoundThermostat')

View File

@ -7,13 +7,22 @@ Tests event helpers.
# pylint: disable=protected-access,too-many-public-methods # pylint: disable=protected-access,too-many-public-methods
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
import unittest import unittest
from datetime import datetime from datetime import datetime, timedelta
from astral import Astral from astral import Astral
import homeassistant.core as ha import homeassistant.core as ha
from homeassistant.helpers.event import * from homeassistant.helpers.event import (
track_point_in_utc_time,
track_point_in_time,
track_utc_time_change,
track_time_change,
track_state_change,
track_sunrise,
track_sunset,
)
from homeassistant.components import sun from homeassistant.components import sun
import homeassistant.util.dt as dt_util
class TestEventHelpers(unittest.TestCase): class TestEventHelpers(unittest.TestCase):

View File

@ -14,8 +14,8 @@ from homeassistant.const import SERVICE_TURN_ON
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from homeassistant.helpers import state from homeassistant.helpers import state
from homeassistant.const import ( from homeassistant.const import (
STATE_OFF, STATE_OPEN, STATE_CLOSED, STATE_OPEN, STATE_CLOSED,
STATE_LOCKED, STATE_UNLOCKED, STATE_UNKNOWN, STATE_LOCKED, STATE_UNLOCKED,
STATE_ON, STATE_OFF) STATE_ON, STATE_OFF)
from homeassistant.components.sun import (STATE_ABOVE_HORIZON, from homeassistant.components.sun import (STATE_ABOVE_HORIZON,
STATE_BELOW_HORIZON) STATE_BELOW_HORIZON)

View File

@ -45,7 +45,9 @@ class TestUtilTemplate(unittest.TestCase):
'open10', 'open10',
template.render( template.render(
self.hass, self.hass,
'{% for state in states.sensor %}{{ state.state }}{% endfor %}')) """
{% for state in states.sensor %}{{ state.state }}{% endfor %}
"""))
def test_rounding_value(self): def test_rounding_value(self):
self.hass.states.set('sensor.temperature', 12.78) self.hass.states.set('sensor.temperature', 12.78)
@ -63,7 +65,8 @@ class TestUtilTemplate(unittest.TestCase):
'128', '128',
template.render( template.render(
self.hass, self.hass,
'{{ states.sensor.temperature.state | multiply(10) | round }}')) '{{ states.sensor.temperature.state | multiply(10) | round }}'
))
def test_passing_vars_as_keywords(self): def test_passing_vars_as_keywords(self):
self.assertEqual( self.assertEqual(
@ -91,7 +94,7 @@ class TestUtilTemplate(unittest.TestCase):
template.render_with_possible_json_value( template.render_with_possible_json_value(
self.hass, '{{ value_json', 'hello')) self.hass, '{{ value_json', 'hello'))
def test_render_with_possible_json_value_with_template_error_error_value(self): def test_render_with_possible_json_value_with_template_error_value(self):
self.assertEqual( self.assertEqual(
'-', '-',
template.render_with_possible_json_value( template.render_with_possible_json_value(
@ -107,7 +110,9 @@ class TestUtilTemplate(unittest.TestCase):
'exists', 'exists',
template.render( template.render(
self.hass, self.hass,
'{% if states.test.object %}exists{% else %}not exists{% endif %}')) """
{% if states.test.object %}exists{% else %}not exists{% endif %}
"""))
def test_is_state(self): def test_is_state(self):
self.hass.states.set('test.object', 'available') self.hass.states.set('test.object', 'available')
@ -115,7 +120,9 @@ class TestUtilTemplate(unittest.TestCase):
'yes', 'yes',
template.render( template.render(
self.hass, self.hass,
'{% if is_state("test.object", "available") %}yes{% else %}no{% endif %}')) """
{% if is_state("test.object", "available") %}yes{% else %}no{% endif %}
"""))
def test_is_state_attr(self): def test_is_state_attr(self):
self.hass.states.set('test.object', 'available', {'mode': 'on'}) self.hass.states.set('test.object', 'available', {'mode': 'on'})
@ -123,7 +130,9 @@ class TestUtilTemplate(unittest.TestCase):
'yes', 'yes',
template.render( template.render(
self.hass, self.hass,
'{% if is_state_attr("test.object", "mode", "on") %}yes{% else %}no{% endif %}')) """
{% if is_state_attr("test.object", "mode", "on") %}yes{% else %}no{% endif %}
"""))
def test_states_function(self): def test_states_function(self):
self.hass.states.set('test.object', 'available') self.hass.states.set('test.object', 'available')