Use a future for mock coro (#34989)
This commit is contained in:
parent
ba7391528f
commit
76f392476b
26 changed files with 154 additions and 262 deletions
|
@ -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",
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue