Fix more tests on Python 3.8 (#34703)

This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-04-25 15:52:50 -07:00
1 parent 5760fb94fe
commit e7f8d6bbf7
7 files changed
+34 -55

No files matched your search

+7 -9
View File
@@ -1,6 +1,5 @@
"""Tests for the Config Entry Flow helper."""
from unittest.mock import Mock, patch
from asynctest import Mock, patch
import pytest
from homeassistant import config_entries, data_entry_flow, setup
@@ -9,7 +8,6 @@ from homeassistant.helpers import config_entry_flow
from tests.common import (
MockConfigEntry,
MockModule,
mock_coro,
mock_entity_platform,
mock_integration,
)
@@ -209,8 +207,8 @@ async def test_webhook_create_cloudhook(hass, webhook_flow_conf):
"""Test only a single entry is allowed."""
assert await setup.async_setup_component(hass, "cloud", {})
async_setup_entry = Mock(return_value=mock_coro(True))
async_unload_entry = Mock(return_value=mock_coro(True))
async_setup_entry = Mock(return_value=True)
async_unload_entry = Mock(return_value=True)
mock_integration(
hass,
@@ -228,10 +226,9 @@ async def test_webhook_create_cloudhook(hass, webhook_flow_conf):
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
coro = mock_coro({"cloudhook_url": "https://example.com"})
with patch(
"hass_nabucasa.cloudhooks.Cloudhooks.async_create", return_value=coro
"hass_nabucasa.cloudhooks.Cloudhooks.async_create",
return_value={"cloudhook_url": "https://example.com"},
) as mock_create, patch(
"homeassistant.components.cloud.async_active_subscription", return_value=True
), patch(
@@ -246,7 +243,8 @@ async def test_webhook_create_cloudhook(hass, webhook_flow_conf):
assert len(async_setup_entry.mock_calls) == 1
with patch(
"hass_nabucasa.cloudhooks.Cloudhooks.async_delete", return_value=coro
"hass_nabucasa.cloudhooks.Cloudhooks.async_delete",
return_value={"cloudhook_url": "https://example.com"},
) as mock_delete:
result = await hass.config_entries.async_remove(result["result"].entry_id)
+11 -19
View File
@@ -2,8 +2,8 @@
from collections import OrderedDict
from copy import deepcopy
import unittest
from unittest.mock import Mock, patch
from asynctest import CoroutineMock, Mock, patch
import pytest
import voluptuous as vol
@@ -30,7 +30,6 @@ from homeassistant.setup import async_setup_component
from tests.common import (
MockEntity,
get_test_home_assistant,
mock_coro,
mock_device_registry,
mock_registry,
mock_service,
@@ -40,10 +39,7 @@ from tests.common import (
@pytest.fixture
def mock_handle_entity_call():
"""Mock service platform call."""
with patch(
"homeassistant.helpers.service._handle_entity_call",
side_effect=lambda *args: mock_coro(),
) as mock_call:
with patch("homeassistant.helpers.service._handle_entity_call") as mock_call:
yield mock_call
@@ -310,7 +306,7 @@ async def test_async_get_all_descriptions(hass):
async def test_call_with_required_features(hass, mock_entities):
"""Test service calls invoked only if entity has required feautres."""
test_service_mock = Mock(return_value=mock_coro())
test_service_mock = CoroutineMock(return_value=None)
await service.entity_service_call(
hass,
[Mock(entities=mock_entities)],
@@ -374,11 +370,9 @@ async def test_call_context_target_all(hass, mock_handle_entity_call, mock_entit
"""Check we only target allowed entities if targeting all."""
with patch(
"homeassistant.auth.AuthManager.async_get_user",
return_value=mock_coro(
Mock(
permissions=PolicyPermissions(
{"entities": {"entity_ids": {"light.kitchen": True}}}, None
)
return_value=Mock(
permissions=PolicyPermissions(
{"entities": {"entity_ids": {"light.kitchen": True}}}, None
)
),
):
@@ -404,11 +398,9 @@ async def test_call_context_target_specific(
"""Check targeting specific entities."""
with patch(
"homeassistant.auth.AuthManager.async_get_user",
return_value=mock_coro(
Mock(
permissions=PolicyPermissions(
{"entities": {"entity_ids": {"light.kitchen": True}}}, None
)
return_value=Mock(
permissions=PolicyPermissions(
{"entities": {"entity_ids": {"light.kitchen": True}}}, None
)
),
):
@@ -435,7 +427,7 @@ async def test_call_context_target_specific_no_auth(
with pytest.raises(exceptions.Unauthorized) as err:
with patch(
"homeassistant.auth.AuthManager.async_get_user",
return_value=mock_coro(Mock(permissions=PolicyPermissions({}, None))),
return_value=Mock(permissions=PolicyPermissions({}, None)),
):
await service.entity_service_call(
hass,
@@ -606,7 +598,7 @@ async def test_domain_control_unknown(hass, mock_entities):
with patch(
"homeassistant.helpers.entity_registry.async_get_registry",
return_value=mock_coro(Mock(entities=mock_entities)),
return_value=Mock(entities=mock_entities),
):
protected_mock_service = hass.helpers.service.verify_domain_control(
"test_domain"
+3 -3
View File
@@ -2,8 +2,8 @@
import asyncio
from datetime import timedelta
import json
from unittest.mock import Mock, patch
from asynctest import Mock, patch
import pytest
from homeassistant.const import (
@@ -14,7 +14,7 @@ from homeassistant.core import CoreState
from homeassistant.helpers import storage
from homeassistant.util import dt
from tests.common import async_fire_time_changed, mock_coro
from tests.common import async_fire_time_changed
MOCK_VERSION = 1
MOCK_KEY = "storage-test"
@@ -189,7 +189,7 @@ async def test_writing_while_writing_delay(hass, store, hass_storage):
async def test_migrator_no_existing_config(hass, store, hass_storage):
"""Test migrator with no existing config."""
with patch("os.path.isfile", return_value=False), patch.object(
store, "async_load", return_value=mock_coro({"cur": "config"})
store, "async_load", return_value={"cur": "config"}
):
data = await storage.async_migrator(hass, "old-path", store)