Fix PEP257 issues

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

No files matched your search

@@ -1,9 +1,4 @@
"""
tests.components.device_tracker.test_owntracks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests Owntracks device tracker.
"""
"""The tests for the Owntracks device tracker."""
import json
import os
import unittest
@@ -11,9 +6,7 @@ import unittest
from collections import defaultdict
from homeassistant.components import device_tracker
from homeassistant.const import (STATE_NOT_HOME, CONF_PLATFORM)
import homeassistant.components.device_tracker.owntracks as owntracks
from tests.common import (
@@ -101,10 +94,10 @@ REGION_LEAVE_INACCURATE_MESSAGE = {
class TestDeviceTrackerOwnTracks(unittest.TestCase):
""" Test the Template sensor. """
"""Test the OwnTrack sensor."""
def setup_method(self, method):
""" Init needed objects. """
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.assertTrue(device_tracker.setup(self.hass, {
@@ -155,7 +148,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
owntracks.MOBILE_BEACONS_ACTIVE = defaultdict(list)
def teardown_method(self, method):
""" Stop down stuff we started. """
"""Stop everything that was started."""
self.hass.stop()
try:
@@ -164,39 +157,48 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
pass
def send_message(self, topic, message):
"""Test the sending of a message."""
fire_mqtt_message(
self.hass, topic, json.dumps(message))
self.hass.pool.block_till_done()
def assert_location_state(self, location):
"""Test the assertion of a location state."""
state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.state, location)
def assert_location_latitude(self, latitude):
"""Test the assertion of a location latitude."""
state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.attributes.get('latitude'), latitude)
def assert_location_longitude(self, longitude):
"""Test the assertion of a location longitude."""
state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.attributes.get('longitude'), longitude)
def assert_location_accuracy(self, accuracy):
"""Test the assertion of a location accuracy."""
state = self.hass.states.get(DEVICE_TRACKER_STATE)
self.assertEqual(state.attributes.get('gps_accuracy'), accuracy)
def assert_tracker_state(self, location):
"""Test the assertion of a tracker state."""
state = self.hass.states.get(REGION_TRACKER_STATE)
self.assertEqual(state.state, location)
def assert_tracker_latitude(self, latitude):
"""Test the assertion of a tracker latitude."""
state = self.hass.states.get(REGION_TRACKER_STATE)
self.assertEqual(state.attributes.get('latitude'), latitude)
def assert_tracker_accuracy(self, accuracy):
"""Test the assertion of a tracker accuracy."""
state = self.hass.states.get(REGION_TRACKER_STATE)
self.assertEqual(state.attributes.get('gps_accuracy'), accuracy)
def test_location_update(self):
"""Test the update of a location."""
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
self.assert_location_latitude(2.0)
@@ -204,6 +206,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_state('outer')
def test_location_inaccurate_gps(self):
"""Test the location for inaccurate GPS information."""
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE)
self.send_message(LOCATION_TOPIC, LOCATION_MESSAGE_INACCURATE)
@@ -211,6 +214,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_longitude(1.0)
def test_event_entry_exit(self):
"""Test the entry event."""
self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
# Enter uses the zone's gps co-ords
@@ -236,6 +240,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assertFalse(owntracks.REGIONS_ENTERED[USER])
def test_event_entry_exit_inaccurate(self):
"""Test the event for inaccurate exit."""
self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
# Enter uses the zone's gps co-ords
@@ -254,6 +259,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assertFalse(owntracks.REGIONS_ENTERED[USER])
def test_event_exit_outside_zone_sets_away(self):
"""Test the event for exit zone."""
self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_state('inner')
@@ -267,6 +273,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_state(STATE_NOT_HOME)
def test_event_entry_exit_right_order(self):
"""Test the event for ordering."""
# Enter inner zone
self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
@@ -297,6 +304,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_accuracy(60.0)
def test_event_entry_exit_wrong_order(self):
"""Test the event for wrong order."""
# Enter inner zone
self.send_message(EVENT_TOPIC, REGION_ENTER_MESSAGE)
self.assert_location_state('inner')
@@ -318,6 +326,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_state('outer')
def test_event_entry_exit_passive_zone(self):
"""Test the event for passive zone exits."""
# Enter passive zone
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = "passive"
@@ -354,6 +363,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_accuracy(60.0)
def test_event_entry_unknown_zone(self):
"""Test the event for unknown zone."""
# Just treat as location update
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = "unknown"
@@ -362,6 +372,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_state('outer')
def test_event_exit_unknown_zone(self):
"""Test the event for unknown zone."""
# Just treat as location update
message = REGION_LEAVE_MESSAGE.copy()
message['desc'] = "unknown"
@@ -370,6 +381,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_state('outer')
def test_event_entry_zone_loading_dash(self):
"""Test the event for zone landing."""
# Make sure the leading - is ignored
# Ownracks uses this to switch on hold
message = REGION_ENTER_MESSAGE.copy()
@@ -379,6 +391,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_location_state('inner')
def test_mobile_enter_move_beacon(self):
"""Test the movement of a beacon."""
# Enter mobile beacon, should set location
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = IBEACON_DEVICE
@@ -396,6 +409,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_tracker_state(STATE_NOT_HOME)
def test_mobile_enter_exit_region_beacon(self):
"""Test the enter and the exit of a region beacon."""
# Start tracking beacon
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = IBEACON_DEVICE
@@ -418,6 +432,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_tracker_latitude(2.0)
def test_mobile_exit_move_beacon(self):
"""Test the exit move of a beacon."""
# Start tracking beacon
message = REGION_ENTER_MESSAGE.copy()
message['desc'] = IBEACON_DEVICE
@@ -440,6 +455,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assert_tracker_latitude(3.0)
def test_mobile_multiple_async_enter_exit(self):
"""Test the multiple entering."""
# Test race condition
enter_message = REGION_ENTER_MESSAGE.copy()
enter_message['desc'] = IBEACON_DEVICE
@@ -460,6 +476,7 @@ class TestDeviceTrackerOwnTracks(unittest.TestCase):
self.assertEqual(owntracks.MOBILE_BEACONS_ACTIVE['greg_phone'], [])
def test_mobile_multiple_enter_exit(self):
"""Test the multiple entering."""
# Should only happen if the iphone dies
enter_message = REGION_ENTER_MESSAGE.copy()
enter_message['desc'] = IBEACON_DEVICE