kopia lustrzana https://github.com/Yakifo/amqtt
map() method now returns a map of result
{plugin1: ret1, plugin2: ret2...} for each plugin calledpull/8/head
rodzic
1dd0da9811
commit
b0007676fb
|
@ -146,12 +146,17 @@ class PluginManager:
|
|||
:return:
|
||||
"""
|
||||
tasks = []
|
||||
plugins_list = []
|
||||
for plugin in self._plugins:
|
||||
coro_instance = coro(plugin, *args, **kwargs)
|
||||
if coro_instance:
|
||||
tasks.append(self._schedule_coro(coro_instance))
|
||||
ret = yield from asyncio.gather(*tasks, loop=self._loop)
|
||||
return ret
|
||||
plugins_list.append(plugin)
|
||||
ret_list = yield from asyncio.gather(*tasks, loop=self._loop)
|
||||
|
||||
# Create result map plugin=>ret
|
||||
ret_dict = {k: v for k, v in zip(plugins_list, ret_list)}
|
||||
return ret_dict
|
||||
|
||||
@staticmethod
|
||||
def _get_coro(plugin, coro_name, *args, **kwargs):
|
||||
|
|
|
@ -30,6 +30,10 @@ class EventTestPlugin:
|
|||
def test_coro(self):
|
||||
self.coro_flag = True
|
||||
|
||||
@asyncio.coroutine
|
||||
def ret_coro(self):
|
||||
return "TEST"
|
||||
|
||||
|
||||
class TestPluginManager(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
@ -71,3 +75,13 @@ class TestPluginManager(unittest.TestCase):
|
|||
self.loop.run_until_complete(call_coro())
|
||||
plugin = manager.get_plugin("event_plugin")
|
||||
self.assertTrue(plugin.object.test_coro)
|
||||
|
||||
def test_map_coro_return(self):
|
||||
@asyncio.coroutine
|
||||
def call_coro():
|
||||
return (yield from manager.map_plugin_coro('ret_coro'))
|
||||
|
||||
manager = PluginManager("hbmqtt.test.plugins", context=None, loop=self.loop)
|
||||
ret = self.loop.run_until_complete(call_coro())
|
||||
plugin = manager.get_plugin("event_plugin")
|
||||
self.assertEqual(ret[plugin], "TEST")
|
||||
|
|
Ładowanie…
Reference in New Issue