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
[flake8]
exclude = .venv,.git,.tox,docs,www_static,tests,venv,bin,lib
exclude = .venv,.git,.tox,docs,www_static,venv,bin,lib
[pep257]
ignore = D203,D105

View File

@ -365,7 +365,7 @@ class TestAutomationNumericState(unittest.TestCase):
self.hass.pool.block_till_done()
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, {
automation.DOMAIN: {
'trigger': {
@ -380,7 +380,8 @@ class TestAutomationNumericState(unittest.TestCase):
}
}))
# 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.assertEqual(1, len(self.calls))
@ -390,7 +391,8 @@ class TestAutomationNumericState(unittest.TestCase):
'trigger': {
'platform': 'numeric_state',
'entity_id': 'test.entity',
'value_template': '{{ state.attributes.test_attribute[2] }}',
'value_template':
'{{ state.attributes.test_attribute[2] }}',
'below': 10,
},
'action': {
@ -399,7 +401,8 @@ class TestAutomationNumericState(unittest.TestCase):
}
}))
# 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.assertEqual(1, len(self.calls))
@ -409,7 +412,8 @@ class TestAutomationNumericState(unittest.TestCase):
'trigger': {
'platform': 'numeric_state',
'entity_id': 'test.entity',
'value_template': '{{ state.attributes.test_attribute | multiply(10) }}',
'value_template':
'{{ state.attributes.test_attribute | multiply(10) }}',
'below': 10,
},
'action': {
@ -418,11 +422,12 @@ class TestAutomationNumericState(unittest.TestCase):
}
}))
# 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.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, {
automation.DOMAIN: {
'trigger': {
@ -437,7 +442,8 @@ class TestAutomationNumericState(unittest.TestCase):
}
}))
# 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.assertEqual(0, len(self.calls))

View File

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

View File

@ -114,7 +114,8 @@ class TestDemoMediaPlayer(unittest.TestCase):
assert 0 < (mp.SUPPORT_PREVIOUS_TRACK &
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):
assert mp.setup(self.hass, {'media_player': {'platform': 'demo'}})
ent_id = 'media_player.living_room'

View File

@ -64,7 +64,7 @@ class TestTemplateSensor:
'sensors': {
'test_template_sensor': {
'value_template':
"It {{ states.sensor.test_state.attributes.missing }}."
"It {{ states.sensor.test_state.attributes.missing }}."
}
}
}

View File

@ -162,7 +162,8 @@ class TestProximity:
self.hass.pool.block_till_done()
state = self.hass.states.get('proximity.home')
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'
def test_device_tracker_test1_away(self):
@ -447,7 +448,7 @@ class TestProximity:
assert state.attributes.get('nearest') == 'test1'
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(
'device_tracker.test1', 'not_home',
{

View File

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

View File

@ -7,13 +7,22 @@ Tests event helpers.
# pylint: disable=protected-access,too-many-public-methods
# pylint: disable=too-few-public-methods
import unittest
from datetime import datetime
from datetime import datetime, timedelta
from astral import Astral
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
import homeassistant.util.dt as dt_util
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.helpers import state
from homeassistant.const import (
STATE_OFF, STATE_OPEN, STATE_CLOSED,
STATE_LOCKED, STATE_UNLOCKED, STATE_UNKNOWN,
STATE_OPEN, STATE_CLOSED,
STATE_LOCKED, STATE_UNLOCKED,
STATE_ON, STATE_OFF)
from homeassistant.components.sun import (STATE_ABOVE_HORIZON,
STATE_BELOW_HORIZON)

View File

@ -45,7 +45,9 @@ class TestUtilTemplate(unittest.TestCase):
'open10',
template.render(
self.hass,
'{% for state in states.sensor %}{{ state.state }}{% endfor %}'))
"""
{% for state in states.sensor %}{{ state.state }}{% endfor %}
"""))
def test_rounding_value(self):
self.hass.states.set('sensor.temperature', 12.78)
@ -63,7 +65,8 @@ class TestUtilTemplate(unittest.TestCase):
'128',
template.render(
self.hass,
'{{ states.sensor.temperature.state | multiply(10) | round }}'))
'{{ states.sensor.temperature.state | multiply(10) | round }}'
))
def test_passing_vars_as_keywords(self):
self.assertEqual(
@ -91,7 +94,7 @@ class TestUtilTemplate(unittest.TestCase):
template.render_with_possible_json_value(
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(
'-',
template.render_with_possible_json_value(
@ -107,7 +110,9 @@ class TestUtilTemplate(unittest.TestCase):
'exists',
template.render(
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):
self.hass.states.set('test.object', 'available')
@ -115,7 +120,9 @@ class TestUtilTemplate(unittest.TestCase):
'yes',
template.render(
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):
self.hass.states.set('test.object', 'available', {'mode': 'on'})
@ -123,7 +130,9 @@ class TestUtilTemplate(unittest.TestCase):
'yes',
template.render(
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):
self.hass.states.set('test.object', 'available')