mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Use builtin mock (#36473)
This commit is contained in:
parent
874c8fea03
commit
4170eb0f83
@ -1,12 +1,13 @@
|
|||||||
"""Fixtures for tests."""
|
"""Fixtures for tests."""
|
||||||
|
|
||||||
from mock import patch
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .common import ComponentFactory
|
from .common import ComponentFactory
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def component_factory(hass: HomeAssistant):
|
def component_factory(hass: HomeAssistant):
|
||||||
|
@ -4,8 +4,6 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
from mock import Mock, patch
|
|
||||||
|
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
ATTR_MEDIA_CONTENT_ID,
|
ATTR_MEDIA_CONTENT_ID,
|
||||||
DOMAIN as DOMAIN_MP,
|
DOMAIN as DOMAIN_MP,
|
||||||
@ -16,6 +14,7 @@ from homeassistant.config import async_process_ha_core_config
|
|||||||
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
|
from homeassistant.const import HTTP_INTERNAL_SERVER_ERROR
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
|
|
||||||
|
from tests.async_mock import Mock, patch
|
||||||
from tests.common import assert_setup_component, get_test_home_assistant, mock_service
|
from tests.common import assert_setup_component, get_test_home_assistant, mock_service
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import mock
|
|
||||||
from py17track.package import Package
|
from py17track.package import Package
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -14,6 +13,7 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
|||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
from homeassistant.util import utcnow
|
from homeassistant.util import utcnow
|
||||||
|
|
||||||
|
from tests.async_mock import MagicMock, patch
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
|
||||||
VALID_CONFIG_MINIMAL = {
|
VALID_CONFIG_MINIMAL = {
|
||||||
@ -113,7 +113,7 @@ class ProfileMock:
|
|||||||
@pytest.fixture(autouse=True, name="mock_client")
|
@pytest.fixture(autouse=True, name="mock_client")
|
||||||
def fixture_mock_client():
|
def fixture_mock_client():
|
||||||
"""Mock py17track client."""
|
"""Mock py17track client."""
|
||||||
with mock.patch(
|
with patch(
|
||||||
"homeassistant.components.seventeentrack.sensor.SeventeenTrackClient",
|
"homeassistant.components.seventeentrack.sensor.SeventeenTrackClient",
|
||||||
new=ClientMock,
|
new=ClientMock,
|
||||||
):
|
):
|
||||||
@ -137,7 +137,7 @@ async def _goto_future(hass, future=None):
|
|||||||
"""Move to future."""
|
"""Move to future."""
|
||||||
if not future:
|
if not future:
|
||||||
future = utcnow() + datetime.timedelta(minutes=10)
|
future = utcnow() + datetime.timedelta(minutes=10)
|
||||||
with mock.patch("homeassistant.util.utcnow", return_value=future):
|
with patch("homeassistant.util.utcnow", return_value=future):
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ async def test_delivered_not_shown(hass):
|
|||||||
)
|
)
|
||||||
ProfileMock.package_list = [package]
|
ProfileMock.package_list = [package]
|
||||||
|
|
||||||
hass.components.persistent_notification = mock.MagicMock()
|
hass.components.persistent_notification = MagicMock()
|
||||||
await _setup_seventeentrack(hass, VALID_CONFIG_FULL_NO_DELIVERED)
|
await _setup_seventeentrack(hass, VALID_CONFIG_FULL_NO_DELIVERED)
|
||||||
assert not hass.states.async_entity_ids()
|
assert not hass.states.async_entity_ids()
|
||||||
hass.components.persistent_notification.create.assert_called()
|
hass.components.persistent_notification.create.assert_called()
|
||||||
@ -258,7 +258,7 @@ async def test_delivered_shown(hass):
|
|||||||
)
|
)
|
||||||
ProfileMock.package_list = [package]
|
ProfileMock.package_list = [package]
|
||||||
|
|
||||||
hass.components.persistent_notification = mock.MagicMock()
|
hass.components.persistent_notification = MagicMock()
|
||||||
await _setup_seventeentrack(hass, VALID_CONFIG_FULL)
|
await _setup_seventeentrack(hass, VALID_CONFIG_FULL)
|
||||||
|
|
||||||
assert hass.states.get("sensor.seventeentrack_package_456") is not None
|
assert hass.states.get("sensor.seventeentrack_package_456") is not None
|
||||||
@ -283,7 +283,7 @@ async def test_becomes_delivered_not_shown_notification(hass):
|
|||||||
)
|
)
|
||||||
ProfileMock.package_list = [package_delivered]
|
ProfileMock.package_list = [package_delivered]
|
||||||
|
|
||||||
hass.components.persistent_notification = mock.MagicMock()
|
hass.components.persistent_notification = MagicMock()
|
||||||
await _goto_future(hass)
|
await _goto_future(hass)
|
||||||
|
|
||||||
hass.components.persistent_notification.create.assert_called()
|
hass.components.persistent_notification.create.assert_called()
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
from typing import Callable, Dict, NamedTuple, Tuple
|
from typing import Callable, Dict, NamedTuple, Tuple
|
||||||
|
|
||||||
from mock import MagicMock
|
|
||||||
import pyvera as pv
|
import pyvera as pv
|
||||||
|
|
||||||
from homeassistant.components.vera.const import CONF_CONTROLLER, DOMAIN
|
from homeassistant.components.vera.const import CONF_CONTROLLER, DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
|
from tests.async_mock import MagicMock
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
SetupCallback = Callable[[pv.VeraController, dict], None]
|
SetupCallback = Callable[[pv.VeraController, dict], None]
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
"""Fixtures for tests."""
|
"""Fixtures for tests."""
|
||||||
|
|
||||||
from mock import patch
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .common import ComponentFactory
|
from .common import ComponentFactory
|
||||||
|
|
||||||
|
from tests.async_mock import patch
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def vera_component_factory():
|
def vera_component_factory():
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
"""Vera tests."""
|
"""Vera tests."""
|
||||||
from mock import patch
|
|
||||||
from requests.exceptions import RequestException
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
@ -12,7 +11,7 @@ from homeassistant.data_entry_flow import (
|
|||||||
RESULT_TYPE_FORM,
|
RESULT_TYPE_FORM,
|
||||||
)
|
)
|
||||||
|
|
||||||
from tests.async_mock import MagicMock
|
from tests.async_mock import MagicMock, patch
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user