New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some handle leaks in rainforest_raven #113035
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
"""Tests for the Rainforest RAVEn data coordinator.""" | ||
|
||
import asyncio | ||
import functools | ||
|
||
from aioraven.device import RAVEnConnectionError | ||
import pytest | ||
|
||
|
@@ -84,6 +87,19 @@ async def test_coordinator_device_error_update(hass: HomeAssistant, mock_device) | |
assert coordinator.last_update_success is False | ||
|
||
|
||
async def test_coordinator_device_timeout_update(hass: HomeAssistant, mock_device): | ||
"""Test handling of a device timeout during an update.""" | ||
entry = create_mock_entry() | ||
coordinator = RAVEnDataCoordinator(hass, entry) | ||
|
||
await coordinator.async_config_entry_first_refresh() | ||
assert coordinator.last_update_success is True | ||
|
||
mock_device.get_network_info.side_effect = functools.partial(asyncio.sleep, 10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides this, I'd make the timeout time a constant so we can easily patch it to 0. We don't want slow tests. |
||
await coordinator.async_refresh() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move time forward instead to trigger a refresh. See other integrations that use a coordinator with tests for examples. |
||
assert coordinator.last_update_success is False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should assert that the mock device is closed. We can also assert that a coordinator entity have its state set to unavailable. |
||
|
||
|
||
async def test_coordinator_comm_error(hass: HomeAssistant, mock_device): | ||
"""Test handling of an error parsing or reading raw device data.""" | ||
entry = create_mock_entry() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set up the integration instead. We shouldn't interact with the coordinator directly as that's an integration detail.
https://developers.home-assistant.io/docs/development_testing#writing-tests-for-integrations