How to use test_normal_call_error method in uiautomator

Best Python code snippet using uiautomator

test_jsonrpc.py

Source:test_jsonrpc.py Github

copy

Full Screen

...38 return_mock.read.return_value = b'{"result": "pong", "id": "JDLSFJLILJEMNC"}'39 self.assertEqual("pong", self.method())40 self.assertEqual("pong", self.method(1, 2, "str", {"a": 1}, ["1"]))41 self.assertEqual("pong", self.method(a=1, b=2))42 def test_normal_call_error(self):43 return_mock = self.urlopen.return_value44 return_mock.getcode.return_value = 50045 with self.assertRaises(Exception):46 self.method()47 return_mock.getcode.return_value = 20048 return_mock.read.return_value = b'{"result": "pong", "error": {"code": -513937, "message": "error message."}, "id": "fGasV62G"}'49 with self.assertRaises(Exception):50 self.method()51 return_mock.read.assert_called_with()52 return_mock.getcode.return_value = 20053 return_mock.read.return_value = b'{"result": null, "error": null, "id": "fGasV62G"}'54 with self.assertRaises(SyntaxError):55 self.method(1, 2, kwarg1="")56class TestJsonRPCClient(unittest.TestCase):57 def setUp(self):58 self.url = "http://localhost/jsonrpc"59 self.timeout = 2060 def test_jsonrpc(self):61 with patch('uiautomator.JsonRPCMethod') as JsonRPCMethod:62 client = JsonRPCClient(self.url, self.timeout, JsonRPCMethod)63 JsonRPCMethod.return_value = "Ok"64 self.assertEqual(client.ping, "Ok")65 JsonRPCMethod.assert_called_once_with(self.url, "ping", timeout=self.timeout)66 JsonRPCMethod.return_value = {"width": 10, "height": 20}67 self.assertEqual(client.info, {"width": 10, "height": 20})68 JsonRPCMethod.assert_called_with(self.url, "info", timeout=self.timeout)69class TestJsonRPCMethod_call_on_windows(unittest.TestCase):70 def setUp(self):71 self.os_name = os.name72 os.name = "nt"73 self.url = "http://localhost/jsonrpc"74 self.timeout = 2075 self.method_name = "ping"76 self.id = "fGasV62G"77 self.method = JsonRPCMethod(self.url, self.method_name, self.timeout)78 self.method.pool = MagicMock()79 self.method.id = MagicMock()80 self.method.id.return_value = self.id81 def tearDown(self):82 os.name = self.os_name83 def test_normal_call(self):84 urlopen = self.method.pool.urlopen85 urlopen.return_value.status = 20086 urlopen.return_value.data = b'{"result": "pong", "error": null, "id": "DKNCJDLDJJ"}'87 self.assertEqual("pong", self.method())88 self.method.id.assert_called_once_with()89 urlopen.return_value.data = b'{"result": "pong", "id": "JDLSFJLILJEMNC"}'90 self.assertEqual("pong", self.method())91 self.assertEqual("pong", self.method(1, 2, "str", {"a": 1}, ["1"]))92 self.assertEqual("pong", self.method(a=1, b=2))93 def test_normal_call_error(self):94 urlopen = self.method.pool.urlopen95 urlopen.return_value.status = 50096 with self.assertRaises(Exception):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run uiautomator automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful