Fix PEP257 issues
This commit is contained in:
1 parent
d6eab03a61
commit
9838697d2b
120 files changed
+1447
-1297
No files matched your search
@@ -1,9 +1,4 @@
|
||||
"""
|
||||
tests.components.test_graphite
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests graphite feeder.
|
||||
"""
|
||||
"""The tests for the Graphite component."""
|
||||
import socket
|
||||
import unittest
|
||||
from unittest import mock
|
||||
@@ -19,23 +14,28 @@ from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestGraphite(unittest.TestCase):
|
||||
"""Test the Graphite component."""
|
||||
|
||||
def setup_method(self, method):
|
||||
"""Setup things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.hass.config.latitude = 32.87336
|
||||
self.hass.config.longitude = 117.22743
|
||||
self.gf = graphite.GraphiteFeeder(self.hass, 'foo', 123, 'ha')
|
||||
|
||||
def teardown_method(self, method):
|
||||
""" Stop down stuff we started. """
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@mock.patch('homeassistant.components.graphite.GraphiteFeeder')
|
||||
def test_minimal_config(self, mock_gf):
|
||||
"""Test setup with minimal configuration."""
|
||||
self.assertTrue(graphite.setup(self.hass, {}))
|
||||
mock_gf.assert_called_once_with(self.hass, 'localhost', 2003, 'ha')
|
||||
|
||||
@mock.patch('homeassistant.components.graphite.GraphiteFeeder')
|
||||
def test_full_config(self, mock_gf):
|
||||
"""Test setup with full configuration."""
|
||||
config = {
|
||||
'graphite': {
|
||||
'host': 'foo',
|
||||
@@ -48,6 +48,7 @@ class TestGraphite(unittest.TestCase):
|
||||
|
||||
@mock.patch('homeassistant.components.graphite.GraphiteFeeder')
|
||||
def test_config_bad_port(self, mock_gf):
|
||||
"""Test setup with invalid port."""
|
||||
config = {
|
||||
'graphite': {
|
||||
'host': 'foo',
|
||||
@@ -58,6 +59,7 @@ class TestGraphite(unittest.TestCase):
|
||||
self.assertFalse(mock_gf.called)
|
||||
|
||||
def test_subscribe(self):
|
||||
"""Test the subscription."""
|
||||
fake_hass = mock.MagicMock()
|
||||
gf = graphite.GraphiteFeeder(fake_hass, 'foo', 123, 'ha')
|
||||
fake_hass.bus.listen_once.has_calls([
|
||||
@@ -68,22 +70,26 @@ class TestGraphite(unittest.TestCase):
|
||||
EVENT_STATE_CHANGED, gf.event_listener)
|
||||
|
||||
def test_start(self):
|
||||
"""Test the start."""
|
||||
with mock.patch.object(self.gf, 'start') as mock_start:
|
||||
self.gf.start_listen('event')
|
||||
mock_start.assert_called_once_with()
|
||||
|
||||
def test_shutdown(self):
|
||||
"""Test the shutdown."""
|
||||
with mock.patch.object(self.gf, '_queue') as mock_queue:
|
||||
self.gf.shutdown('event')
|
||||
mock_queue.put.assert_called_once_with(self.gf._quit_object)
|
||||
|
||||
def test_event_listener(self):
|
||||
"""Test the event listener."""
|
||||
with mock.patch.object(self.gf, '_queue') as mock_queue:
|
||||
self.gf.event_listener('foo')
|
||||
mock_queue.put.assert_called_once_with('foo')
|
||||
|
||||
@mock.patch('time.time')
|
||||
def test_report_attributes(self, mock_time):
|
||||
"""Test the reporting with attributes."""
|
||||
mock_time.return_value = 12345
|
||||
attrs = {'foo': 1,
|
||||
'bar': 2.0,
|
||||
@@ -104,6 +110,7 @@ class TestGraphite(unittest.TestCase):
|
||||
|
||||
@mock.patch('time.time')
|
||||
def test_report_with_string_state(self, mock_time):
|
||||
"""Test the reporting with strings."""
|
||||
mock_time.return_value = 12345
|
||||
expected = [
|
||||
'ha.entity.foo 1.000000 12345',
|
||||
@@ -117,6 +124,7 @@ class TestGraphite(unittest.TestCase):
|
||||
|
||||
@mock.patch('time.time')
|
||||
def test_report_with_binary_state(self, mock_time):
|
||||
"""Test the reporting with binary state."""
|
||||
mock_time.return_value = 12345
|
||||
state = ha.State('domain.entity', STATE_ON, {'foo': 1.0})
|
||||
with mock.patch.object(self.gf, '_send_to_graphite') as mock_send:
|
||||
@@ -136,6 +144,7 @@ class TestGraphite(unittest.TestCase):
|
||||
|
||||
@mock.patch('time.time')
|
||||
def test_send_to_graphite_errors(self, mock_time):
|
||||
"""Test the sending with errors."""
|
||||
mock_time.return_value = 12345
|
||||
state = ha.State('domain.entity', STATE_ON, {'foo': 1.0})
|
||||
with mock.patch.object(self.gf, '_send_to_graphite') as mock_send:
|
||||
@@ -146,6 +155,7 @@ class TestGraphite(unittest.TestCase):
|
||||
|
||||
@mock.patch('socket.socket')
|
||||
def test_send_to_graphite(self, mock_socket):
|
||||
"""Test the sending of data."""
|
||||
self.gf._send_to_graphite('foo')
|
||||
mock_socket.assert_called_once_with(socket.AF_INET,
|
||||
socket.SOCK_STREAM)
|
||||
@@ -156,6 +166,7 @@ class TestGraphite(unittest.TestCase):
|
||||
sock.close.assert_called_once_with()
|
||||
|
||||
def test_run_stops(self):
|
||||
"""Test the stops."""
|
||||
with mock.patch.object(self.gf, '_queue') as mock_queue:
|
||||
mock_queue.get.return_value = self.gf._quit_object
|
||||
self.assertEqual(None, self.gf.run())
|
||||
@@ -163,6 +174,7 @@ class TestGraphite(unittest.TestCase):
|
||||
mock_queue.task_done.assert_called_once_with()
|
||||
|
||||
def test_run(self):
|
||||
"""Test the running."""
|
||||
runs = []
|
||||
event = mock.MagicMock(event_type=EVENT_STATE_CHANGED,
|
||||
data={'entity_id': 'entity',
|
||||
|
||||
Reference in new issue
Block a user