def test_plugin_with_exception_callback(self): plugin = Plugin(exceptions=0) @plugin.on_after_processed() async def _(message, env): if env.exception: plugin.exceptions += 1 @plugin.on_has_text() async def _(message, env): raise Exception app = Kutana() app.register_plugins([plugin]) loop = asyncio.get_event_loop() set_logger_level(logging.CRITICAL) loop.run_until_complete(app.process(DebugManager(), "message")) set_logger_level(logging.ERROR) self.assertEqual(plugin.exceptions, 1)
def test_exception(self): self.called = 0 self.target = [ "Произошла крайне критическая ошибка. " "Сообщите об этом администратору." ] with self.debug_manager(["message"]): async def new_update(update, env): async def just_raise(update, env): self.called += 1 raise Exception env.register_after_processed(just_raise) raise Exception self.app.register(new_update) set_logger_level(logging.CRITICAL) set_logger_level(logging.ERROR) self.assertEqual(self.called, 1)
async def test(): mngr.session = FakeSession() set_logger_level(logging.CRITICAL) response = await mngr.raw_request("any.method", a1="v1", a2="v2") set_logger_level(logging.ERROR) self.assertEqual(response.errors[0][1]["error_code"], 5)
def test_no_default_exception_handle(self): self.target = [] with self.debug_manager(["message"]): async def new_update(update, env): raise Exception self.app.register(new_update) set_logger_level(logging.CRITICAL) set_logger_level(logging.ERROR)