本文整理汇总了Python中pypeman.channels.BaseChannel.handle_and_wait方法的典型用法代码示例。如果您正苦于以下问题:Python BaseChannel.handle_and_wait方法的具体用法?Python BaseChannel.handle_and_wait怎么用?Python BaseChannel.handle_and_wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypeman.channels.BaseChannel
的用法示例。
在下文中一共展示了BaseChannel.handle_and_wait方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_chan_node_mocking_in_test_mode
# 需要导入模块: from pypeman.channels import BaseChannel [as 别名]
# 或者: from pypeman.channels.BaseChannel import handle_and_wait [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")
示例2: test_chan_process_in_test_mode
# 需要导入模块: from pypeman.channels import BaseChannel [as 别名]
# 或者: from pypeman.channels.BaseChannel import handle_and_wait [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")