當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。