mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Fix zeroconf tests with cython 3 (#97054)
This commit is contained in:
parent
9a5774a95d
commit
f36930f165
@ -1104,23 +1104,34 @@ def mock_get_source_ip() -> Generator[None, None, None]:
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_zeroconf() -> Generator[None, None, None]:
|
def mock_zeroconf() -> Generator[None, None, None]:
|
||||||
"""Mock zeroconf."""
|
"""Mock zeroconf."""
|
||||||
|
from zeroconf import DNSCache # pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.zeroconf.HaZeroconf", autospec=True
|
"homeassistant.components.zeroconf.HaZeroconf", autospec=True
|
||||||
) as mock_zc, patch(
|
) as mock_zc, patch(
|
||||||
"homeassistant.components.zeroconf.HaAsyncServiceBrowser", autospec=True
|
"homeassistant.components.zeroconf.HaAsyncServiceBrowser", autospec=True
|
||||||
):
|
):
|
||||||
|
zc = mock_zc.return_value
|
||||||
|
# DNSCache has strong Cython type checks, and MagicMock does not work
|
||||||
|
# so we must mock the class directly
|
||||||
|
zc.cache = DNSCache()
|
||||||
yield mock_zc
|
yield mock_zc
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_async_zeroconf(mock_zeroconf: None) -> Generator[None, None, None]:
|
def mock_async_zeroconf(mock_zeroconf: None) -> Generator[None, None, None]:
|
||||||
"""Mock AsyncZeroconf."""
|
"""Mock AsyncZeroconf."""
|
||||||
|
from zeroconf import DNSCache # pylint: disable=import-outside-toplevel
|
||||||
|
|
||||||
with patch("homeassistant.components.zeroconf.HaAsyncZeroconf") as mock_aiozc:
|
with patch("homeassistant.components.zeroconf.HaAsyncZeroconf") as mock_aiozc:
|
||||||
zc = mock_aiozc.return_value
|
zc = mock_aiozc.return_value
|
||||||
zc.async_unregister_service = AsyncMock()
|
zc.async_unregister_service = AsyncMock()
|
||||||
zc.async_register_service = AsyncMock()
|
zc.async_register_service = AsyncMock()
|
||||||
zc.async_update_service = AsyncMock()
|
zc.async_update_service = AsyncMock()
|
||||||
zc.zeroconf.async_wait_for_start = AsyncMock()
|
zc.zeroconf.async_wait_for_start = AsyncMock()
|
||||||
|
# DNSCache has strong Cython type checks, and MagicMock does not work
|
||||||
|
# so we must mock the class directly
|
||||||
|
zc.zeroconf.cache = DNSCache()
|
||||||
zc.zeroconf.done = False
|
zc.zeroconf.done = False
|
||||||
zc.async_close = AsyncMock()
|
zc.async_close = AsyncMock()
|
||||||
zc.ha_async_close = AsyncMock()
|
zc.ha_async_close = AsyncMock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user