Example #1
0
def test_access_exceptions():
    """Test access exceptions.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    assert database.list_accessible_entries('root') == ['val1']

    database.add_access_exception('root', 'root/node1', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val2']
    assert database.get_value('root', 'val2') == 'a'

    database.add_access_exception('root', 'root/node2', 'val3')
    assert database.list_accessible_entries('root') == ['val1', 'val2', 'val3']
    assert database.get_value('root', 'val3') == 2.0

    database.remove_access_exception('root', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val3']

    database.remove_access_exception('root')
    assert database.list_accessible_entries('root') == ['val1']
Example #2
0
def test_access_exceptions():
    """Test access exceptions.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    assert database.list_accessible_entries('root') == ['val1']

    database.add_access_exception('root', 'root/node1', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val2']
    assert database.get_value('root', 'val2') == 'a'

    database.add_access_exception('root', 'root/node2', 'val3')
    assert database.list_accessible_entries('root') == ['val1', 'val2', 'val3']
    assert database.get_value('root', 'val3') == 2.0

    database.remove_access_exception('root', 'val2')
    assert database.list_accessible_entries('root') == ['val1', 'val3']

    database.remove_access_exception('root')
    assert database.list_accessible_entries('root') == ['val1']
Example #3
0
def test_flattening_database():
    """Check that the database can be flattened.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')

    database.prepare_to_run()
Example #4
0
def test_flattening_database():
    """Check that the database can be flattened.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')

    database.prepare_for_running()
Example #5
0
def test_access_exceptions_renaming_values():
    """Test renaming values linked to an access ex.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val1', 2.0)

    database.add_access_exception('root', 'root/node1', 'val1')
    database.rename_values('root/node1', ['val1'], ['new_val'], {'val1': 1})
    assert database.get_value('root', 'new_val') == 2.0
Example #6
0
def test_access_exceptions_renaming_values():
    """Test renaming values linked to an access ex.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val1', 2.0)

    database.add_access_exception('root', 'root/node1', 'val1')
    database.rename_values('root/node1', ['val1'], ['new_val'], {'val1': 1})
    assert database.get_value('root', 'new_val') == 2.0
Example #7
0
def test_database_nodes():
    """Test all nodes operations.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.rename_node('root', 'node1', 'n_node1')
    database.delete_node('root/n_node1', 'node2')
    with raises(KeyError):
        database.delete_node('root/n_node1', 'node2')
Example #8
0
def test_database_nodes():
    """Test all nodes operations.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.rename_node('root', 'node1', 'n_node1')
    database.delete_node('root/n_node1', 'node2')
    with raises(KeyError):
        database.delete_node('root/n_node1', 'node2')
Example #9
0
def test_database_values3():
    """Test accessing a value with the wrong path.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.set_value('root/node1/node2', 'val1', 1)
    assert database.get_value('root/node1/node2', 'val1') == 1
    with raises(KeyError):
        database.get_value('root/node1', 'val1')
Example #10
0
def test_database_values3():
    """Test accessing a value with the wrong path.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.set_value('root/node1/node2', 'val1', 1)
    assert database.get_value('root/node1/node2', 'val1') == 1
    with raises(KeyError):
        database.get_value('root/node1', 'val1')
Example #11
0
def test_get_set_on_flat_database1():
    """Test get/set operations on flat database using names.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')

    database.prepare_to_run()
    assert not database.set_value('root', 'val1', 2)
    assert database.get_value('root', 'val1') == 2
    assert database.get_value('root/node1', 'val1') == 2
Example #12
0
def test_copy_node_values():
    """Test copying the values found in a node.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    assert database.copy_node_values() == {'val1': 1}
    assert database.copy_node_values('root/node1') == {'val2': 'a'}
Example #13
0
def test_copy_node_values():
    """Test copying the values found in a node.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    assert database.copy_node_values() == {'val1': 1}
    assert database.copy_node_values('root/node1') == {'val2': 'a'}
Example #14
0
def test_get_set_on_flat_database1():
    """Test get/set operations on flat database using names.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')

    database.prepare_for_running()
    assert not database.set_value('root', 'val1', 2)
    assert database.get_value('root', 'val1') == 2
    assert database.get_value('root/node1', 'val1') == 2
Example #15
0
def test_get_set_on_flat_database2():
    """Test get/set operations on flat database using names when an access ex
    exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_for_running()
    assert not database.set_value('root', 'val2', 2)
    assert database.get_value('root', 'val2') == 2
Example #16
0
def test_get_set_on_flat_database2():
    """Test get/set operations on flat database using names when an access ex
    exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_to_run()
    assert not database.set_value('root', 'val2', 2)
    assert database.get_value('root', 'val2') == 2
Example #17
0
def test_index_op_on_flat_database2():
    """Test operation on flat database relying on indexes when a simple access
    ex exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_for_running()
    assert database.get_entries_indexes('root', ['val1']) == {'val1': 0}
    assert database.get_entries_indexes('root', ['val1', 'val2']) == \
        {'val1': 0, 'val2': 1}
Example #18
0
def test_index_op_on_flat_database2():
    """Test operation on flat database relying on indexes when a simple access
    ex exists.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.add_access_exception('root', 'root/node1', 'val2')

    database.prepare_to_run()
    assert database.get_entries_indexes('root', ['val1']) == {'val1': 0}
    assert database.get_entries_indexes('root', ['val1', 'val2']) == \
        {'val1': 0, 'val2': 1}
Example #19
0
def test_list_nodes():
    """Test listing the nodes existing in the database.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    nodes = database.list_nodes()
    assert 'root' in nodes
    assert 'root/node1' in nodes
    assert 'root/node2' in nodes
Example #20
0
def test_list_nodes():
    """Test listing the nodes existing in the database.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root', 'node2')
    database.set_value('root/node2', 'val3', 2.0)

    nodes = database.list_nodes()
    assert 'root' in nodes
    assert 'root/node1' in nodes
    assert 'root/node2' in nodes
Example #21
0
def test_forbidden_operations():
    """Check that all forbidden operations does raise a RuntimeError.

    """
    database = TaskDatabase()
    database.prepare_for_running()
    with raises(RuntimeError):
        database.rename_values('root', [], [])
    with raises(RuntimeError):
        database.delete_value('root', '')
    with raises(RuntimeError):
        database.create_node('root', '')
    with raises(RuntimeError):
        database.rename_node('root', '', '')
    with raises(RuntimeError):
        database.delete_node('root', '')
Example #22
0
def test_forbidden_operations():
    """Check that all forbidden operations does raise a RuntimeError.

    """
    database = TaskDatabase()
    database.prepare_to_run()
    with raises(RuntimeError):
        database.rename_values('root', [], [])
    with raises(RuntimeError):
        database.delete_value('root', '')
    with raises(RuntimeError):
        database.create_node('root', '')
    with raises(RuntimeError):
        database.rename_node('root', '', '')
    with raises(RuntimeError):
        database.delete_node('root', '')
Example #23
0
def test_database_values():
    """Test get/set value operations.

    """
    database = TaskDatabase()
    assert database.set_value('root', 'val1', 1) is True
    assert database.get_value('root', 'val1') == 1
    assert database.set_value('root', 'val1', 2) is False
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    assert database.get_value('root/node1', 'val2') == 'a'
    assert database.get_value('root/node1', 'val1') == 2
    with raises(KeyError):
        database.get_value('root/rrtt', 'val')
    with raises(KeyError):
        database.get_value('root/node1/rr', 'val')
Example #24
0
def test_database_values():
    """Test get/set value operations.

    """
    database = TaskDatabase()
    assert database.set_value('root', 'val1', 1) is True
    assert database.get_value('root', 'val1') == 1
    assert database.set_value('root', 'val1', 2) is False
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    assert database.get_value('root/node1', 'val2') == 'a'
    assert database.get_value('root/node1', 'val1') == 2
    with raises(KeyError):
        database.get_value('root/rrtt', 'val')
    with raises(KeyError):
        database.get_value('root/node1/rr', 'val')
Example #25
0
def test_access_exceptions_renaming_node():
    """Test renaming a node holding an access exception.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.set_value('root/node1/node2', 'val1', 2.0)

    database.add_access_exception('root', 'root/node1/node2', 'val1')
    assert database.get_value('root', 'val1') == 2.0

    database.rename_node('root/node1', 'node2', 'node22')
    assert database.get_value('root', 'val1') == 2.0

    database.rename_node('root', 'node1', 'node11')
    assert database.get_value('root', 'val1') == 2.0
Example #26
0
def test_access_exceptions_renaming_node():
    """Test renaming a node holding an access exception.

    The relative path is exactly the name of the renamed node.

    """
    database = TaskDatabase()
    database.create_node('root', 'node1')
    database.create_node('root/node1', 'node2')
    database.set_value('root/node1/node2', 'val1', 2.0)

    database.add_access_exception('root/node1', 'root/node1/node2', 'val1')
    assert database.get_value('root/node1', 'val1') == 2.0

    database.rename_node('root/node1', 'node2', 'node22')
    assert database.get_value('root/node1', 'val1') == 2.0

    database.rename_node('root', 'node1', 'node11')
    assert database.get_value('root/node11', 'val1') == 2.0
Example #27
0
def test_index_op_on_flat_database1():
    """Test operation on flat database relying on indexes.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root/node1', 'node2')

    database.prepare_to_run()
    assert database.get_entries_indexes('root', ['val1']) == {'val1': 0}
    assert database.get_entries_indexes('root/node1', ['val1', 'val2']) == \
        {'val1': 0, 'val2': 1}
    assert database.get_entries_indexes('root/node1/node2', ['val2']) == \
        {'val2': 1}

    assert database.get_values_by_index([0, 1]) == [1, 'a']
    assert database.get_values_by_index([0, 1], 'e_') == \
        {'e_0': 1, 'e_1': 'a'}
    with raises(KeyError):
        database.get_entries_indexes('root/rr', [''])
Example #28
0
def test_index_op_on_flat_database1():
    """Test operation on flat database relying on indexes.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')
    database.create_node('root/node1', 'node2')

    database.prepare_for_running()
    assert database.get_entries_indexes('root', ['val1']) == {'val1': 0}
    assert database.get_entries_indexes('root/node1', ['val1', 'val2']) == \
        {'val1': 0, 'val2': 1}
    assert database.get_entries_indexes('root/node1/node2', ['val2']) == \
        {'val2': 1}

    assert database.get_values_by_index([0, 1]) == [1, 'a']
    assert database.get_values_by_index([0, 1], 'e_') == \
        {'e_0': 1, 'e_1': 'a'}
    with raises(KeyError):
        database.get_entries_indexes('root/rr', [''])
Example #29
0
def test_database_listing():
    """Test database entries listing.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')

    assert database.list_all_entries() == \
        sorted(['root/val1', 'root/node1/val2'])
    assert database.list_all_entries(values=True) == \
        {'root/val1': 1, 'root/node1/val2': 'a'}
    assert database.list_accessible_entries('root') == ['val1']
    assert database.list_accessible_entries('root/node1') ==\
        sorted(['val1', 'val2'])

    # Test excluding values from the database.
    database.excluded = ['val1']
    assert database.list_all_entries() == sorted(['root/node1/val2'])
    assert database.list_all_entries(values=True) == {'root/node1/val2': 'a'}
    assert database.list_accessible_entries('root') == []
    assert database.list_accessible_entries('root/node1') == sorted(['val2'])
Example #30
0
def test_database_listing():
    """Test database entries listing.

    """
    database = TaskDatabase()
    database.set_value('root', 'val1', 1)
    database.create_node('root', 'node1')
    database.set_value('root/node1', 'val2', 'a')

    assert database.list_all_entries() == \
        sorted(['root/val1', 'root/node1/val2'])
    assert database.list_all_entries(values=True) == \
        {'root/val1': 1, 'root/node1/val2': 'a'}
    assert database.list_accessible_entries('root') == ['val1']
    assert database.list_accessible_entries('root/node1') ==\
        sorted(['val1', 'val2'])

    # Test excluding values from the database.
    database.excluded = ['val1']
    assert database.list_all_entries() == sorted(['root/node1/val2'])
    assert database.list_all_entries(values=True) == {'root/node1/val2': 'a'}
    assert database.list_accessible_entries('root') == []
    assert database.list_accessible_entries('root/node1') == sorted(['val2'])