Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions tests/components/google_assistant/test_smart_home.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test Google Smart Home."""
from unittest.mock import Mock, patch

from asynctest import Mock, patch
import pytest

from homeassistant.components import camera
Expand Down Expand Up @@ -29,12 +28,7 @@

from . import BASIC_CONFIG, MockConfig

from tests.common import (
mock_area_registry,
mock_coro,
mock_device_registry,
mock_registry,
)
from tests.common import mock_area_registry, mock_device_registry, mock_registry

REQ_ID = "ff36a3cc-ec34-11e6-b1a0-64510650abcf"

Expand Down Expand Up @@ -262,6 +256,8 @@ async def test_query_message(hass):
},
}

await hass.async_block_till_done()

assert len(events) == 4
assert events[0].event_type == EVENT_QUERY_RECEIVED
assert events[0].data == {
Expand Down Expand Up @@ -788,9 +784,7 @@ async def test_query_disconnect(hass):
config = MockConfig(hass=hass)
config.async_enable_report_state()
assert config._unsub_report_state is not None
with patch.object(
config, "async_disconnect_agent_user", side_effect=mock_coro
) as mock_disconnect:
with patch.object(config, "async_disconnect_agent_user") as mock_disconnect:
result = await sh.async_handle_message(
hass,
config,
Expand All @@ -811,7 +805,7 @@ async def test_trait_execute_adding_query_data(hass):

with patch(
Comment thread
balloob marked this conversation as resolved.
"homeassistant.components.camera.async_request_stream",
return_value=mock_coro("/api/streams/bla"),
return_value="/api/streams/bla",
):
result = await sh.async_handle_message(
hass,
Expand Down
7 changes: 4 additions & 3 deletions tests/components/google_assistant/test_trait.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Tests for the Google Assistant traits."""
import logging
from unittest.mock import Mock, patch
from unittest.mock import Mock

from asynctest import patch
import pytest

from homeassistant.components import (
Expand Down Expand Up @@ -45,7 +46,7 @@

from . import BASIC_CONFIG, MockConfig

from tests.common import async_mock_service, mock_coro
from tests.common import async_mock_service

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -117,7 +118,7 @@ async def test_camera_stream(hass):

with patch(
"homeassistant.components.camera.async_request_stream",
return_value=mock_coro("/api/streams/bla"),
return_value="/api/streams/bla",
):
await trt.execute(trait.COMMAND_GET_CAMERA_STREAM, BASIC_DATA, {}, {})

Expand Down
22 changes: 22 additions & 0 deletions tests/components/ps4/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Test configuration for PS4."""
from asynctest import patch
import pytest


@pytest.fixture
def patch_load_json():
"""Prevent load JSON being used."""
with patch("homeassistant.components.ps4.load_json", return_value={}) as mock_load:
yield mock_load


@pytest.fixture
def patch_save_json():
"""Prevent save JSON being used."""
with patch("homeassistant.components.ps4.save_json") as mock_save:
yield mock_save


@pytest.fixture(autouse=True)
def patch_io(patch_load_json, patch_save_json):
"""Prevent PS4 doing I/O."""
7 changes: 3 additions & 4 deletions tests/components/ps4/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Define tests for the PlayStation 4 config flow."""
from unittest.mock import patch

from asynctest import patch
from pyps4_2ndscreen.errors import CredentialTimeout

from homeassistant import data_entry_flow
Expand All @@ -21,7 +20,7 @@
)
from homeassistant.util import location

from tests.common import MockConfigEntry, mock_coro
from tests.common import MockConfigEntry

MOCK_TITLE = "PlayStation 4"
MOCK_CODE = 12345678
Expand Down Expand Up @@ -313,7 +312,7 @@ async def test_0_pin(hass):
"pyps4_2ndscreen.Helper.has_devices", return_value=[{"host-ip": MOCK_HOST}]
), patch(
"homeassistant.components.ps4.config_flow.location.async_detect_location_info",
return_value=mock_coro(MOCK_LOCATION),
return_value=MOCK_LOCATION,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"], MOCK_AUTO
Expand Down
14 changes: 7 additions & 7 deletions tests/components/ps4/test_init.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests for the PS4 Integration."""
from unittest.mock import MagicMock, patch
from asynctest import MagicMock, patch

from homeassistant import config_entries, data_entry_flow
from homeassistant.components import ps4
Expand Down Expand Up @@ -29,7 +29,7 @@
from homeassistant.setup import async_setup_component
from homeassistant.util import location

from tests.common import MockConfigEntry, mock_coro, mock_registry
from tests.common import MockConfigEntry, mock_registry

MOCK_HOST = "192.168.0.1"
MOCK_NAME = "test_ps4"
Expand Down Expand Up @@ -119,8 +119,8 @@ async def test_creating_entry_sets_up_media_player(hass):
mock_flow = "homeassistant.components.ps4.PlayStation4FlowHandler.async_step_user"
with patch(
"homeassistant.components.ps4.media_player.async_setup_entry",
return_value=mock_coro(True),
) as mock_setup, patch(mock_flow, return_value=mock_coro(MOCK_FLOW_RESULT)):
return_value=True,
) as mock_setup, patch(mock_flow, return_value=MOCK_FLOW_RESULT):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
Expand Down Expand Up @@ -152,10 +152,10 @@ async def test_config_flow_entry_migrate(hass):

with patch(
"homeassistant.util.location.async_detect_location_info",
return_value=mock_coro(MOCK_LOCATION),
return_value=MOCK_LOCATION,
), patch(
"homeassistant.helpers.entity_registry.async_get_registry",
return_value=mock_coro(mock_e_registry),
return_value=mock_e_registry,
):
await ps4.async_migrate_entry(hass, mock_entry)

Expand Down Expand Up @@ -281,7 +281,7 @@ async def test_send_command(hass):
assert mock_entity.entity_id == f"media_player.{MOCK_NAME}"

# Test that all commands call service function.
with patch(mock_func, return_value=mock_coro(True)) as mock_service:
with patch(mock_func, return_value=True) as mock_service:
for mock_command in COMMANDS:
await hass.services.async_call(
DOMAIN,
Expand Down
Loading