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


Python EventPublisher._topic方法代码示例

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


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

示例1: TestEventPublisher

# 需要导入模块: from pyon.event.event import EventPublisher [as 别名]
# 或者: from pyon.event.event.EventPublisher import _topic [as 别名]
class TestEventPublisher(IonUnitTestCase):

    def setUp(self):
        self._node = Mock(spec=NodeB)
        self._pub = EventPublisher(node=self._node)

    def test_init(self):
        self.assertEquals(self._pub.name, ("%s.pyon.events" % bootstrap.sys_name, None))

        pub = EventPublisher(node=self._node, xp=sentinel.xp)
        self.assertEquals(pub.name, (sentinel.xp, None))

    def test__topic_no_origin(self):
        self.assertRaises(AssertionError, self._pub._topic, None)

    def test__topic(self):
        topic = self._pub._topic(sentinel.origin)
        self.assertIn(str(sentinel.origin), topic)
        self.assertIn(str(self._pub.event_name), topic)

        self.assertEquals(topic, "%s.%s" % (self._pub.event_name, str(sentinel.origin)))

    def test__topic_new_event_name(self):
        self._pub.event_name = sentinel.event_name

        topic2 = self._pub._topic(sentinel.origin2)
        self.assertEquals(topic2, "%s.%s" % (str(sentinel.event_name), str(sentinel.origin2)))

    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)
#.........这里部分代码省略.........
开发者ID:dstuebe,项目名称:pyon,代码行数:103,代码来源:test_event.py


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