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


Python BaseChannel.when方法代码示例

本文整理汇总了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")
开发者ID:ElBui,项目名称:pypeman,代码行数:33,代码来源:test_channel.py

示例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))
开发者ID:jrmi,项目名称:pypeman,代码行数:24,代码来源:test_msgstore.py


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