示例#1
0
    def test_map_coro(self):
        async def call_coro():
            await manager.map_plugin_coro("test_coro")

        manager = PluginManager("amqtt.test.plugins",
                                context=None,
                                loop=self.loop)
        self.loop.run_until_complete(call_coro())
        plugin = manager.get_plugin("event_plugin")
        assert plugin.object.test_coro
示例#2
0
    def test_map_coro_return(self):
        async def call_coro():
            return await manager.map_plugin_coro("ret_coro")

        manager = PluginManager("amqtt.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")
示例#3
0
    def test_fire_event_wait(self):
        async def fire_event():
            await manager.fire_event("test", wait=True)
            await manager.close()

        manager = PluginManager("amqtt.test.plugins",
                                context=None,
                                loop=self.loop)
        self.loop.run_until_complete(fire_event())
        plugin = manager.get_plugin("event_plugin")
        assert plugin.object.test_flag
示例#4
0
文件: client.py 项目: nfsnfs/amqtt
    def __init__(self, client_id=None, config=None, loop=None):
        self.logger = logging.getLogger(__name__)
        self.config = copy.deepcopy(_defaults)
        if config is not None:
            self.config.update(config)
        if client_id is not None:
            self.client_id = client_id
        else:
            from amqtt.utils import gen_client_id

            self.client_id = gen_client_id()
            self.logger.debug("Using generated client ID : %s" %
                              self.client_id)

        if loop is not None:
            self._loop = loop
        else:
            self._loop = asyncio.get_event_loop()
        self.session = None
        self._handler = None
        self._disconnect_task = None
        self._connected_state = asyncio.Event(loop=self._loop)
        self._no_more_connections = asyncio.Event(loop=self._loop)
        self.extra_headers = {}

        # Init plugins manager
        context = ClientContext()
        context.config = self.config
        self.plugins_manager = PluginManager("amqtt.client.plugins",
                                             context,
                                             loop=self._loop)
        self.client_tasks = deque()
示例#5
0
    def test_map_coro_filter(self):
        """
        Run plugin coro but expect no return as an empty filter is given
        :return:
        """
        async def call_coro():
            return await manager.map_plugin_coro("ret_coro", filter_plugins=[])

        manager = PluginManager("amqtt.test.plugins",
                                context=None,
                                loop=self.loop)
        ret = self.loop.run_until_complete(call_coro())
        assert len(ret) == 0
示例#6
0
 def test_load_plugin_transition(self):
     # entry points have been renamed from hbmqtt. to amqtt.
     # For now the plugin manager automatically rewrites
     # hbmqtt.test.plugins -> amqtt.test.plugins
     manager = PluginManager("hbmqtt.test.plugins", context=None)
     assert len(manager._plugins) > 0
示例#7
0
 def test_load_plugin(self):
     manager = PluginManager("amqtt.test.plugins", context=None)
     assert len(manager._plugins) > 0
示例#8
0
 def setUp(self):
     self.loop = asyncio.new_event_loop()
     asyncio.set_event_loop(self.loop)
     self.plugin_manager = PluginManager("amqtt.test.plugins",
                                         context=None,
                                         loop=self.loop)