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

+16 -7
View File
@@ -1,9 +1,4 @@
"""
tests.components.switch.test_mfi
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests mFi switch.
"""
"""The tests for the mFi switch platform."""
import unittest
import unittest.mock as mock
@@ -15,6 +10,8 @@ from tests.common import get_test_home_assistant
class TestMfiSwitchSetup(test_mfi_sensor.TestMfiSensorSetup):
"""Test the mFi switch."""
PLATFORM = mfi
COMPONENT = switch
THING = 'switch'
@@ -31,6 +28,7 @@ class TestMfiSwitchSetup(test_mfi_sensor.TestMfiSensorSetup):
@mock.patch('mficlient.client.MFiClient')
@mock.patch('homeassistant.components.switch.mfi.MfiSwitch')
def test_setup_adds_proper_devices(self, mock_switch, mock_client):
"""Test if setup adds devices."""
ports = {i: mock.MagicMock(model=model)
for i, model in enumerate(mfi.SWITCH_MODELS)}
ports['bad'] = mock.MagicMock(model='notaswitch')
@@ -45,7 +43,10 @@ class TestMfiSwitchSetup(test_mfi_sensor.TestMfiSensorSetup):
class TestMfiSwitch(unittest.TestCase):
"""Test for mFi switch platform."""
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
@@ -53,17 +54,20 @@ class TestMfiSwitch(unittest.TestCase):
self.switch = mfi.MfiSwitch(self.port)
def teardown_method(self, method):
""" Stop down stuff we started. """
"""Stop everything that was started."""
self.hass.stop()
def test_name(self):
"""Test the name."""
self.assertEqual(self.port.label, self.switch.name)
def test_update(self):
"""Test update."""
self.switch.update()
self.port.refresh.assert_called_once_with()
def test_update_with_target_state(self):
"""Test update with target state."""
self.switch._target_state = True
self.port.data = {}
self.port.data['output'] = 'stale'
@@ -75,24 +79,29 @@ class TestMfiSwitch(unittest.TestCase):
self.assertEqual('untouched', self.port.data['output'])
def test_turn_on(self):
"""Test turn_on."""
self.switch.turn_on()
self.port.control.assert_called_once_with(True)
self.assertTrue(self.switch._target_state)
def test_turn_off(self):
"""Test turn_off."""
self.switch.turn_off()
self.port.control.assert_called_once_with(False)
self.assertFalse(self.switch._target_state)
def test_current_power_mwh(self):
"""Test current power."""
self.port.data = {'active_pwr': 1}
self.assertEqual(1000, self.switch.current_power_mwh)
def test_current_power_mwh_no_data(self):
"""Test current power if there is no data."""
self.port.data = {'notpower': 123}
self.assertEqual(0, self.switch.current_power_mwh)
def test_device_state_attributes(self):
"""Test the state attributes."""
self.port.data = {'v_rms': 1.25,
'i_rms': 2.75}
self.assertEqual({'volts': 1.2, 'amps': 2.8},