本文整理汇总了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))