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_load_plugins(self): loaded_plugins = load_plugins("test/test_plugins/") loaded_plugins.sort(key=lambda plugin: plugin.name) self.assertEqual(len(loaded_plugins), 3) self.assertEqual(loaded_plugins[0].name, "Memory") self.assertEqual(loaded_plugins[1].name, "My file") self.assertEqual(loaded_plugins[2].name, "My file twice") app = Kutana() app.register_plugins(loaded_plugins) loop = asyncio.get_event_loop() loop.run_until_complete(app.startup()) loop.run_until_complete(app.process(DebugManager(), "message")) self.assertEqual(loaded_plugins[0].memory, "message") self.assertEqual(loaded_plugins[1].my_file, ":)") self.assertEqual(loaded_plugins[2].my_file, ":):)")