本文整理匯總了Python中pypeman.channels.BaseChannel.when方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseChannel.when方法的具體用法?Python BaseChannel.when怎麽用?Python BaseChannel.when使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pypeman.channels.BaseChannel
的用法示例。
在下文中一共展示了BaseChannel.when方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_cond_channel
# 需要導入模塊: from pypeman.channels import BaseChannel [as 別名]
# 或者: from pypeman.channels.BaseChannel import when [as 別名]
def test_cond_channel(self):
""" Whether Conditionnal channel is working """
chan = BaseChannel(name="test_channel5", loop=self.loop)
n1 = TestNode(name="main")
n2 = TestNode(name="end_main")
not_processed = TestNode(name="cond_notproc")
processed = TestNode(name="cond_proc")
msg = generate_msg()
chan.add(n1)
# Nodes in this channel should not be processed
cond1 = chan.when(lambda x: False, name="Toto")
# Nodes in this channel should be processed
cond2 = chan.when(True, name="condchannel")
chan.add(n2)
cond1.add(not_processed)
cond2.add(processed)
# Launch channel processing
self.start_channels()
self.loop.run_until_complete(chan.handle(msg))
self.assertFalse(not_processed.processed, "Cond Channel when condition == False not working")
self.assertTrue(processed.processed, "Cond Channel when condition == True not working")
self.assertFalse(n2.processed, "Cond Channel don't became the main path")
self.assertEqual(cond2.name, "test_channel5.condchannel", "Condchannel name is incorrect")
示例2: test_memory_message_store_in_fork
# 需要導入模塊: from pypeman.channels import BaseChannel [as 別名]
# 或者: from pypeman.channels.BaseChannel import when [as 別名]
def test_memory_message_store_in_fork(self):
""" We can store a message in FileMessageStore """
store_factory = msgstore.MemoryMessageStoreFactory()
chan = BaseChannel(name="test_channel10.25", loop=self.loop, message_store_factory=store_factory)
n1 = TestNode()
n2 = TestNode()
n3 = TestNode()
n4 = TestNode()
chan.add(n1, n2)
fork = chan.fork()
fork.add(n3)
self.assertTrue(isinstance(fork.message_store, msgstore.NullMessageStore))
whe = chan.when(True, message_store_factory=store_factory)
whe.add(n4)
self.assertTrue(isinstance(whe.message_store, msgstore.MemoryMessageStore))