Skip to content

Commit

Permalink
Remove the 'check_current' parameter from 'launch_app'
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffLIrion committed Jan 4, 2020
1 parent dcc557e commit 5427521
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 2 additions & 7 deletions androidtv/basetv.py
Expand Up @@ -805,21 +805,16 @@ def _send_intent(self, pkg, intent, count=1):

return {"output": output, "retcode": retcode}

def launch_app(self, app, check_current=True):
def launch_app(self, app):
"""Launch an app.
Parameters
----------
app : str
The ID of the app that will be launched
check_current : bool
Whether to check that the app is not already the current app before launching it
"""
if check_current:
self._adb.shell(constants.CMD_LAUNCH_APP.format(app))
else:
self._send_intent(app, constants.INTENT_LAUNCH)
self._adb.shell(constants.CMD_LAUNCH_APP.format(app))

def stop_app(self, app):
"""Stop an app.
Expand Down
16 changes: 11 additions & 5 deletions tests/test_firetv.py
Expand Up @@ -147,18 +147,24 @@ def test_turn_on_off(self):
self.ftv.turn_off()
self.assertEqual(getattr(self.ftv._adb, self.ADB_ATTR).shell_cmd, constants.CMD_SCREEN_ON + " && input keyevent {0}".format(constants.KEY_SLEEP))

def test_launch_app_stop_app(self):
"""Test that the ``FireTV.launch_app`` and ``FireTV.stop_app`` methods work correctly.
def test_send_intent(self):
"""Test that the ``_send_intent`` method works correctly.
"""
with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('output\r\nretcode')[self.PATCH_KEY]:
self.ftv.launch_app("TEST", check_current=False)
result = self.ftv._send_intent("TEST", constants.INTENT_LAUNCH)
self.assertEqual(getattr(self.ftv._adb, self.ADB_ATTR).shell_cmd, "monkey -p TEST -c android.intent.category.LAUNCHER 1; echo $?")
self.assertDictEqual(result, {'output': 'output', 'retcode': 'retcode'})

with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(None)[self.PATCH_KEY]:
result = self.ftv.launch_app("TEST", check_current=False)
with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(None)[self.PATCH_KEY]:
result = self.ftv._send_intent("TEST", constants.INTENT_LAUNCH)
self.assertEqual(getattr(self.ftv._adb, self.ADB_ATTR).shell_cmd, "monkey -p TEST -c android.intent.category.LAUNCHER 1; echo $?")
self.assertDictEqual(result, {})

def test_launch_app_stop_app(self):
"""Test that the ``FireTV.launch_app`` and ``FireTV.stop_app`` methods work correctly.
"""
with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell(None)[self.PATCH_KEY]:
self.ftv.launch_app("TEST")
self.assertEqual(getattr(self.ftv._adb, self.ADB_ATTR).shell_cmd, constants.CMD_LAUNCH_APP.format("TEST"))
Expand Down

0 comments on commit 5427521

Please sign in to comment.