当前位置: 首页>>代码示例>>Python>>正文


Python EventPublisher.create_and_publish_event方法代码示例

本文整理汇总了Python中pyon.event.event.EventPublisher.create_and_publish_event方法的典型用法代码示例。如果您正苦于以下问题:Python EventPublisher.create_and_publish_event方法的具体用法?Python EventPublisher.create_and_publish_event怎么用?Python EventPublisher.create_and_publish_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyon.event.event.EventPublisher的用法示例。


在下文中一共展示了EventPublisher.create_and_publish_event方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_base_subscriber_as_catchall

# 需要导入模块: from pyon.event.event import EventPublisher [as 别名]
# 或者: from pyon.event.event.EventPublisher import create_and_publish_event [as 别名]
    def test_base_subscriber_as_catchall(self):
        ar = event.AsyncResult()
        gq = queue.Queue()
        self.count = 0

        def cb(*args, **kwargs):
            self.count += 1
            gq.put(args[0])
            if self.count == 2:
                ar.set()

        sub = EventSubscriber(node=self.container.node, callback=cb)
        pub1 = self.TestEventPublisher(node=self.container.node)
        pub2 = EventPublisher(node=self.container.node)

        self._listen(sub)

        pub1.create_and_publish_event(origin="some", description="1")
        pub2.create_and_publish_event(origin="other", description="2")

        ar.get(timeout=5)

        res = []
        for x in xrange(self.count):
            res.append(gq.get(timeout=5))

        self.assertEquals(len(res), 2)
        self.assertEquals(res[0].description, "1")
        self.assertEquals(res[1].description, "2")
开发者ID:dstuebe,项目名称:pyon,代码行数:31,代码来源:test_event.py

示例2: TestEventPublisher

# 需要导入模块: from pyon.event.event import EventPublisher [as 别名]
# 或者: from pyon.event.event.EventPublisher import create_and_publish_event [as 别名]

#.........这里部分代码省略.........
    def test__set_event_msg_fields_no_args(self):
        msg = Mock()     # Mock has a __dict__ member so this works

        pre_dict = str(msg.__dict__)
        unused = self._pub._set_event_msg_fields(msg, {})

        self.assertEquals(len(unused), 0)
        self.assertEquals(str(pre_dict), str(msg.__dict__))

    def test__set_event_msg_fields_args_not_in_msg(self):
        msg = Mock()

        pre_dict = str(msg.__dict__)
        unused = self._pub._set_event_msg_fields(msg, {'field': sentinel.value, 'field2': sentinel.value2})

        self.assertEquals(len(unused), 2)
        self.assertIn('field', unused)
        self.assertIn('field2', unused)

        self.assertEquals(str(pre_dict), str(msg.__dict__))

    def test__set_event_msg_fields(self):
        msg = Mock()
        msg.field = sentinel.old_value
        msg.field2 = sentinel.old_value2
        msg.field3 = sentinel.old_value3

        pre_dict = str(msg.__dict__)
        unused = self._pub._set_event_msg_fields(msg, {'field': sentinel.value, 'field2': sentinel.value2})

        self.assertEquals(len(unused), 0)
        self.assertNotEquals(str(pre_dict), str(msg.__dict__))

        self.assertEquals(msg.field, sentinel.value)
        self.assertEquals(msg.field2, sentinel.value2)
        self.assertEquals(msg.field3, sentinel.old_value3)

    @patch('pyon.event.event.bootstrap')
    def test_create_event_default_timestamp(self, mockobj):
        m = Mock()
        m.ts_created = sentinel.old_ts_created
        mockobj.IonObject.return_value = m

        ev = self._pub.create_event()
        mockobj.IonObject.assert_called_once_with(self._pub.msg_type)

        self.assertTrue(hasattr(ev, 'ts_created'))
        self.assertNotEquals(ev.ts_created, sentinel.old_ts_created)
        self.assertIsInstance(ev.ts_created, float)

    @patch('pyon.event.event.bootstrap')
    def test_create_event_with_kwargs(self, mockobj):
        m = Mock()
        m.ts_created = sentinel.old_ts_created
        m.field = sentinel.old_value
        mockobj.IonObject.return_value = m

        ev = self._pub.create_event(field=sentinel.value)
        mockobj.IonObject.assert_called_once_with(self._pub.msg_type)

        self.assertEquals(m.field, sentinel.value)

    @patch('pyon.event.event.bootstrap')
    def test_create_event_unknown_kwargs(self, mockobj):
        m = Mock()
        m.ts_created = sentinel.old_ts_created
        mockobj.IonObject.return_value = m

        with self.assertRaises(EventError) as cm:
            self._pub.create_event(extra=sentinel.extra)

        self.assertIn('extra', cm.exception.message)

    def test_publish_event_no_origin(self):
        self.assertRaises(AssertionError, self._pub.publish_event, sentinel.event_msg)

    def test_publish_event(self):
        self._pub.publish = Mock()

        self._pub.publish_event(sentinel.event_msg, origin=sentinel.origin)
        self._pub.publish.assert_called_once_with(sentinel.event_msg, to_name=(get_events_exchange_point(), self._pub._topic(sentinel.origin)))
        self._pub.publish().close.assert_called_once_with()

    def test_publish_event_with_event_repo(self):
        self._pub.publish = Mock()
        self._pub.event_repo = Mock()

        self._pub.publish_event(sentinel.event_msg, origin=sentinel.origin)

        self._pub.event_repo.put_event.assert_called_once_with(sentinel.event_msg)

    def test_create_and_publish_event(self):
        self._pub.create_event = Mock()
        self._pub.create_event.return_value = sentinel.event_msg
        self._pub.publish_event = Mock()

        self._pub.create_and_publish_event(origin=sentinel.origin, field=sentinel.value, field2=sentinel.value2)

        self._pub.create_event.assert_called_once_with(origin=sentinel.origin, field=sentinel.value, field2=sentinel.value2)
        self._pub.publish_event.assert_called_once_with(sentinel.event_msg, origin=sentinel.origin)
开发者ID:dstuebe,项目名称:pyon,代码行数:104,代码来源:test_event.py


注:本文中的pyon.event.event.EventPublisher.create_and_publish_event方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。