本文整理汇总了Python中ecpy.tasks.base_tasks.RootTask.check方法的典型用法代码示例。如果您正苦于以下问题:Python RootTask.check方法的具体用法?Python RootTask.check怎么用?Python RootTask.check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecpy.tasks.base_tasks.RootTask
的用法示例。
在下文中一共展示了RootTask.check方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestConditionTask
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import check [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.database.prepare_for_running()
self.root.check()
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.database.prepare_for_running()
self.root.check()
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 check [as 别名]
class TestLoopTask(object):
"""Test Loop task with and without included child.
"""
def setup(self):
self.root = RootTask(should_stop=Event(), should_pause=Event())
self.task = LoopTask(name='Test')
self.root.add_child_task(0, self.task)
def test_subtask_handling(self):
"""Test adding, changing, removing the subtask.
"""
subtask1 = CheckTask(name='check', database_entries={'val': 1})
self.task.task = subtask1
assert subtask1.root is self.root
assert subtask1.database is self.root.database
assert subtask1.parent is self.task
assert subtask1.path and subtask1.depth
assert 'value' not in self.task.database_entries
assert subtask1.get_from_database('check_val')
assert self.task.preferences['task']['name'] == 'check'
subtask2 = CheckTask(name='rep', database_entries={'new': 1})
self.task.task = subtask2
assert not subtask1.root
assert not subtask1.parent
with pytest.raises(KeyError):
assert subtask1.get_from_database('check_val')
assert subtask2.root is self.root
assert subtask2.database is self.root.database
assert subtask2.parent is self.task
assert subtask2.path and subtask1.depth
assert 'value' not in self.task.database_entries
assert subtask2.get_from_database('rep_new')
assert self.task.preferences['task']['name'] == 'rep'
self.task.task = None
assert not subtask2.root
assert not subtask2.parent
with pytest.raises(KeyError):
assert subtask2.get_from_database('rep_new')
assert 'value' in self.task.database_entries
def test_traverse(self, linspace_interface):
"""Test traversing a with interfaces ComplexTask.
"""
self.task.interface = linspace_interface
self.task.add_child_task(0, CheckTask(name='check'))
assert len(list(self.task.traverse())) == 3
def test_saving_building_from_config(self):
"""Done here as the LoopTask is a viable case of a member tagged with
child.
"""
subtask1 = CheckTask(name='check', database_entries={'val': 1})
self.task.task = subtask1
self.root.update_preferences_from_members()
new = RootTask.build_from_config(self.root.preferences,
{'ecpy.task': {'RootTask': RootTask,
'LoopTask': LoopTask,
'CheckTask': CheckTask}
})
assert new.children[0].task.name == 'check'
self.root.update_preferences_from_members()
prefs = self.root.preferences
del prefs['children_0']['task']
new = RootTask.build_from_config(prefs,
{'ecpy.task': {'RootTask': RootTask,
'LoopTask': LoopTask,
'CheckTask': CheckTask}
})
assert not new.children[0].task
def test_timing_handling(self):
"""Test enabling/disabling the timing.
"""
assert 'elapsed_time' not in self.task.database_entries
self.task.timing = True
assert 'elapsed_time' in self.task.database_entries
self.task.timing = False
assert 'elapsed_time' not in self.task.database_entries
#.........这里部分代码省略.........
示例3: TestWhileTask
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import check [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.database.prepare_for_running()
self.root.check()
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.database.prepare_for_running()
self.root.check()
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.database.prepare_for_running()
self.root.check()
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.check()
self.task.perform()
assert self.task.children[0].perform_called == 1