Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_setup(self):
"""Test that the ``setup`` function works correctly.
"""
with self.assertRaises(ValueError):
setup('HOST', 5555, device_class='INVALID')
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, FireTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
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, AndroidTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
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, AndroidTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
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, FireTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
def setUp(self):
with patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
self.ftv = FireTVSync('HOST', 5555, adb_server_ip='ADB_SERVER_PORT')
self.ftv.adb_connect()
self.assertIsInstance(ftv, FireTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
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, AndroidTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
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, AndroidTVSync)
self.assertDictEqual(ftv.device_properties, DEVICE_PROPERTIES_DICT1)
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, FireTVSync)
self.assertDictEqual(atv.device_properties, DEVICE_PROPERTIES_DICT2)
def setUp(self):
with patchers.PATCH_ADB_DEVICE_TCP, patchers.patch_connect(True)[self.PATCH_KEY], patchers.patch_shell('')[self.PATCH_KEY]:
self.ftv = FireTVSync('HOST', 5555)
self.ftv.adb_connect()
The signer for the ADB keys, as loaded by :meth:`androidtv.adb_manager.adb_manager_sync.ADBPythonSync.load_adbkey`
Returns
-------
AndroidTVSync, FireTVSync
The representation of the device
"""
if device_class == 'androidtv':
atv = AndroidTVSync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
atv.adb_connect(auth_timeout_s=auth_timeout_s)
atv.device_properties = atv.get_device_properties()
return atv
if device_class == 'firetv':
ftv = FireTVSync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
ftv.adb_connect(auth_timeout_s=auth_timeout_s)
ftv.device_properties = ftv.get_device_properties()
return ftv
if device_class != 'auto':
raise ValueError("`device_class` must be 'androidtv', 'firetv', or 'auto'.")
aftv = BaseTVSync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
# establish the ADB connection
aftv.adb_connect(auth_timeout_s=auth_timeout_s)
# get device properties
aftv.device_properties = aftv.get_device_properties()
# Fire TV
return ftv
if device_class != 'auto':
raise ValueError("`device_class` must be 'androidtv', 'firetv', or 'auto'.")
aftv = BaseTVSync(host, port, adbkey, adb_server_ip, adb_server_port, state_detection_rules, signer)
# establish the ADB connection
aftv.adb_connect(auth_timeout_s=auth_timeout_s)
# get device properties
aftv.device_properties = aftv.get_device_properties()
# Fire TV
if aftv.device_properties.get('manufacturer') == 'Amazon':
aftv.__class__ = FireTVSync
# Android TV
else:
aftv.__class__ = AndroidTVSync
return aftv