Review AndroidTV tests for media player entity (#71168)

This commit is contained in:
ollo69 2022-05-03 00:18:38 +02:00 committed by GitHub
parent 188040b8bb
commit ea456893f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 372 additions and 468 deletions

View File

@ -58,7 +58,6 @@ omit =
homeassistant/components/amcrest/*
homeassistant/components/ampio/*
homeassistant/components/android_ip_webcam/*
homeassistant/components/androidtv/__init__.py
homeassistant/components/androidtv/diagnostics.py
homeassistant/components/anel_pwrctrl/switch.py
homeassistant/components/anthemav/media_player.py

View File

@ -1,8 +1,15 @@
"""Define patches used for androidtv tests."""
from unittest.mock import mock_open, patch
from unittest.mock import patch
from androidtv.constants import CMD_DEVICE_PROPERTIES, CMD_MAC_ETH0, CMD_MAC_WLAN0
from homeassistant.components.androidtv.const import (
DEFAULT_ADB_SERVER_PORT,
DEVICE_ANDROIDTV,
DEVICE_FIRETV,
)
ADB_SERVER_HOST = "127.0.0.1"
KEY_PYTHON = "python"
KEY_SERVER = "server"
@ -36,7 +43,7 @@ class AdbDeviceTcpAsyncFake:
class ClientAsyncFakeSuccess:
"""A fake of the `ClientAsync` class when the connection and shell commands succeed."""
def __init__(self, host="127.0.0.1", port=5037):
def __init__(self, host=ADB_SERVER_HOST, port=DEFAULT_ADB_SERVER_PORT):
"""Initialize a `ClientAsyncFakeSuccess` instance."""
self._devices = []
@ -50,7 +57,7 @@ class ClientAsyncFakeSuccess:
class ClientAsyncFakeFail:
"""A fake of the `ClientAsync` class when the connection and shell commands fail."""
def __init__(self, host="127.0.0.1", port=5037):
def __init__(self, host=ADB_SERVER_HOST, port=DEFAULT_ADB_SERVER_PORT):
"""Initialize a `ClientAsyncFakeFail` instance."""
self._devices = []
@ -143,37 +150,18 @@ def patch_shell(response=None, error=False, mac_eth=False):
}
PATCH_ADB_DEVICE_TCP = patch(
"androidtv.adb_manager.adb_manager_async.AdbDeviceTcpAsync", AdbDeviceTcpAsyncFake
)
PATCH_ANDROIDTV_OPEN = patch(
"homeassistant.components.androidtv.media_player.open", mock_open()
)
PATCH_KEYGEN = patch("homeassistant.components.androidtv.keygen")
PATCH_SIGNER = patch(
"homeassistant.components.androidtv.ADBPythonSync.load_adbkey",
return_value="signer for testing",
)
def isfile(filepath):
"""Mock `os.path.isfile`."""
return filepath.endswith("adbkey")
def patch_firetv_update(state, current_app, running_apps, hdmi_input):
"""Patch the `FireTV.update()` method."""
return patch(
"androidtv.firetv.firetv_async.FireTVAsync.update",
return_value=(state, current_app, running_apps, hdmi_input),
)
def patch_androidtv_update(
state, current_app, running_apps, device, is_volume_muted, volume_level, hdmi_input
state,
current_app,
running_apps,
device,
is_volume_muted,
volume_level,
hdmi_input,
):
"""Patch the `AndroidTV.update()` method."""
return patch(
return {
DEVICE_ANDROIDTV: patch(
"androidtv.androidtv.androidtv_async.AndroidTVAsync.update",
return_value=(
state,
@ -184,9 +172,25 @@ def patch_androidtv_update(
volume_level,
hdmi_input,
),
),
DEVICE_FIRETV: patch(
"androidtv.firetv.firetv_async.FireTVAsync.update",
return_value=(state, current_app, running_apps, hdmi_input),
),
}
def isfile(filepath):
"""Mock `os.path.isfile`."""
return filepath.endswith("adbkey")
PATCH_SETUP_ENTRY = patch(
"homeassistant.components.androidtv.async_setup_entry",
return_value=True,
)
PATCH_ACCESS = patch("homeassistant.components.androidtv.os.access", return_value=True)
PATCH_ISFILE = patch("homeassistant.components.androidtv.os.path.isfile", isfile)
PATCH_LAUNCH_APP = patch("androidtv.basetv.basetv_async.BaseTVAsync.launch_app")
PATCH_STOP_APP = patch("androidtv.basetv.basetv_async.BaseTVAsync.stop_app")

View File

@ -36,7 +36,7 @@ from homeassistant.components.androidtv.const import (
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_DEVICE_CLASS, CONF_HOST, CONF_PORT
from .patchers import isfile
from .patchers import PATCH_ACCESS, PATCH_ISFILE, PATCH_SETUP_ENTRY
from tests.common import MockConfigEntry
@ -66,16 +66,6 @@ CONFIG_ADB_SERVER = {
CONNECT_METHOD = (
"homeassistant.components.androidtv.config_flow.async_connect_androidtv"
)
PATCH_ACCESS = patch(
"homeassistant.components.androidtv.config_flow.os.access", return_value=True
)
PATCH_ISFILE = patch(
"homeassistant.components.androidtv.config_flow.os.path.isfile", isfile
)
PATCH_SETUP_ENTRY = patch(
"homeassistant.components.androidtv.async_setup_entry",
return_value=True,
)
class MockConfigDevice:

File diff suppressed because it is too large Load Diff