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


Python RootTask.observe方法代碼示例

本文整理匯總了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')
開發者ID:pombredanne,項目名稱:ecpy,代碼行數:35,代碼來源:test_base_tasks.py

示例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])
開發者ID:pombredanne,項目名稱:ecpy,代碼行數:41,代碼來源:test_base_tasks.py


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