本文整理汇总了Python中ecpy.tasks.base_tasks.RootTask.add_child_task方法的典型用法代码示例。如果您正苦于以下问题:Python RootTask.add_child_task方法的具体用法?Python RootTask.add_child_task怎么用?Python RootTask.add_child_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecpy.tasks.base_tasks.RootTask
的用法示例。
在下文中一共展示了RootTask.add_child_task方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_task_renaming
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_task_renaming():
"""Test renaming simple and complex task.
"""
root = RootTask()
task1 = ComplexTask(name='task1',
database_entries={'val1': 2.0})
task2 = ComplexTask(name='task2')
task3 = SimpleTask(name='task3',
database_entries={'val2': 1},
access_exs={'val2': 2})
task2.add_child_task(0, task3)
task1.add_child_task(0, task2)
root.add_child_task(0, task1)
task3.name = 'worker3'
with pytest.raises(KeyError):
root.get_from_database('task3_val2')
assert root.get_from_database('worker3_val2') == 1
task1.name = 'worker1'
with pytest.raises(KeyError):
root.get_from_database('task1_val1')
assert root.get_from_database('worker1_val1') == 2.0
assert root.get_from_database('worker3_val2') == 1
示例2: test_deleting_child
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_deleting_child():
"""Test deleting a child.
"""
root = RootTask()
task1 = ComplexTask(name='task1',
database_entries={'val1': 2.0})
task2 = SimpleTask(name='task2',
database_entries={'val2': 1},
access_exs={'val2': 2})
task3 = ComplexTask(name='task3')
task4 = ComplexTask(name='task4')
task1.add_child_task(0, task2)
task1.add_child_task(1, task4)
root.add_child_task(0, task1)
root.add_child_task(1, task3)
listener = SignalListener()
task1.observe('children_changed', listener.listen)
task1.remove_child_task(0)
assert listener.counter == 1
assert listener.signals[0].removed
assert task1.preferences['children_0']['name'] == 'task4'
assert 'task2_val2' not in task3.list_accessible_database_entries()
root.remove_child_task(0)
assert len(root.children) == 1
with pytest.raises(KeyError):
root.get_from_database('task1_val1')
示例3: test_moving_child
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_moving_child():
"""Test moving a child.
"""
root = RootTask()
task1 = ComplexTask(name='task1',
database_entries={'val1': 2.0})
task2 = SimpleTask(name='task2',
database_entries={'val2': 1},
access_exs={'val2': 2})
task3 = ComplexTask(name='task3')
task4 = ComplexTask(name='task4')
task1.add_child_task(0, task2)
task1.add_child_task(1, task4)
root.add_child_task(0, task1)
root.add_child_task(1, task3)
listener = SignalListener()
task1.observe('children_changed', listener.listen)
assert task1.preferences['children_0']['name'] == 'task2'
assert task1.preferences['children_1']['name'] == 'task4'
task1.move_child_task(0, 1)
assert listener.counter == 1
assert listener.signals[0].moved
assert task1.preferences['children_0']['name'] == 'task4'
assert task1.preferences['children_1']['name'] == 'task2'
assert task3.get_from_database('task2_val2') == 1
示例4: test_database_update_with_exception
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_database_update_with_exception():
"""Test that replacing the database_entries members refreshes the database.
"""
root = RootTask()
task1 = ComplexTask(name='task1',
database_entries={'val1': 2.0})
task2 = SimpleTask(name='task2',
database_entries={'val2': 1},
access_exs={'val2': 1})
task3 = ComplexTask(name='task3')
task1.add_child_task(0, task2)
root.add_child_task(0, task1)
root.add_child_task(1, task3)
assert task3.get_from_database('task2_val2')
entries = task2.database_entries.copy()
del entries['val2']
task2.database_entries = entries
with pytest.raises(KeyError):
task1.get_from_database('task2_val2')
with pytest.raises(KeyError):
task3.get_from_database('task2_val2')
示例5: test_access_exceptions
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_access_exceptions():
"""Test adding, modifying and removing an access exception after creation.
"""
root = RootTask()
listener = SignalListener()
root.observe('children_changed', listener.listen)
task1 = ComplexTask(name='task1',
database_entries={'val1': 2.0})
task2 = ComplexTask(name='task2')
task3 = SimpleTask(name='task3',
database_entries={'val2': 1},
)
task2.add_child_task(0, task3)
task1.add_child_task(0, task2)
root.add_child_task(0, task1)
with pytest.raises(KeyError):
task2.get_from_database('task3_val2')
task3.add_access_exception('val2', 1)
assert task2.get_from_database('task3_val2') == 1
with pytest.raises(KeyError):
task1.get_from_database('task3_val2')
task3.modify_access_exception('val2', 2)
assert task1.get_from_database('task3_val2') == 1
task3.remove_access_exception('val2')
with pytest.raises(KeyError):
task2.get_from_database('task3_val2')
示例6: TestConditionTask
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [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
示例7: test_build_from_config1
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_build_from_config1(self):
"""Test building a interfaceable task with no interface from a config.
"""
aux = RootTask()
aux.add_child_task(0, IMixin())
print(aux.preferences)
bis = RootTask.build_from_config(aux.preferences,
{'ecpy.task': {'IMixin': IMixin,
'RootTask': RootTask}})
assert type(bis.children[0]).__name__ == 'IMixin'
示例8: test_build_from_config1
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_build_from_config1(self):
"""Test building a interfaceable interface with no interface from a
config.
"""
aux = RootTask()
mixin = Mixin()
mixin.interface = InterfaceTest3()
aux.add_child_task(0, mixin)
deps = {'ecpy.task': {'tests.Mixin': Mixin, 'ecpy.RootTask': RootTask},
'ecpy.tasks.interface':
{('InterfaceTest3', ('tests.Mixin',)): InterfaceTest3}}
bis = RootTask.build_from_config(aux.preferences, deps)
assert type(bis.children[0].interface).__name__ == 'InterfaceTest3'
示例9: test_update_preferences_from_members
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_update_preferences_from_members():
"""Test updating the preferences.
Only operation on the children cause re-registering to ensure the children
ordering.
"""
root = RootTask()
task1 = SimpleTask(name='task1')
root.add_child_task(0, task1)
assert root.preferences['children_0']['name'] == 'task1'
task1.name = 'worker1'
assert root.preferences['children_0']['name'] == 'task1'
root.update_preferences_from_members()
assert root.preferences['children_0']['name'] == 'worker1'
示例10: test_traverse
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_traverse():
"""Test traversing a task hierarchy to collect infos.
"""
root = RootTask()
task1 = ComplexTask(name='task1',
database_entries={'val1': 2.0})
task2 = SimpleTask(name='task2',
database_entries={'val2': 1},
access_exs={'val2': 2})
task3 = ComplexTask(name='task3')
task1.add_child_task(0, task2)
root.add_child_task(0, task1)
root.add_child_task(1, task3)
flat = list(root.traverse())
assert flat == [root, task1, task2, task3]
flat = list(root.traverse(0))
assert flat == [root, task1, task3]
示例11: test_adding_child
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_adding_child():
"""Test adding children.
This test adding a child with and without access_exs to a task which is not
root and then to the root. This makes sure that giving the root afterwards
does trigger the right updates.
"""
root = RootTask()
listener = SignalListener()
root.observe('children_changed', listener.listen)
task1 = ComplexTask(name='task1',
database_entries={'val1': 2.0})
task2 = SimpleTask(name='task2',
database_entries={'val2': 1},
access_exs={'val2': 2})
task3 = ComplexTask(name='task3')
task1.add_child_task(0, task2)
root.add_child_task(0, task1)
root.add_child_task(1, task3)
assert task1.depth == 1
assert task1.path == 'root'
assert task1.database is root.database
assert task1.root is root
assert task1.parent is root
assert task2.depth == 2
assert task2.path == 'root/task1'
assert task2.database is root.database
assert task2.root is root
assert task2.parent is task1
assert task1.get_from_database('task1_val1') == 2.0
assert root.get_from_database('task1_val1') == 2.0
assert task3.get_from_database('task2_val2') == 1
assert listener.counter == 2
assert all([bool(c.added) for c in listener.signals])
示例12: test_swapping
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
def test_swapping(windows, task_workbench):
"""Test moving a view between containers.
"""
from ..conftest import DIALOG_SLEEP
task = RootTask()
view = RootTaskView(task=task,
core=task_workbench.get_plugin('enaml.workbench.core'))
subtask = ComplexTask(name='Test')
subview = view.view_for(subtask)
task.add_child_task(0, subtask)
cont = Container()
show_widget(cont)
view.set_parent(cont)
view.refresh()
process_app_events()
assert cont.children == [view]
sleep(DIALOG_SLEEP)
view.set_parent(None)
subview.set_parent(cont)
subview.refresh()
process_app_events()
assert cont.children == [subview]
sleep(DIALOG_SLEEP)
subview.set_parent(None)
view.set_parent(cont)
view.refresh()
process_app_events()
assert cont.children == [view]
assert subview.visible
sleep(DIALOG_SLEEP)
示例13: TestInterfaceableInterfaceMixin
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
class TestInterfaceableInterfaceMixin(object):
"""Test the capabilities of task interfaces.
"""
def setup(self):
self.root = RootTask()
self.mixin = InterfaceTest3()
self.root.add_child_task(0, Mixin(name='Simple', interface=self.mixin))
def test_interface_observer(self):
"""Test changing the interface.
"""
i1 = IIinterfaceTest1()
i2 = IIinterfaceTest2()
self.mixin.interface = i1
assert i1.parent is self.mixin
assert i1.task is self.mixin.task
assert i1.interface_id[1] ==\
(self.mixin.interface_id[1] + (self.mixin.interface_id[0],))
assert self.mixin.task.database_entries == {'test': 2.0, 'itest': 1.0}
self.mixin.interface = i2
assert i2.task is self.mixin.task
assert i1.parent is None
with pytest.raises(AttributeError):
i1.task
assert self.mixin.task.database_entries == {'test': 2.0, 'itest': 2.0,
'fmt': '', 'feval': 0}
def test_check1(self):
"""Test running checks when the interface is present.
"""
self.mixin.interface = IIinterfaceTest1(answer=True)
res, traceback = self.mixin.check()
assert res
assert not traceback
assert self.mixin.interface.called
def test_check2(self):
"""Test running checks when no interface exist but i_perform is
implemented.
"""
interface = InterfaceTest4()
self.root.children[0].interface = interface
res, traceback = interface.check()
assert res
assert not traceback
def test_check3(self):
"""Test handling missing interface.
"""
res, traceback = self.mixin.check()
assert not res
assert traceback
assert len(traceback) == 1
assert 'root/Simple/InterfaceTest3-interface' in traceback
def test_check4(self):
"""Test handling a non-passing test from the interface.
"""
self.mixin.interface = IIinterfaceTest1()
res, traceback = self.mixin.check()
assert not res
assert len(traceback) == 1
assert self.mixin.interface.called
def test_check5(self):
"""Check that auto-check of fmt and feavl tagged members works.
"""
self.mixin.interface = IIinterfaceTest2(fmt='{Simple_test}',
feval='2*{Simple_test}')
res, traceback = self.mixin.check()
assert res
assert not traceback
assert self.root.get_from_database('Simple_fmt') == '2.0'
assert self.root.get_from_database('Simple_feval') == 4.0
def test_check6(self):
"""Check that auto-check of fmt and feavl handle errors.
"""
self.mixin.interface = IIinterfaceTest2(fmt='{Simple_test*}',
feval='2*{Simple_test}*')
res, traceback = self.mixin.check()
assert not res
assert self.root.get_from_database('Simple_fmt') == ''
assert self.root.get_from_database('Simple_feval') == 0
assert len(traceback) == 2
#.........这里部分代码省略.........
示例14: TestInterfaceableTaskMixin
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
class TestInterfaceableTaskMixin(object):
"""Test the capabilities of task interfaces.
"""
def setup(self):
self.root = RootTask()
self.mixin = Mixin(name='Simple')
self.root.add_child_task(0, self.mixin)
def test_interface_observer(self):
"""Test changing the interface.
"""
i1 = InterfaceTest()
i2 = InterfaceTest2()
self.mixin.interface = i1
assert i1.task is self.mixin
assert self.mixin.database_entries == {'test': 2.0, 'itest': 1.0}
assert i1.interface_id[1] == (self.mixin.task_id,)
self.mixin.interface = i2
assert i2.task is self.mixin
assert i1.task is None
assert self.mixin.database_entries == {'test': 2.0, 'itest': 2.0,
'fmt': '', 'feval': 0}
def test_check1(self):
"""Test running checks when the interface is present.
"""
self.mixin.interface = InterfaceTest(answer=True)
res, traceback = self.mixin.check()
assert res
assert not traceback
assert self.mixin.interface.called
def test_check2(self):
"""Test running checks when no interface exist but i_perform is
implemented.
"""
res, traceback = IMixin().check()
assert res
assert not traceback
def test_check3(self):
"""Test handling missing interface.
"""
res, traceback = self.mixin.check()
assert not res
assert traceback
assert len(traceback) == 1
assert 'root/Simple-interface' in traceback
def test_check4(self):
"""Test handling a non-passing test from the interface.
"""
self.mixin.interface = InterfaceTest()
res, traceback = self.mixin.check()
assert not res
assert len(traceback) == 1
assert self.mixin.interface.called
def test_check5(self):
"""Check that auto-check of fmt and feavl tagged members works.
"""
self.mixin.interface = InterfaceTest2(fmt='{Simple_test}',
feval='2*{Simple_test}')
res, traceback = self.mixin.check()
assert res
assert not traceback
assert self.root.get_from_database('Simple_fmt') == '2.0'
assert self.root.get_from_database('Simple_feval') == 4.0
def test_check6(self):
"""Check that auto-check of fmt and feavl handle errors.
"""
self.mixin.interface = InterfaceTest2(fmt='{Simple_test*}',
feval='2*{Simple_test}*')
res, traceback = self.mixin.check()
assert not res
assert self.root.get_from_database('Simple_fmt') == ''
assert self.root.get_from_database('Simple_feval') == 0
assert len(traceback) == 2
assert 'root/Simple-fmt' in traceback
assert 'root/Simple-feval' in traceback
def test_perform1(self):
"""Test perform does call interface if present.
#.........这里部分代码省略.........
示例15: TestExceptionTasks
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import add_child_task [as 别名]
class TestExceptionTasks(object):
"""Test Break and Continue tasks checks, perform will be tested in each
looping task
"""
def setup(self):
self.root = RootTask(should_stop=Event(), should_pause=Event())
def test_check1(self, exception_task):
"""Test that everything is ok condition is evaluable and parent
is a Loop.
"""
loop = LoopTask()
loop.add_child_task(0, exception_task)
self.root.add_child_task(0, loop)
exception_task.condition = 'True'
test, traceback = exception_task.check()
assert test
assert not traceback
def test_check2(self, exception_task):
"""Simply test that everything is ok condition is evaluable and parent
is a While.
"""
whil = WhileTask()
whil.add_child_task(0, exception_task)
exception_task.condition = 'True'
self.root.add_child_task(0, whil)
test, traceback = exception_task.check()
assert test
assert not traceback
def test_check3(self, exception_task):
"""Test handling a wrong condition.
"""
loop = LoopTask(name='Parent')
loop.add_child_task(0, exception_task)
exception_task.condition = '*True'
self.root.add_child_task(0, loop)
test, traceback = exception_task.check()
assert not test
assert len(traceback) == 1
assert 'root/Parent/Test-condition' in traceback
def test_check4(self, exception_task):
"""Test handling a wrong parent type.
"""
self.root.add_child_task(0, exception_task)
exception_task.condition = 'True'
test, traceback = exception_task.check()
assert not test
assert len(traceback) == 1
assert 'root/Test-parent' in traceback