Fix tests for Python 3.8 (#34672)
This commit is contained in:
1 parent
d53cb951e7
commit
0d700f6a63
40 files changed
+248
-285
No files matched your search
@@ -1,10 +1,7 @@
|
||||
"""Common tradfri test fixtures."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from tests.common import mock_coro
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_gateway_info():
|
||||
@@ -19,5 +16,5 @@ def mock_gateway_info():
|
||||
def mock_entry_setup():
|
||||
"""Mock entry setup."""
|
||||
with patch("homeassistant.components.tradfri.async_setup_entry") as mock_setup:
|
||||
mock_setup.return_value = mock_coro(True)
|
||||
mock_setup.return_value = True
|
||||
yield mock_setup
|
||||
@@ -1,12 +1,11 @@
|
||||
"""Test the Tradfri config flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from asynctest import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.tradfri import config_flow
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -20,9 +19,7 @@ def mock_auth():
|
||||
|
||||
async def test_user_connection_successful(hass, mock_auth, mock_entry_setup):
|
||||
"""Test a successful connection."""
|
||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
||||
{"host": host, "gateway_id": "bla"}
|
||||
)
|
||||
mock_auth.side_effect = lambda hass, host, code: {"host": host, "gateway_id": "bla"}
|
||||
|
||||
flow = await hass.config_entries.flow.async_init(
|
||||
"tradfri", context={"source": "user"}
|
||||
@@ -80,9 +77,7 @@ async def test_user_connection_bad_key(hass, mock_auth, mock_entry_setup):
|
||||
|
||||
async def test_discovery_connection(hass, mock_auth, mock_entry_setup):
|
||||
"""Test a connection via discovery."""
|
||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
||||
{"host": host, "gateway_id": "bla"}
|
||||
)
|
||||
mock_auth.side_effect = lambda hass, host, code: {"host": host, "gateway_id": "bla"}
|
||||
|
||||
flow = await hass.config_entries.flow.async_init(
|
||||
"tradfri", context={"source": "zeroconf"}, data={"host": "123.123.123.123"}
|
||||
@@ -104,9 +99,12 @@ async def test_discovery_connection(hass, mock_auth, mock_entry_setup):
|
||||
|
||||
async def test_import_connection(hass, mock_auth, mock_entry_setup):
|
||||
"""Test a connection via import."""
|
||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
||||
{"host": host, "gateway_id": "bla", "identity": "mock-iden", "key": "mock-key"}
|
||||
)
|
||||
mock_auth.side_effect = lambda hass, host, code: {
|
||||
"host": host,
|
||||
"gateway_id": "bla",
|
||||
"identity": "mock-iden",
|
||||
"key": "mock-key",
|
||||
}
|
||||
|
||||
flow = await hass.config_entries.flow.async_init(
|
||||
"tradfri",
|
||||
@@ -132,9 +130,12 @@ async def test_import_connection(hass, mock_auth, mock_entry_setup):
|
||||
|
||||
async def test_import_connection_no_groups(hass, mock_auth, mock_entry_setup):
|
||||
"""Test a connection via import and no groups allowed."""
|
||||
mock_auth.side_effect = lambda hass, host, code: mock_coro(
|
||||
{"host": host, "gateway_id": "bla", "identity": "mock-iden", "key": "mock-key"}
|
||||
)
|
||||
mock_auth.side_effect = lambda hass, host, code: {
|
||||
"host": host,
|
||||
"gateway_id": "bla",
|
||||
"identity": "mock-iden",
|
||||
"key": "mock-key",
|
||||
}
|
||||
|
||||
flow = await hass.config_entries.flow.async_init(
|
||||
"tradfri",
|
||||
@@ -160,9 +161,12 @@ async def test_import_connection_no_groups(hass, mock_auth, mock_entry_setup):
|
||||
|
||||
async def test_import_connection_legacy(hass, mock_gateway_info, mock_entry_setup):
|
||||
"""Test a connection via import."""
|
||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: mock_coro(
|
||||
{"host": host, "identity": identity, "key": key, "gateway_id": "mock-gateway"}
|
||||
)
|
||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: {
|
||||
"host": host,
|
||||
"identity": identity,
|
||||
"key": key,
|
||||
"gateway_id": "mock-gateway",
|
||||
}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tradfri",
|
||||
@@ -187,9 +191,12 @@ async def test_import_connection_legacy_no_groups(
|
||||
hass, mock_gateway_info, mock_entry_setup
|
||||
):
|
||||
"""Test a connection via legacy import and no groups allowed."""
|
||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: mock_coro(
|
||||
{"host": host, "identity": identity, "key": key, "gateway_id": "mock-gateway"}
|
||||
)
|
||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: {
|
||||
"host": host,
|
||||
"identity": identity,
|
||||
"key": key,
|
||||
"gateway_id": "mock-gateway",
|
||||
}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tradfri",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""Tests for Tradfri setup."""
|
||||
from unittest.mock import patch
|
||||
from asynctest import patch
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry, mock_coro
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_config_yaml_host_not_imported(hass):
|
||||
@@ -51,9 +51,12 @@ async def test_config_json_host_not_imported(hass):
|
||||
|
||||
async def test_config_json_host_imported(hass, mock_gateway_info, mock_entry_setup):
|
||||
"""Test that we import a configured host."""
|
||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: mock_coro(
|
||||
{"host": host, "identity": identity, "key": key, "gateway_id": "mock-gateway"}
|
||||
)
|
||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: {
|
||||
"host": host,
|
||||
"identity": identity,
|
||||
"key": key,
|
||||
"gateway_id": "mock-gateway",
|
||||
}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.tradfri.load_json",
|
||||
|
||||
Reference in new issue
Block a user