1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-27 14:31:13 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -14,10 +14,10 @@ from tests.common import get_test_home_assistant
@pytest.fixture(autouse=True)
def pymochad_mock():
"""Mock pymochad."""
with mock.patch.dict('sys.modules', {
'pymochad': mock.MagicMock(),
'pymochad.exceptions': mock.MagicMock(),
}):
with mock.patch.dict(
"sys.modules",
{"pymochad": mock.MagicMock(), "pymochad.exceptions": mock.MagicMock()},
):
yield
@@ -26,7 +26,7 @@ class TestMochadSwitchSetup(unittest.TestCase):
PLATFORM = mochad
COMPONENT = switch
THING = 'switch'
THING = "switch"
def setUp(self):
"""Set up things to be run when tests are started."""
@@ -36,20 +36,15 @@ class TestMochadSwitchSetup(unittest.TestCase):
"""Stop everything that was started."""
self.hass.stop()
@mock.patch('homeassistant.components.mochad.switch.MochadSwitch')
@mock.patch("homeassistant.components.mochad.switch.MochadSwitch")
def test_setup_adds_proper_devices(self, mock_switch):
"""Test if setup adds devices."""
good_config = {
'mochad': {},
'switch': {
'platform': 'mochad',
'devices': [
{
'name': 'Switch1',
'address': 'a1',
},
],
}
"mochad": {},
"switch": {
"platform": "mochad",
"devices": [{"name": "Switch1", "address": "a1"}],
},
}
assert setup_component(self.hass, switch.DOMAIN, good_config)
@@ -61,9 +56,8 @@ class TestMochadSwitch(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
controller_mock = mock.MagicMock()
dev_dict = {'address': 'a1', 'name': 'fake_switch'}
self.switch = mochad.MochadSwitch(self.hass, controller_mock,
dev_dict)
dev_dict = {"address": "a1", "name": "fake_switch"}
self.switch = mochad.MochadSwitch(self.hass, controller_mock, dev_dict)
def teardown_method(self, method):
"""Stop everything that was started."""
@@ -71,14 +65,14 @@ class TestMochadSwitch(unittest.TestCase):
def test_name(self):
"""Test the name."""
assert 'fake_switch' == self.switch.name
assert "fake_switch" == self.switch.name
def test_turn_on(self):
"""Test turn_on."""
self.switch.turn_on()
self.switch.switch.send_cmd.assert_called_once_with('on')
self.switch.switch.send_cmd.assert_called_once_with("on")
def test_turn_off(self):
"""Test turn_off."""
self.switch.turn_off()
self.switch.switch.send_cmd.assert_called_once_with('off')
self.switch.switch.send_cmd.assert_called_once_with("off")