本文整理汇总了Python中ecpy.tasks.base_tasks.RootTask.observe方法的典型用法代码示例。如果您正苦于以下问题:Python RootTask.observe方法的具体用法?Python RootTask.observe怎么用?Python RootTask.observe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ecpy.tasks.base_tasks.RootTask
的用法示例。
在下文中一共展示了RootTask.observe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_access_exceptions
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import observe [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')
示例2: test_adding_child
# 需要导入模块: from ecpy.tasks.base_tasks import RootTask [as 别名]
# 或者: from ecpy.tasks.base_tasks.RootTask import observe [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])