Use a future for mock coro (#34989)

This commit is contained in:
Paulus Schoutsen 2020-04-30 16:31:00 -07:00 committed by GitHub
parent ba7391528f
commit 76f392476b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 154 additions and 262 deletions

View file

@ -5,8 +5,6 @@ from unittest.mock import Mock, patch
from homeassistant.components import folder_watcher
from homeassistant.setup import async_setup_component
from tests.common import MockDependency
async def test_invalid_path_setup(hass):
"""Test that an invalid path is not set up."""
@ -29,8 +27,7 @@ async def test_valid_path_setup(hass):
)
@MockDependency("watchdog", "events")
def test_event(mock_watchdog):
def test_event():
"""Check that Home Assistant events are fired correctly on watchdog event."""
class MockPatternMatchingEventHandler:
@ -39,17 +36,20 @@ def test_event(mock_watchdog):
def __init__(self, patterns):
pass
mock_watchdog.events.PatternMatchingEventHandler = MockPatternMatchingEventHandler
hass = Mock()
handler = folder_watcher.create_event_handler(["*"], hass)
handler.on_created(
Mock(is_directory=False, src_path="/hello/world.txt", event_type="created")
)
assert hass.bus.fire.called
assert hass.bus.fire.mock_calls[0][1][0] == folder_watcher.DOMAIN
assert hass.bus.fire.mock_calls[0][1][1] == {
"event_type": "created",
"path": "/hello/world.txt",
"file": "world.txt",
"folder": "/hello",
}
with patch(
"homeassistant.components.folder_watcher.PatternMatchingEventHandler",
MockPatternMatchingEventHandler,
):
hass = Mock()
handler = folder_watcher.create_event_handler(["*"], hass)
handler.on_created(
Mock(is_directory=False, src_path="/hello/world.txt", event_type="created")
)
assert hass.bus.fire.called
assert hass.bus.fire.mock_calls[0][1][0] == folder_watcher.DOMAIN
assert hass.bus.fire.mock_calls[0][1][1] == {
"event_type": "created",
"path": "/hello/world.txt",
"file": "world.txt",
"folder": "/hello",
}