Exemple #1
0
def test_spy(caplog):
    """Test the measurement spy working.

    """
    q = Queue()
    # Set up the database
    data = TaskDatabase()
    data.set_value('root', 'test', 0)
    data.set_value('root', 'test2', 2)
    data.prepare_to_run()

    spy = MeasureSpy(queue=q, observed_database=data,
                     observed_entries=('root/test',))

    class A(object):

        def __getstate__(self):
            raise Exception()

    with pytest.raises(Exception):
        dumps(A())

    data.set_value('root', 'test', 1)
    assert q.get(2) == ('root/test', 1)

    data.set_value('root', 'test', A())
    assert caplog.records

    data.set_value('root', 'test2', 1)
    assert q.empty()

    spy.close()
    assert q.get(2) == ('', '')
Exemple #2
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()
Exemple #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()
Exemple #4
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
Exemple #5
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
Exemple #6
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
Exemple #7
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
Exemple #8
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}
Exemple #9
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}
Exemple #10
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', '')
Exemple #11
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', '')
Exemple #12
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', [''])
Exemple #13
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', [''])