本文整理匯總了Python中pypeman.channels.BaseChannel.get_node方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseChannel.get_node方法的具體用法?Python BaseChannel.get_node怎麽用?Python BaseChannel.get_node使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pypeman.channels.BaseChannel
的用法示例。
在下文中一共展示了BaseChannel.get_node方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_chan_node_mocking_in_test_mode
# 需要導入模塊: from pypeman.channels import BaseChannel [as 別名]
# 或者: from pypeman.channels.BaseChannel import get_node [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 get_node [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")