def test_download_and_push_download(self, adb): jars = ["bundle.jar", "uiautomator-stub.jar"] with patch("os.path.exists") as exists,\ patch("os.mkdir") as mkdir,\ patch("%s.open" % open.__class__.__module__, mock_open(), create=True) as m_open: server = AutomatorServer() exists.return_value = False self.assertEqual(set(server.download_and_push()), set(jars)) self.assertEqual(len(m_open.call_args_list), len(jars))
def test_download_and_push(self, adb): jars = ["bundle.jar", "uiautomator-stub.jar"] with patch("os.path.exists") as exists: server = AutomatorServer() exists.return_value = True self.assertEqual(set(server.download_and_push()), set(jars)) for args in adb.cmd.call_args_list: self.assertEqual(args[0][0], "push") self.assertEqual(args[0][2], "/data/local/tmp/")
def test_start_success(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = "pong" server.adb = MagicMock() server.start() server.adb.cmd.assert_valled_onec_with('shell', 'uiautomator', 'runtest', 'bundle.jar', 'uiautomator-stub.jar', '-c', 'com.github.uiautomatorstub.Stub')
def test_start_forward_error(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = ["bundle.jar", "uiautomator-stub.jar"] with patch("uiautomator.adb") as adb: adb.forward.return_value = 1 with patch.dict('os.environ', {'LOCAL_PORT': '9000', 'DEVICE_PORT': '9000'}): with self.assertRaises(IOError): server.start() adb.forward.assert_called_once_with(9000, 9000)
def test_start_error(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = None server.adb = MagicMock() with patch("time.sleep"): with self.assertRaises(IOError): server.start()
def test_start_error(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = [ "bundle.jar", "uiautomator-stub.jar" ] server.ping = MagicMock() server.ping.return_value = None server.adb = MagicMock() with patch("time.sleep"): with self.assertRaises(IOError): server.start()
def test_download_and_push(self): jars = ["bundle.jar", "uiautomator-stub.jar"] with patch("os.path.exists") as exists: with patch("os.stat") as stat: server = AutomatorServer() server.adb = MagicMock() exists.return_value = True stat.st_size = 1024 self.assertEqual(set(server.download_and_push()), set(jars)) for args in server.adb.cmd.call_args_list: self.assertEqual(args[0][0], "push") self.assertEqual(args[0][2], "/data/local/tmp/")
def test_start_success(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = ["bundle.jar", "uiautomator-stub.jar"] server.ping = MagicMock() server.ping.return_value = "pong" with patch("uiautomator.adb") as adb: adb.forward.return_value = 0 with patch.dict('os.environ', {'LOCAL_PORT': '9000', 'DEVICE_PORT': '9000'}): server.start() adb.cmd.assert_valled_onec_with('shell', 'uiautomator', 'runtest', 'bundle.jar', 'uiautomator-stub.jar', '-c', 'com.github.uiautomatorstub.Stub') adb.forward.assert_called_once_with(9000, 9000)
def test_start_success(self): server = AutomatorServer() server.download_and_push = MagicMock() server.download_and_push.return_value = [ "bundle.jar", "uiautomator-stub.jar" ] server.ping = MagicMock() server.ping.return_value = "pong" server.adb = MagicMock() server.start() server.adb.cmd.assert_valled_onec_with( 'shell', 'uiautomator', 'runtest', 'bundle.jar', 'uiautomator-stub.jar', '-c', 'com.github.uiautomatorstub.Stub')
def test_download_and_push_download(self): jars = ["bundle.jar", "uiautomator-stub.jar"] with patch("os.path.exists") as exists: with patch("os.mkdir") as mkdir: with patch("%s.open" % open.__class__.__module__, mock_open(), create=True) as m_open: server = AutomatorServer() server.adb = MagicMock() exists.return_value = False self.assertEqual(set(server.download_and_push()), set(jars)) self.assertEqual(len(m_open.call_args_list), len(jars))