當前位置: 首頁>>代碼示例>>Python>>正文


Python RootTask.prepare方法代碼示例

本文整理匯總了Python中ecpy.tasks.base_tasks.RootTask.prepare方法的典型用法代碼示例。如果您正苦於以下問題:Python RootTask.prepare方法的具體用法?Python RootTask.prepare怎麽用?Python RootTask.prepare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ecpy.tasks.base_tasks.RootTask的用法示例。


在下文中一共展示了RootTask.prepare方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestConditionTask

# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import prepare [as 別名]
class TestConditionTask(object):
    """Test ConditionalTask.

    """

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = ConditionalTask(name='Test')
        self.root.add_child_task(0, self.task)
        self.check = CheckTask(name='check')
        self.task.add_child_task(0, self.check)

    def test_check1(self):
        """Test that everything is ok if condition is evaluable.

        """
        self.task.condition = 'True'

        test, traceback = self.task.check()
        assert test
        assert not traceback
        assert self.check.check_called

    def test_check2(self):
        """Test handling a wrong condition.

        """
        self.task.condition = '*True'

        test, traceback = self.task.check(test_instr=True)
        assert not test
        assert len(traceback) == 1
        assert 'root/Test-condition' in traceback

    def test_perform1(self):
        """Test performing when condition is True.

        """
        self.task.condition = 'True'
        self.root.prepare()

        self.task.perform()
        assert self.check.perform_called

    def test_perform2(self):
        """Test performing when condition is False.

        """
        self.task.condition = '1 < 0'
        self.root.prepare()

        self.task.perform()
        assert not self.check.perform_called
開發者ID:MatthieuDartiailh,項目名稱:ecpy,代碼行數:55,代碼來源:test_conditional_task.py

示例2: TestLoopTask

# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import prepare [as 別名]

#.........這裏部分代碼省略.........
        assert 'root/Test-iterable' in traceback

    def test_check_iterable_interface3(self, iterable_interface):
        """Test handling a wrong iterable type.

        """
        iterable_interface.iterable = '1.0'
        self.task.interface = iterable_interface

        test, traceback = self.task.check()
        assert not test
        assert len(traceback) == 1
        assert 'root/Test' in traceback

    def test_check_execution_order(self, iterable_interface):
        """Test that the interface checks are run before the children checks.

        """
        iterable_interface.iterable = '[(1, 0)]'
        self.task.interface = iterable_interface

        subiter = IterableLoopInterface(iterable='{Test_value}')
        self.task.add_child_task(0, LoopTask(interface=subiter))

        test, traceback = self.task.check()
        print(traceback)
        assert test

    def test_perform1(self, iterable_interface):
        """Test performing a simple loop no timing. Iterable interface.

        """
        self.task.interface = iterable_interface
        self.root.prepare()

        self.task.perform()
        assert self.root.get_from_database('Test_value') == 10

    def test_perform2(self, linspace_interface):
        """Test performing a simple loop no timing. Linspace interface.

        """
        self.task.interface = linspace_interface
        self.root.prepare()

        self.task.perform()
        assert self.root.get_from_database('Test_value') == 2.0

    def test_perform3(self, iterable_interface):
        """Test performing a simple loop no timing. Break.

        """
        self.task.interface = iterable_interface
        self.task.add_child_task(0, BreakTask(name='break',
                                              condition='{Test_value} == 5')
                                 )
        self.root.prepare()

        self.task.perform()
        assert self.root.get_from_database('Test_value') == 5

    def test_perform4(self, iterable_interface):
        """Test performing a simple loop no timing. Continue

        """
        self.task.interface = iterable_interface
開發者ID:MatthieuDartiailh,項目名稱:ecpy,代碼行數:70,代碼來源:test_loop_task.py

示例3: TestWhileTask

# 需要導入模塊: from ecpy.tasks.base_tasks import RootTask [as 別名]
# 或者: from ecpy.tasks.base_tasks.RootTask import prepare [as 別名]
class TestWhileTask(object):
    """The Whiletask behaviour.

    """

    def setup(self):
        self.root = RootTask(should_stop=Event(), should_pause=Event())
        self.task = WhileTask(name='Test')
        self.root.add_child_task(0, self.task)
        self.check = CheckTask(name='check')
        self.task.add_child_task(0, self.check)

    def test_check1(self):
        """Simply test that everything is ok if condition is evaluable.

        """
        self.task.condition = 'True'

        test, traceback = self.task.check()
        assert test
        assert not traceback
        assert self.check.check_called

    def test_check2(self):
        """Test handling a wrong condition.

        """
        self.task.condition = '*True'

        test, traceback = self.task.check(test_instr=True)
        assert not test
        assert len(traceback) == 1
        assert 'root/Test-condition' in traceback

    def test_perform1(self):
        """Test performing when condition is True.

        """
        self.task.condition = '{Test_index} < 5'

        self.root.prepare()

        self.task.perform()
        assert self.check.perform_called == 4

    def test_perform2(self):
        """Test performing when condition is False.

        """
        self.task.condition = '1 < 0'

        self.root.prepare()

        self.task.perform()
        assert not self.check.perform_called

    def test_perform3(self):
        """Test handling of BreakTask and ContinueTask.

        """
        self.task.condition = 'True'
        self.task.add_child_task(0, BreakTask(name='Break',
                                              condition='True'))
        self.task.add_child_task(0, ContinueTask(name='Continue',
                                                 condition='{Test_index} < 5'))

        self.root.prepare()

        self.task.perform()
        assert not self.check.perform_called
        assert self.task.get_from_database('Test_index') == 5

    @pytest.mark.timeout(1)
    def test_perform4(self):
        """Test handling stopping while iterating.

        """
        self.task.condition = 'True'
        stop = lambda t, v: t.root.should_stop.set()
        self.task.add_child_task(0, CheckTask(name='Stop', custom=stop,
                                              stoppable=False))
        self.root.prepare()

        self.task.perform()

        assert self.task.children[0].perform_called == 1
開發者ID:MatthieuDartiailh,項目名稱:ecpy,代碼行數:88,代碼來源:test_while_task.py


注:本文中的ecpy.tasks.base_tasks.RootTask.prepare方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。