Пример #1
0
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,
            'val3': 2
        },
    )

    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)
    task3.add_access_exception('val3', 1)

    assert task2.get_from_database('task3_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)
    task3.modify_access_exception('val3', -1)
    assert task1.get_from_database('task3_val2') == 1
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val3')

    task3.remove_access_exception('val2')
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val2')
Пример #2
0
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])
Пример #3
0
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])
Пример #4
0
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, 'val3': 2},
                       )

    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)
    task3.add_access_exception('val3', 1)

    assert task2.get_from_database('task3_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)
    task3.modify_access_exception('val3', -1)
    assert task1.get_from_database('task3_val2') == 1
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val3')

    task3.remove_access_exception('val2')
    with pytest.raises(KeyError):
        task2.get_from_database('task3_val2')