mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Fix PEP257 issues
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
"""
|
||||
tests.components.sensor.test_mfi
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Tests mFi sensor.
|
||||
"""
|
||||
"""The tests for the mFi sensor platform."""
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
|
||||
@@ -17,6 +12,8 @@ from tests.common import get_test_home_assistant
|
||||
|
||||
|
||||
class TestMfiSensorSetup(unittest.TestCase):
|
||||
"""Test the mFi sensor platform."""
|
||||
|
||||
PLATFORM = mfi
|
||||
COMPONENT = sensor
|
||||
THING = 'sensor'
|
||||
@@ -33,15 +30,17 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
def teardown_method(self, method):
|
||||
""" Stop down stuff we started. """
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
def test_setup_missing_config(self):
|
||||
"""Test setup with missing configuration."""
|
||||
config = {
|
||||
'sensor': {
|
||||
'platform': 'mfi',
|
||||
@@ -51,6 +50,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
|
||||
@mock.patch('mficlient.client')
|
||||
def test_setup_failed_login(self, mock_client):
|
||||
"""Test setup with login failure."""
|
||||
mock_client.FailedToLogin = Exception()
|
||||
mock_client.MFiClient.side_effect = mock_client.FailedToLogin
|
||||
self.assertFalse(
|
||||
@@ -60,6 +60,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
|
||||
@mock.patch('mficlient.client')
|
||||
def test_setup_failed_connect(self, mock_client):
|
||||
"""Test setup with conection failure."""
|
||||
mock_client.FailedToLogin = Exception()
|
||||
mock_client.MFiClient.side_effect = requests.exceptions.ConnectionError
|
||||
self.assertFalse(
|
||||
@@ -69,6 +70,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
|
||||
@mock.patch('mficlient.client.MFiClient')
|
||||
def test_setup_minimum(self, mock_client):
|
||||
"""Test setup with minimum configuration."""
|
||||
config = dict(self.GOOD_CONFIG)
|
||||
del config[self.THING]['port']
|
||||
assert self.COMPONENT.setup(self.hass, config)
|
||||
@@ -78,6 +80,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
|
||||
@mock.patch('mficlient.client.MFiClient')
|
||||
def test_setup_with_port(self, mock_client):
|
||||
"""Test setup with port."""
|
||||
config = dict(self.GOOD_CONFIG)
|
||||
config[self.THING]['port'] = 6123
|
||||
assert self.COMPONENT.setup(self.hass, config)
|
||||
@@ -87,6 +90,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
|
||||
@mock.patch('mficlient.client.MFiClient')
|
||||
def test_setup_with_tls_disabled(self, mock_client):
|
||||
"""Test setup without TLS."""
|
||||
config = dict(self.GOOD_CONFIG)
|
||||
del config[self.THING]['port']
|
||||
config[self.THING]['use_tls'] = False
|
||||
@@ -99,6 +103,7 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
@mock.patch('mficlient.client.MFiClient')
|
||||
@mock.patch('homeassistant.components.sensor.mfi.MfiSensor')
|
||||
def test_setup_adds_proper_devices(self, mock_sensor, mock_client):
|
||||
"""Test if setup adds devices."""
|
||||
ports = {i: mock.MagicMock(model=model)
|
||||
for i, model in enumerate(mfi.SENSOR_MODELS)}
|
||||
ports['bad'] = mock.MagicMock(model='notasensor')
|
||||
@@ -113,7 +118,10 @@ class TestMfiSensorSetup(unittest.TestCase):
|
||||
|
||||
|
||||
class TestMfiSensor(unittest.TestCase):
|
||||
"""Test for mFi sensor 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
|
||||
@@ -121,29 +129,35 @@ class TestMfiSensor(unittest.TestCase):
|
||||
self.sensor = mfi.MfiSensor(self.port, self.hass)
|
||||
|
||||
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.sensor.name)
|
||||
|
||||
def test_uom_temp(self):
|
||||
"""Test the UOM temperature."""
|
||||
self.port.tag = 'temperature'
|
||||
self.assertEqual(TEMP_CELCIUS, self.sensor.unit_of_measurement)
|
||||
|
||||
def test_uom_power(self):
|
||||
"""Test the UOEM power."""
|
||||
self.port.tag = 'active_pwr'
|
||||
self.assertEqual('Watts', self.sensor.unit_of_measurement)
|
||||
|
||||
def test_uom_digital(self):
|
||||
"""Test the UOM digital input."""
|
||||
self.port.model = 'Input Digital'
|
||||
self.assertEqual('State', self.sensor.unit_of_measurement)
|
||||
|
||||
def test_uom_unknown(self):
|
||||
"""Test the UOM."""
|
||||
self.port.tag = 'balloons'
|
||||
self.assertEqual('balloons', self.sensor.unit_of_measurement)
|
||||
|
||||
def test_state_digital(self):
|
||||
"""Test the digital input."""
|
||||
self.port.model = 'Input Digital'
|
||||
self.port.value = 0
|
||||
self.assertEqual(mfi.STATE_OFF, self.sensor.state)
|
||||
@@ -153,6 +167,7 @@ class TestMfiSensor(unittest.TestCase):
|
||||
self.assertEqual(mfi.STATE_ON, self.sensor.state)
|
||||
|
||||
def test_state_digits(self):
|
||||
"""Test the state of digits."""
|
||||
self.port.tag = 'didyoucheckthedict?'
|
||||
self.port.value = 1.25
|
||||
with mock.patch.dict(mfi.DIGITS, {'didyoucheckthedict?': 1}):
|
||||
@@ -161,5 +176,6 @@ class TestMfiSensor(unittest.TestCase):
|
||||
self.assertEqual(1.0, self.sensor.state)
|
||||
|
||||
def test_update(self):
|
||||
"""Test the update."""
|
||||
self.sensor.update()
|
||||
self.port.refresh.assert_called_once_with()
|
||||
|
||||
Reference in New Issue
Block a user