예제 #1
0
    def test_stop_started_server(self):
        server = AutomatorServer()
        server.adb = MagicMock()
        server.uiautomator_process = process = MagicMock()
        process.poll.return_value = None
        server.stop()
        process.wait.assert_called_once_with()

        server.uiautomator_process = process = MagicMock()
        process.poll.return_value = None
        self.urlopen.side_effect = IOError("error")
        server.stop()
        process.kill.assert_called_once_with()
예제 #2
0
    def test_stop_started_server(self):
        server = AutomatorServer()
        server.adb = MagicMock()
        server.uiautomator_process = process = MagicMock()
        process.poll.return_value = None
        server.stop()
        process.wait.assert_called_once_with()

        server.uiautomator_process = process = MagicMock()
        process.poll.return_value = None
        self.urlopen.side_effect = IOError("error")
        server.stop()
        process.kill.assert_called_once_with()
예제 #3
0
 def test_stop(self):
     results = [
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\n\rsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator",
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\r\nsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator",
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\nsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator",
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\rsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator"
     ]
     for r in results:
         server = AutomatorServer()
         server.adb = MagicMock()
         server.adb.cmd.return_value.communicate.return_value = (r, "")
         server.stop()
         self.assertEqual(server.adb.cmd.call_args_list,
                          [call("shell", "ps", "-C", "uiautomator"), call("shell", "kill", "-9", "372")])
예제 #4
0
 def test_stop(self):
     results = [
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\n\rsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator",
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\r\nsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator",
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\nsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator",
         b"USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME\rsystem    372   126   635596 104808 ffffffff 00000000 S uiautomator"
     ]
     for r in results:
         server = AutomatorServer()
         server.adb = MagicMock()
         server.adb.cmd.return_value.communicate.return_value = (r, "")
         server.stop()
         self.assertEqual(server.adb.cmd.call_args_list,
                          [call("shell", "ps", "-C", "uiautomator"), call("shell", "kill", "-9", "372")])
예제 #5
0
    def test_auto_start(self):
        try:
            import requests
            # import urllib2
        except ImportError:
            raise
            # import urllib.request as urllib2
        with patch("uiautomator.JsonRPCMethod") as JsonRPCMethod:
            # returns = [urllib2.URLError("error"), "ok"]
            returns = [requests.exceptions.ConnectionError("error"), "ok"]

            def side_effect():
                result = returns.pop(0)
                if isinstance(result, Exception):
                    raise result
                return result

            JsonRPCMethod.return_value.side_effect = side_effect
            server = AutomatorServer()
            server.start = MagicMock()
            server.stop = MagicMock()
            self.assertEqual("ok", server.jsonrpc.any_method())
            server.start.assert_called_once_with(timeout=30)
        with patch("uiautomator.JsonRPCMethod") as JsonRPCMethod:
            returns = [JsonRPCError(-32000 - 1, "error msg"), "ok"]

            def side_effect():
                result = returns.pop(0)
                if isinstance(result, Exception):
                    raise result
                return result

            JsonRPCMethod.return_value.side_effect = side_effect
            server = AutomatorServer()
            server.start = MagicMock()
            server.stop = MagicMock()
            self.assertEqual("ok", server.jsonrpc.any_method())
            server.start.assert_called_once_with()
        with patch("uiautomator.JsonRPCMethod") as JsonRPCMethod:
            JsonRPCMethod.return_value.side_effect = JsonRPCError(
                -32000 - 2, "error msg")
            server = AutomatorServer()
            server.start = MagicMock()
            server.stop = MagicMock()
            with self.assertRaises(JsonRPCError):
                server.jsonrpc.any_method()
예제 #6
0
 def test_auto_start(self):
     with patch("uiautomator.JsonRPCClient") as JsonRPCClient:
         JsonRPCClient.ping.return_value = None
         server = AutomatorServer()
         server.start = MagicMock()
         server.stop = MagicMock()
         server.jsonrpc
         server.start.assert_called_once_with()
예제 #7
0
 def test_auto_start(self):
     with patch("uiautomator.JsonRPCClient") as JsonRPCClient:
         JsonRPCClient.ping.return_value = None
         server = AutomatorServer()
         server.start = MagicMock()
         server.stop = MagicMock()
         server.jsonrpc
         server.start.assert_called_once_with()
예제 #8
0
 def test_auto_start(self):
     try:
         import requests
     except ImportError:
         raise
     with patch("uiautomator.JsonRPCMethod") as JsonRPCMethod:
         # returns = [urllib2.URLError("error"), "ok"]
         returns = [requests.exceptions.ConnectionError("error"), "ok"]
         
         def side_effect():
             result = returns.pop(0)
             if isinstance(result, Exception):
                 raise result
             return result
         JsonRPCMethod.return_value.side_effect = side_effect
         server = AutomatorServer()
         server.start = MagicMock()
         server.stop = MagicMock()
         self.assertEqual("ok", server.jsonrpc.any_method())
         server.start.assert_called_once_with(timeout=30)
     with patch("uiautomator.JsonRPCMethod") as JsonRPCMethod:
         returns = [requests.exceptions.ConnectionError("error"), "ok"]
         # returns = [JsonRPCError(-32000-1, "error msg"), "ok"]
         
         def side_effect():
             result = returns.pop(0)
             if isinstance(result, Exception):
                 raise result
             return result
         JsonRPCMethod.return_value.side_effect = side_effect
         server = AutomatorServer()
         server.start = MagicMock()
         server.stop = MagicMock()
         self.assertEqual("ok", server.jsonrpc.any_method())
         server.start.assert_called_once_with(timeout=30)
     with patch("uiautomator.JsonRPCMethod") as JsonRPCMethod:
         JsonRPCMethod.return_value.side_effect = JsonRPCError(-32000-2, "error msg")
         server = AutomatorServer()
         server.start = MagicMock()
         server.stop = MagicMock()
         with self.assertRaises(JsonRPCError):
             server.jsonrpc.any_method()
예제 #9
0
"""start and quit rpc server on device.
"""
from uiautomator import AutomatorServer

r = AutomatorServer()
print "RPC server is going to stop ..."
r.stop()

if not r.alive:
    print "Sever is stopped."
else:
    print "Somthing wrong"