mirror of
https://github.com/home-assistant/core.git
synced 2025-12-27 22:34:47 +00:00
Improve androidtv mac address handling and test coverage (#65749)
* Better mac addr handling and improve test coverage * Apply suggested changes * Apply more suggested changes
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
"""Define patches used for androidtv tests."""
|
||||
|
||||
from unittest.mock import mock_open, patch
|
||||
|
||||
from androidtv.constants import CMD_DEVICE_PROPERTIES, CMD_MAC_ETH0, CMD_MAC_WLAN0
|
||||
|
||||
KEY_PYTHON = "python"
|
||||
KEY_SERVER = "server"
|
||||
|
||||
ADB_DEVICE_TCP_ASYNC_FAKE = "AdbDeviceTcpAsyncFake"
|
||||
DEVICE_ASYNC_FAKE = "DeviceAsyncFake"
|
||||
|
||||
PROPS_DEV_INFO = "fake\nfake\n0123456\nfake"
|
||||
PROPS_DEV_MAC = "ether ab:cd:ef:gh:ij:kl brd"
|
||||
|
||||
|
||||
class AdbDeviceTcpAsyncFake:
|
||||
"""A fake of the `adb_shell.adb_device_async.AdbDeviceTcpAsync` class."""
|
||||
@@ -100,12 +104,18 @@ def patch_connect(success):
|
||||
}
|
||||
|
||||
|
||||
def patch_shell(response=None, error=False):
|
||||
def patch_shell(response=None, error=False, mac_eth=False):
|
||||
"""Mock the `AdbDeviceTcpAsyncFake.shell` and `DeviceAsyncFake.shell` methods."""
|
||||
|
||||
async def shell_success(self, cmd, *args, **kwargs):
|
||||
"""Mock the `AdbDeviceTcpAsyncFake.shell` and `DeviceAsyncFake.shell` methods when they are successful."""
|
||||
self.shell_cmd = cmd
|
||||
if cmd == CMD_DEVICE_PROPERTIES:
|
||||
return PROPS_DEV_INFO
|
||||
if cmd == CMD_MAC_WLAN0:
|
||||
return PROPS_DEV_MAC
|
||||
if cmd == CMD_MAC_ETH0:
|
||||
return PROPS_DEV_MAC if mac_eth else None
|
||||
return response
|
||||
|
||||
async def shell_fail_python(self, cmd, *args, **kwargs):
|
||||
@@ -185,15 +195,3 @@ PATCH_ANDROIDTV_UPDATE_EXCEPTION = patch(
|
||||
"androidtv.androidtv.androidtv_async.AndroidTVAsync.update",
|
||||
side_effect=ZeroDivisionError,
|
||||
)
|
||||
|
||||
PATCH_DEVICE_PROPERTIES = patch(
|
||||
"androidtv.basetv.basetv_async.BaseTVAsync.get_device_properties",
|
||||
return_value={
|
||||
"manufacturer": "a",
|
||||
"model": "b",
|
||||
"serialno": "c",
|
||||
"sw_version": "d",
|
||||
"wifimac": "ab:cd:ef:gh:ij:kl",
|
||||
"ethmac": None,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user