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