Skip to content

Commit

Permalink
Bump adb-shell requirement to >=0.1.0 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Dec 10, 2019
1 parent 2b7229e commit dce38af
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions androidtv/adb_manager.py
Expand Up @@ -10,7 +10,7 @@
import sys
import threading

from adb_shell.adb_device import AdbDevice
from adb_shell.adb_device import AdbDeviceTcp
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
from ppadb.client import Client

Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(self, host, port, adbkey=''):
self.host = host
self.port = int(port)
self.adbkey = adbkey
self._adb = AdbDevice(serial='{}:{}'.format(self.host, self.port), default_timeout_s=9.)
self._adb = AdbDeviceTcp(host=self.host, port=self.port, default_timeout_s=9.)

# keep track of whether the ADB connection is intact
self._available = False
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -9,7 +9,7 @@
author='Jeff Irion',
author_email='jefflirion@users.noreply.github.com',
packages=['androidtv'],
install_requires=['adb-shell>=0.0.9', 'pure-python-adb>=0.2.2.dev0'],
install_requires=['adb-shell>=0.1.0', 'pure-python-adb>=0.2.2.dev0'],
classifiers=[
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
Expand Down
34 changes: 17 additions & 17 deletions tests/patchers.py
Expand Up @@ -8,11 +8,11 @@
from mock import patch


class AdbDeviceFake(object):
"""A fake of the `adb_shell.adb_device.AdbDevice` class."""
class AdbDeviceTcpFake(object):
"""A fake of the `adb_shell.adb_device.AdbDeviceTcp` class."""

def __init__(self, *args, **kwargs):
"""Initialize a fake `adb_shell.adb_device.AdbDevice` instance."""
"""Initialize a fake `adb_shell.adb_device.AdbDeviceTcp` instance."""
self.available = False

def close(self):
Expand Down Expand Up @@ -91,31 +91,31 @@ def shell(self, cmd):


def patch_connect(success):
"""Mock the `adb_shell.adb_device.AdbDevice` and `ppadb.client.Client` classes."""
"""Mock the `adb_shell.adb_device.AdbDeviceTcp` and `ppadb.client.Client` classes."""

def connect_success_python(self, *args, **kwargs):
"""Mock the `AdbDeviceFake.connect` method when it succeeds."""
"""Mock the `AdbDeviceTcpFake.connect` method when it succeeds."""
self.available = True

def connect_fail_python(self, *args, **kwargs):
"""Mock the `AdbDeviceFake.connect` method when it fails."""
"""Mock the `AdbDeviceTcpFake.connect` method when it fails."""
raise OSError

if success:
return {"python": patch("{}.AdbDeviceFake.connect".format(__name__), connect_success_python), "server": patch("androidtv.adb_manager.Client", ClientFakeSuccess)}
return {"python": patch("{}.AdbDeviceFake.connect".format(__name__), connect_fail_python), "server": patch("androidtv.adb_manager.Client", ClientFakeFail)}
return {"python": patch("{}.AdbDeviceTcpFake.connect".format(__name__), connect_success_python), "server": patch("androidtv.adb_manager.Client", ClientFakeSuccess)}
return {"python": patch("{}.AdbDeviceTcpFake.connect".format(__name__), connect_fail_python), "server": patch("androidtv.adb_manager.Client", ClientFakeFail)}


def patch_shell(response=None, error=False):
"""Mock the `AdbDeviceFake.shell` and `DeviceFake.shell` methods."""
"""Mock the `AdbDeviceTcpFake.shell` and `DeviceFake.shell` methods."""

def shell_success(self, cmd):
"""Mock the `AdbDeviceFake.shell` and `DeviceFake.shell` methods when they are successful."""
"""Mock the `AdbDeviceTcpFake.shell` and `DeviceFake.shell` methods when they are successful."""
self.shell_cmd = cmd
return response

def shell_fail_python(self, cmd):
"""Mock the `AdbDeviceFake.shell` method when it fails."""
"""Mock the `AdbDeviceTcpFake.shell` method when it fails."""
self.shell_cmd = cmd
raise AttributeError

Expand All @@ -125,19 +125,19 @@ def shell_fail_server(self, cmd):
raise ConnectionResetError

if not error:
return {"python": patch("{}.AdbDeviceFake.shell".format(__name__), shell_success), "server": patch("{}.DeviceFake.shell".format(__name__), shell_success)}
return {"python": patch("{}.AdbDeviceFake.shell".format(__name__), shell_fail_python), "server": patch("{}.DeviceFake.shell".format(__name__), shell_fail_server)}
return {"python": patch("{}.AdbDeviceTcpFake.shell".format(__name__), shell_success), "server": patch("{}.DeviceFake.shell".format(__name__), shell_success)}
return {"python": patch("{}.AdbDeviceTcpFake.shell".format(__name__), shell_fail_python), "server": patch("{}.DeviceFake.shell".format(__name__), shell_fail_server)}


PATCH_PUSH = {"python": patch("{}.AdbDeviceFake.push".format(__name__)), "server": patch("{}.DeviceFake.push".format(__name__))}
PATCH_PUSH = {"python": patch("{}.AdbDeviceTcpFake.push".format(__name__)), "server": patch("{}.DeviceFake.push".format(__name__))}

PATCH_PULL = {"python": patch("{}.AdbDeviceFake.pull".format(__name__)), "server": patch("{}.DeviceFake.pull".format(__name__))}
PATCH_PULL = {"python": patch("{}.AdbDeviceTcpFake.pull".format(__name__)), "server": patch("{}.DeviceFake.pull".format(__name__))}

PATCH_ADB_DEVICE = patch("androidtv.adb_manager.AdbDevice", AdbDeviceFake)
PATCH_ADB_DEVICE_TCP = patch("androidtv.adb_manager.AdbDeviceTcp", AdbDeviceTcpFake)


class CustomException(Exception):
"""A custom exception type."""


PATCH_CONNECT_FAIL_CUSTOM_EXCEPTION = {"python": patch("{}.AdbDeviceFake.connect".format(__name__), side_effect=CustomException), "server": patch("{}.ClientFakeSuccess.devices".format(__name__), side_effect=CustomException)}
PATCH_CONNECT_FAIL_CUSTOM_EXCEPTION = {"python": patch("{}.AdbDeviceTcpFake.connect".format(__name__), side_effect=CustomException), "server": patch("{}.ClientFakeSuccess.devices".format(__name__), side_effect=CustomException)}
6 changes: 3 additions & 3 deletions tests/test_adb_manager.py
Expand Up @@ -68,7 +68,7 @@ def setUp(self):
"""Create an `ADBPython` instance.
"""
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY]:
self.adb = ADBPython('HOST', 5555)

def test_connect_success(self):
Expand Down Expand Up @@ -251,7 +251,7 @@ def setUp(self):
"""Create an `ADBPython` instance.
"""
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY]:
self.adb = ADBPython('HOST', 5555, 'adbkey')

def test_connect_success_with_priv_key(self):
Expand Down Expand Up @@ -281,7 +281,7 @@ class TestADBPythonClose(unittest.TestCase):
def test_close(self):
"""Test the `ADBPython.close` method.
"""
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY]:
self.adb = ADBPython('HOST', 5555)

with patchers.patch_connect(True)[self.PATCH_KEY]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_androidtv.py
Expand Up @@ -535,7 +535,7 @@ class TestAndroidTVPython(unittest.TestCase):
ADB_ATTR = '_adb'

def setUp(self):
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
self.atv = AndroidTV('HOST', 5555)

def test_turn_on_off(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basetv.py
Expand Up @@ -80,7 +80,7 @@ class TestBaseTVPython(unittest.TestCase):
ADB_ATTR = '_adb'

def setUp(self):
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
self.btv = BaseTV('HOST', 5555)

def test_available(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_firetv.py
Expand Up @@ -133,7 +133,7 @@ class TestFireTVPython(unittest.TestCase):
PATCH_KEY = 'python'

def setUp(self):
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
self.ftv = FireTV('HOST', 5555)

def test_turn_on_off(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_homeassistant.py
Expand Up @@ -241,7 +241,7 @@ class TestAndroidTVPythonImplementation(unittest.TestCase):

def setUp(self):
"""Set up an `AndroidTVDevice` media player."""
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
aftv = setup("HOST", 5555, device_class="androidtv")
self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, None, None)

Expand Down Expand Up @@ -372,7 +372,7 @@ class TestFireTVPythonImplementation(TestAndroidTVPythonImplementation):

def setUp(self):
"""Set up a `FireTVDevice` media player."""
with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell("")[self.PATCH_KEY]:
aftv = setup("HOST", 5555, device_class="firetv")
self.aftv = FireTVDevice(aftv, "Fake Fire TV", {}, True, None, None)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_setup.py
Expand Up @@ -45,22 +45,22 @@ def test_setup(self):
with self.assertRaises(ValueError):
setup('HOST', 5555, device_class='INVALID')

with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555)
self.assertIsInstance(ftv, FireTV)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)

with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
atv = setup('HOST', 5555)
self.assertIsInstance(atv, AndroidTV)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)

with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
ftv = setup('HOST', 5555, device_class='androidtv')
self.assertIsInstance(ftv, AndroidTV)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)

with patchers.PATCH_ADB_DEVICE, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(DEVICE_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
atv = setup('HOST', 5555, device_class='firetv')
self.assertIsInstance(atv, FireTV)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
Expand Down

0 comments on commit dce38af

Please sign in to comment.