-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update opentherm_gw tests to avoid patching internals (#125152)
* Update tests to avoid patching internals * * Use fixtures for tests * Update variable names in tests for clarity * Use hass.config_entries.async_setup instead of setup.async_setup_component
- Loading branch information
Showing
3 changed files
with
157 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Test configuration for opentherm_gw.""" | ||
|
||
from collections.abc import Generator | ||
from unittest.mock import AsyncMock, MagicMock, patch | ||
|
||
from pyotgw.vars import OTGW, OTGW_ABOUT | ||
import pytest | ||
|
||
VERSION_TEST = "4.2.5" | ||
MINIMAL_STATUS = {OTGW: {OTGW_ABOUT: f"OpenTherm Gateway {VERSION_TEST}"}} | ||
|
||
|
||
@pytest.fixture | ||
def mock_setup_entry() -> Generator[AsyncMock]: | ||
"""Override async_setup_entry.""" | ||
with patch( | ||
"homeassistant.components.opentherm_gw.async_setup_entry", | ||
return_value=True, | ||
) as mock_setup_entry: | ||
yield mock_setup_entry | ||
|
||
|
||
@pytest.fixture | ||
def mock_pyotgw() -> Generator[MagicMock]: | ||
"""Mock a pyotgw.OpenThermGateway object.""" | ||
with ( | ||
patch( | ||
"homeassistant.components.opentherm_gw.OpenThermGateway", | ||
return_value=MagicMock( | ||
connect=AsyncMock(return_value=MINIMAL_STATUS), | ||
set_control_setpoint=AsyncMock(), | ||
set_max_relative_mod=AsyncMock(), | ||
disconnect=AsyncMock(), | ||
), | ||
) as mock_gateway, | ||
patch( | ||
"homeassistant.components.opentherm_gw.config_flow.pyotgw.OpenThermGateway", | ||
new=mock_gateway, | ||
), | ||
): | ||
yield mock_gateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.