mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Migrate discovery tests from coroutine to async/await (#30376)
This commit is contained in:
parent
b43b50b6d2
commit
bcb47dab45
@ -1,5 +1,4 @@
|
|||||||
"""The tests for the discovery component."""
|
"""The tests for the discovery component."""
|
||||||
import asyncio
|
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -55,29 +54,27 @@ async def mock_discovery(hass, discoveries, config=BASE_CONFIG):
|
|||||||
return mock_discover, mock_platform
|
return mock_discover, mock_platform
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_unknown_service(hass):
|
||||||
def test_unknown_service(hass):
|
|
||||||
"""Test that unknown service is ignored."""
|
"""Test that unknown service is ignored."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [("this_service_will_never_be_supported", {"info": "some"})]
|
return [("this_service_will_never_be_supported", {"info": "some"})]
|
||||||
|
|
||||||
mock_discover, mock_platform = yield from mock_discovery(hass, discover)
|
mock_discover, mock_platform = await mock_discovery(hass, discover)
|
||||||
|
|
||||||
assert not mock_discover.called
|
assert not mock_discover.called
|
||||||
assert not mock_platform.called
|
assert not mock_platform.called
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_load_platform(hass):
|
||||||
def test_load_platform(hass):
|
|
||||||
"""Test load a platform."""
|
"""Test load a platform."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE, SERVICE_INFO)]
|
return [(SERVICE, SERVICE_INFO)]
|
||||||
|
|
||||||
mock_discover, mock_platform = yield from mock_discovery(hass, discover)
|
mock_discover, mock_platform = await mock_discovery(hass, discover)
|
||||||
|
|
||||||
assert not mock_discover.called
|
assert not mock_discover.called
|
||||||
assert mock_platform.called
|
assert mock_platform.called
|
||||||
@ -86,15 +83,14 @@ def test_load_platform(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_load_component(hass):
|
||||||
def test_load_component(hass):
|
|
||||||
"""Test load a component."""
|
"""Test load a component."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
mock_discover, mock_platform = yield from mock_discovery(hass, discover)
|
mock_discover, mock_platform = await mock_discovery(hass, discover)
|
||||||
|
|
||||||
assert mock_discover.called
|
assert mock_discover.called
|
||||||
assert not mock_platform.called
|
assert not mock_platform.called
|
||||||
@ -107,24 +103,20 @@ def test_load_component(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_ignore_service(hass):
|
||||||
def test_ignore_service(hass):
|
|
||||||
"""Test ignore service."""
|
"""Test ignore service."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
"""Fake discovery."""
|
"""Fake discovery."""
|
||||||
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
return [(SERVICE_NO_PLATFORM, SERVICE_INFO)]
|
||||||
|
|
||||||
mock_discover, mock_platform = yield from mock_discovery(
|
mock_discover, mock_platform = await mock_discovery(hass, discover, IGNORE_CONFIG)
|
||||||
hass, discover, IGNORE_CONFIG
|
|
||||||
)
|
|
||||||
|
|
||||||
assert not mock_discover.called
|
assert not mock_discover.called
|
||||||
assert not mock_platform.called
|
assert not mock_platform.called
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_discover_duplicates(hass):
|
||||||
def test_discover_duplicates(hass):
|
|
||||||
"""Test load a component."""
|
"""Test load a component."""
|
||||||
|
|
||||||
def discover(netdisco):
|
def discover(netdisco):
|
||||||
@ -134,7 +126,7 @@ def test_discover_duplicates(hass):
|
|||||||
(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
(SERVICE_NO_PLATFORM, SERVICE_INFO),
|
||||||
]
|
]
|
||||||
|
|
||||||
mock_discover, mock_platform = yield from mock_discovery(hass, discover)
|
mock_discover, mock_platform = await mock_discovery(hass, discover)
|
||||||
|
|
||||||
assert mock_discover.called
|
assert mock_discover.called
|
||||||
assert mock_discover.call_count == 1
|
assert mock_discover.call_count == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user