def test_should_keep_error_text(self, set_debug_function, Script): Script.side_effect = RuntimeError try: jedibackend.run_with_debug(jedi, 'test_method', 1, 2, arg=3) except rpc.Fault as e: self.assertEqual(str(e), str(RuntimeError())) self.assertEqual(e.message, str(RuntimeError()))
def test_should_handle_source_special(self, set_debug_function, Script): Script.side_effect = RuntimeError try: jedibackend.run_with_debug(jedi, 'test_method', source="foo") except rpc.Fault as e: self.assertEqual(e.data["jedi_debug_info"]["script_args"], "source=source") self.assertEqual(e.data["jedi_debug_info"]["source"], "foo")
def test_should_re_raise(self, Script): Script.side_effect = RuntimeError with self.assertRaises(RuntimeError): jedibackend.run_with_debug(jedi, 'test_method', 1, 2, arg=3, re_raise=(RuntimeError, ))
def test_should_not_fail_with_bad_data(self, Script, set_debug_function): import jedi.debug def set_debug(function, speed=True): if function is not None: function(jedi.debug.NOTICE, u"\xab") set_debug_function.side_effect = set_debug Script.return_value.test_method.side_effect = Exception with self.assertRaises(rpc.Fault): jedibackend.run_with_debug(jedi, 'test_method', {}, 1, 2, arg=3)
def test_should_not_fail_with_bad_data(self, Script, set_debug_function): import jedi.debug def set_debug(function, speed=True): if function is not None: function(jedi.debug.NOTICE, u"\xab") set_debug_function.side_effect = set_debug Script.return_value.test_method.side_effect = Exception with self.assertRaises(rpc.Fault): jedibackend.run_with_debug(jedi, 'test_method', 1, 2, arg=3)
def test_should_keep_debug_info(self, set_debug_function, Script): Script.side_effect = RuntimeError try: jedibackend.run_with_debug(jedi, 'test_method', 1, 2, arg=3) except rpc.Fault as e: self.assertGreaterEqual(e.code, 400) self.assertIsNotNone(e.data) self.assertIn("traceback", e.data) jedi_debug_info = e.data["jedi_debug_info"] self.assertIsNotNone(jedi_debug_info) self.assertEqual(jedi_debug_info["script_args"], "1, 2, arg=3") self.assertEqual(jedi_debug_info["source"], None) self.assertEqual(jedi_debug_info["method"], "test_method") self.assertEqual(jedi_debug_info["debug_info"], [])
def test_should_call_method(self, Script): Script.return_value.test_method.return_value = "test-result" result = jedibackend.run_with_debug(jedi, 'test_method', 1, 2, arg=3) Script.assert_called_with(1, 2, arg=3) self.assertEqual(result, 'test-result')
def test_should_set_debug_info(self, set_debug_function, Script): the_debug_function = [None] def my_set_debug_function(debug_function, **kwargs): the_debug_function[0] = debug_function def my_script(*args, **kwargs): the_debug_function[0](jedi.debug.NOTICE, "Notice") the_debug_function[0](jedi.debug.WARNING, "Warning") the_debug_function[0]("other", "Other") raise RuntimeError set_debug_function.side_effect = my_set_debug_function Script.return_value.test_method = my_script try: jedibackend.run_with_debug(jedi, 'test_method', source="foo") except rpc.Fault as e: self.assertEqual(e.data["jedi_debug_info"]["debug_info"], ["[N] Notice", "[W] Warning", "[?] Other"])
def test_should_re_raise(self, Script): Script.side_effect = RuntimeError with self.assertRaises(RuntimeError): jedibackend.run_with_debug(jedi, 'test_method', 1, 2, arg=3, re_raise=(RuntimeError,))