Rewrite homematic unittest tests to pytest style test functions (#41766)

Issue: https://github.com/home-assistant/core/issues/40856
This commit is contained in:
thaohtp 2020-10-13 19:51:08 +02:00 committed by GitHub
parent 267d97e80e
commit 7298bb32f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,77 +1,65 @@
"""The tests for the Homematic notification platform.""" """The tests for the Homematic notification platform."""
import unittest
import homeassistant.components.notify as notify_comp import homeassistant.components.notify as notify_comp
from homeassistant.setup import setup_component from homeassistant.setup import async_setup_component
from tests.common import assert_setup_component, get_test_home_assistant from tests.common import assert_setup_component
class TestHomematicNotify(unittest.TestCase): async def test_setup_full(hass):
"""Test the Homematic notifications.""" """Test valid configuration."""
await async_setup_component(
def setUp(self): # pylint: disable=invalid-name hass,
"""Set up things to be run when tests are started.""" "homematic",
self.hass = get_test_home_assistant() {"homematic": {"hosts": {"ccu2": {"host": "127.0.0.1"}}}},
self.addCleanup(self.tear_down_cleanup) )
with assert_setup_component(1) as handle_config:
def tear_down_cleanup(self): assert await async_setup_component(
"""Stop down everything that was started.""" hass,
self.hass.stop() "notify",
{
def test_setup_full(self): "notify": {
"""Test valid configuration.""" "name": "test",
setup_component( "platform": "homematic",
self.hass, "address": "NEQXXXXXXX",
"homematic", "channel": 2,
{"homematic": {"hosts": {"ccu2": {"host": "127.0.0.1"}}}}, "param": "SUBMIT",
"value": "1,1,108000,2",
"interface": "my-interface",
}
},
) )
with assert_setup_component(1) as handle_config: assert handle_config[notify_comp.DOMAIN]
assert setup_component(
self.hass,
"notify",
{
"notify": {
"name": "test",
"platform": "homematic",
"address": "NEQXXXXXXX",
"channel": 2,
"param": "SUBMIT",
"value": "1,1,108000,2",
"interface": "my-interface",
}
},
)
assert handle_config[notify_comp.DOMAIN]
def test_setup_without_optional(self):
"""Test valid configuration without optional.""" async def test_setup_without_optional(hass):
setup_component( """Test valid configuration without optional."""
self.hass, await async_setup_component(
"homematic", hass,
{"homematic": {"hosts": {"ccu2": {"host": "127.0.0.1"}}}}, "homematic",
{"homematic": {"hosts": {"ccu2": {"host": "127.0.0.1"}}}},
)
with assert_setup_component(1) as handle_config:
assert await async_setup_component(
hass,
"notify",
{
"notify": {
"name": "test",
"platform": "homematic",
"address": "NEQXXXXXXX",
"channel": 2,
"param": "SUBMIT",
"value": "1,1,108000,2",
}
},
) )
with assert_setup_component(1) as handle_config: assert handle_config[notify_comp.DOMAIN]
assert setup_component(
self.hass,
"notify",
{
"notify": {
"name": "test",
"platform": "homematic",
"address": "NEQXXXXXXX",
"channel": 2,
"param": "SUBMIT",
"value": "1,1,108000,2",
}
},
)
assert handle_config[notify_comp.DOMAIN]
def test_bad_config(self):
"""Test invalid configuration.""" async def test_bad_config(hass):
config = {notify_comp.DOMAIN: {"name": "test", "platform": "homematic"}} """Test invalid configuration."""
with assert_setup_component(0) as handle_config: config = {notify_comp.DOMAIN: {"name": "test", "platform": "homematic"}}
assert setup_component(self.hass, notify_comp.DOMAIN, config) with assert_setup_component(0) as handle_config:
assert not handle_config[notify_comp.DOMAIN] assert await async_setup_component(hass, notify_comp.DOMAIN, config)
assert not handle_config[notify_comp.DOMAIN]