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


Python BaseChannel._reset_test方法代码示例

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


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

示例1: test_chan_node_mocking_in_test_mode

# 需要导入模块: from pypeman.channels import BaseChannel [as 别名]
# 或者: from pypeman.channels.BaseChannel import _reset_test [as 别名]
    def test_chan_node_mocking_in_test_mode(self):
        """ Whether node mocking input and output is working """

        chan = BaseChannel(name="test_channel_test_2", loop=self.loop)

        n = TestNode(name="testme")
        chan.add(n)

        msg_x = generate_msg(message_content="X")
        msg_a = generate_msg(message_content="A")
        msg_b = generate_msg(message_content="B")
        msg_c = generate_msg(message_content="C")
        msg_d = generate_msg(message_content="D")

        def concat_e(msg):
            msg.payload += "E"
            return msg

        def concat_f(msg):
            msg.payload += "F"
            return msg

        # Launch channel processing
        self.start_channels()

        # Mock input
        chan._reset_test()
        chan.get_node("testme").mock(input=msg_a)

        ret = chan.handle_and_wait(msg_x)

        self.assertEqual(n.processed, 1, "Channel in test mode not working")
        self.assertEqual(ret.payload, "A", "Mocking input broken")
        self.assertEqual(chan.get_node("testme").last_input().payload, "X", "Last input broken")

        # Mock output
        chan._reset_test()
        chan.get_node("testme").mock(output=msg_b)
        ret = chan.handle_and_wait(msg_x)

        self.assertEqual(n.processed, 1, "Channel in test mode not working")
        self.assertEqual(ret.payload, "B", "Mocking input broken")
        self.assertEqual(chan.get_node("testme").last_input().payload, "X", "Last input broken")

        # Mock both
        chan._reset_test()
        chan.get_node("testme").mock(input=msg_c, output=msg_d)
        ret = chan.handle_and_wait(msg_x)

        self.assertEqual(n.processed, 1, "Channel in test mode not working")
        self.assertEqual(ret.payload, "D", "Mocking both input and output broken")

        # Mock both functions
        chan._reset_test()
        chan.get_node("testme").mock(input=concat_e, output=concat_f)
        ret = chan.handle_and_wait(msg_x)

        self.assertEqual(n.processed, 1, "Channel in test mode not working")
        self.assertEqual(ret.payload, "XEF", "Mocking with function broken")
开发者ID:jrmi,项目名称:pypeman,代码行数:61,代码来源:test_testing.py

示例2: test_chan_process_in_test_mode

# 需要导入模块: from pypeman.channels import BaseChannel [as 别名]
# 或者: from pypeman.channels.BaseChannel import _reset_test [as 别名]
    def test_chan_process_in_test_mode(self):
        """ Whether BaseChannel handling with test mode is working """

        chan = BaseChannel(name="test_channel_test_1", loop=self.loop)

        n = TestNode(name="testme")
        chan.add(n)

        msg = generate_msg(message_content="X")

        # Launch channel processing
        self.start_channels()
        chan._reset_test()

        chan.handle_and_wait(msg)

        self.assertEqual(n.processed, 1, "Channel in test mode not working")
        self.assertTrue(hasattr(n, '_handle'), "Channel in test mode not working")
        self.assertEqual(chan.get_node("testme").last_input().payload, "X", "Last input broken")
开发者ID:jrmi,项目名称:pypeman,代码行数:21,代码来源:test_testing.py


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