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


Python RootTask.format_string方法代码示例

本文整理汇总了Python中ecpy.tasks.base_tasks.RootTask.format_string方法的典型用法代码示例。如果您正苦于以下问题:Python RootTask.format_string方法的具体用法?Python RootTask.format_string怎么用?Python RootTask.format_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ecpy.tasks.base_tasks.RootTask的用法示例。


在下文中一共展示了RootTask.format_string方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestFormatting

# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import format_string [as 别名]
class TestFormatting(object):
    """Test formatting strings and caching in running mode.

    """

    def setup(self):
        self.root = RootTask()
        database = self.root.database
        database.set_value('root', 'val1', 1)
        database.create_node('root', 'node1')
        database.set_value('root/node1', 'val2', 10.0)
        database.add_access_exception('root', 'root/node1', 'val2')

    def test_formatting_editing_mode1(self):
        """Test formatting values with text on both sides of expression.

        """
        test = 'progress is {val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0, it is good.'
        assert not self.root._format_cache

    def test_formatting_editing_mode2(self):
        """Test formatting values with text only on the left of expression.

        """
        test = 'progress is {val1}/{val2}'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0'
        assert not self.root._format_cache

    def test_formatting_editing_mode3(self):
        """Test formatting values with text only on the right of expression.

        """
        test = '{val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == '1/10.0, it is good.'
        assert not self.root._format_cache

    def test_formatting_editing_mode4(self):
        """Test formatting values with no other text.

        """
        test = '{val1}/{val2}'
        formatted = self.root.format_string(test)
        assert formatted == '1/10.0'
        assert not self.root._format_cache

    def test_formatting_editing_mode5(self):
        """Test formatting when there is only text.

        """
        test = 'test'
        formatted = self.root.format_string(test)
        assert formatted == 'test'
        assert not self.root._format_cache

    def test_formatting_running_mode1(self):
        """Test formatting values with text on both sides of expression.

        """
        self.root.database.prepare_to_run()
        test = 'progress is {val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0, it is good.'
        assert self.root._format_cache
        assert test in self.root._format_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 2/10.0, it is good.'

    def test_formatting_running_mode2(self):
        """Test formatting values with text only on the left of expression.

        """
        self.root. database.prepare_to_run()
        test = 'progress is {val1}/{val2}'
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 1/10.0'
        assert self.root._format_cache
        assert test in self.root._format_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_string(test)
        assert formatted == 'progress is 2/10.0'

    def test_formatting_running_mode3(self):
        """Test formatting values with text only on the right of expression.

        """
        self.root.database.prepare_to_run()
        test = '{val1}/{val2}, it is good.'
        formatted = self.root.format_string(test)
        assert formatted == '1/10.0, it is good.'
        assert self.root._format_cache
        assert test in self.root._format_cache
        self.root.database.set_value('root', 'val1', 2)
        formatted = self.root.format_string(test)
        assert formatted == '2/10.0, it is good.'

#.........这里部分代码省略.........
开发者ID:MatthieuDartiailh,项目名称:ecpy,代码行数:103,代码来源:test_string_ops.py


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