Bump androidtv to 0.0.28 (#26906)
* Bump androidtv to 0.0.28 * Address reviewer comments * Remove adb-shell from requirements_test_all.txt * Use a one-liner to avoid a coverage failure
This commit is contained in:
1 parent
b04a70995e
commit
45c548ae47
6 files changed
+61
-52
No files matched your search
@@ -4,34 +4,24 @@ from socket import error as socket_error
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
class AdbCommandsFake:
|
||||
"""A fake of the `adb.adb_commands.AdbCommands` class."""
|
||||
class AdbDeviceFake:
|
||||
"""A fake of the `adb_shell.adb_device.AdbDevice` class."""
|
||||
|
||||
def ConnectDevice(self, *args, **kwargs): # pylint: disable=invalid-name
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize a fake `adb_shell.adb_device.AdbDevice` instance."""
|
||||
self.available = False
|
||||
|
||||
def close(self):
|
||||
"""Close the socket connection."""
|
||||
self.available = False
|
||||
|
||||
def connect(self, *args, **kwargs):
|
||||
"""Try to connect to a device."""
|
||||
raise NotImplementedError
|
||||
|
||||
def Shell(self, cmd): # pylint: disable=invalid-name
|
||||
def shell(self, cmd):
|
||||
"""Send an ADB shell command."""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class AdbCommandsFakeSuccess(AdbCommandsFake):
|
||||
"""A fake of the `adb.adb_commands.AdbCommands` class when the connection attempt succeeds."""
|
||||
|
||||
def ConnectDevice(self, *args, **kwargs): # pylint: disable=invalid-name
|
||||
"""Successfully connect to a device."""
|
||||
return self
|
||||
|
||||
|
||||
class AdbCommandsFakeFail(AdbCommandsFake):
|
||||
"""A fake of the `adb.adb_commands.AdbCommands` class when the connection attempt fails."""
|
||||
|
||||
def ConnectDevice(
|
||||
self, *args, **kwargs
|
||||
): # pylint: disable=invalid-name, no-self-use
|
||||
"""Fail to connect to a device."""
|
||||
raise socket_error
|
||||
return None
|
||||
|
||||
|
||||
class ClientFakeSuccess:
|
||||
@@ -85,31 +75,39 @@ class DeviceFake:
|
||||
|
||||
|
||||
def patch_connect(success):
|
||||
"""Mock the `adb.adb_commands.AdbCommands` and `adb_messenger.client.Client` classes."""
|
||||
"""Mock the `adb_shell.adb_device.AdbDevice` and `adb_messenger.client.Client` classes."""
|
||||
|
||||
def connect_success_python(self, *args, **kwargs):
|
||||
"""Mock the `AdbDeviceFake.connect` method when it succeeds."""
|
||||
self.available = True
|
||||
|
||||
def connect_fail_python(self, *args, **kwargs):
|
||||
"""Mock the `AdbDeviceFake.connect` method when it fails."""
|
||||
raise socket_error
|
||||
|
||||
if success:
|
||||
return {
|
||||
"python": patch(
|
||||
"androidtv.adb_manager.AdbCommands", AdbCommandsFakeSuccess
|
||||
f"{__name__}.AdbDeviceFake.connect", connect_success_python
|
||||
),
|
||||
"server": patch("androidtv.adb_manager.Client", ClientFakeSuccess),
|
||||
}
|
||||
return {
|
||||
"python": patch("androidtv.adb_manager.AdbCommands", AdbCommandsFakeFail),
|
||||
"python": patch(f"{__name__}.AdbDeviceFake.connect", connect_fail_python),
|
||||
"server": patch("androidtv.adb_manager.Client", ClientFakeFail),
|
||||
}
|
||||
|
||||
|
||||
def patch_shell(response=None, error=False):
|
||||
"""Mock the `AdbCommandsFake.Shell` and `DeviceFake.shell` methods."""
|
||||
"""Mock the `AdbDeviceFake.shell` and `DeviceFake.shell` methods."""
|
||||
|
||||
def shell_success(self, cmd):
|
||||
"""Mock the `AdbCommandsFake.Shell` and `DeviceFake.shell` methods when they are successful."""
|
||||
"""Mock the `AdbDeviceFake.shell` and `DeviceFake.shell` methods when they are successful."""
|
||||
self.shell_cmd = cmd
|
||||
return response
|
||||
|
||||
def shell_fail_python(self, cmd):
|
||||
"""Mock the `AdbCommandsFake.Shell` method when it fails."""
|
||||
"""Mock the `AdbDeviceFake.shell` method when it fails."""
|
||||
self.shell_cmd = cmd
|
||||
raise AttributeError
|
||||
|
||||
@@ -120,10 +118,13 @@ def patch_shell(response=None, error=False):
|
||||
|
||||
if not error:
|
||||
return {
|
||||
"python": patch(f"{__name__}.AdbCommandsFake.Shell", shell_success),
|
||||
"python": patch(f"{__name__}.AdbDeviceFake.shell", shell_success),
|
||||
"server": patch(f"{__name__}.DeviceFake.shell", shell_success),
|
||||
}
|
||||
return {
|
||||
"python": patch(f"{__name__}.AdbCommandsFake.Shell", shell_fail_python),
|
||||
"python": patch(f"{__name__}.AdbDeviceFake.shell", shell_fail_python),
|
||||
"server": patch(f"{__name__}.DeviceFake.shell", shell_fail_server),
|
||||
}
|
||||
|
||||
|
||||
PATCH_ADB_DEVICE = patch("androidtv.adb_manager.AdbDevice", AdbDeviceFake)
|
||||
@@ -79,7 +79,9 @@ async def _test_reconnect(hass, caplog, config):
|
||||
else:
|
||||
entity_id = "media_player.fire_tv"
|
||||
|
||||
with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
|
||||
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[
|
||||
patch_key
|
||||
], patchers.patch_shell("")[patch_key]:
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.helpers.entity_component.async_update_entity(entity_id)
|
||||
state = hass.states.get(entity_id)
|
||||
@@ -151,7 +153,9 @@ async def _test_adb_shell_returns_none(hass, config):
|
||||
else:
|
||||
entity_id = "media_player.fire_tv"
|
||||
|
||||
with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
|
||||
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[
|
||||
patch_key
|
||||
], patchers.patch_shell("")[patch_key]:
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.helpers.entity_component.async_update_entity(entity_id)
|
||||
state = hass.states.get(entity_id)
|
||||
|
||||
Reference in new issue
Block a user