Esempio n. 1
0
def test_format_rule(monitor):
    """Test simplifying some entries through formatting.

    """
    f = FormatRule(suffixes=['index', 'number'],
                   new_entry_suffix='progress',
                   new_entry_formatting='{index}/{number}')

    f.try_apply('root/test_value', monitor)
    assert len(monitor.displayed_entries) == 3

    f.try_apply('root/test_index', monitor)
    assert len(monitor.displayed_entries) == 2
    assert len(monitor.hidden_entries) == 2

    f.hide_entries = False

    monitor.handle_database_entries_change(
        ('added', 'root/simp/test_index', 0))
    f.try_apply('root/simp/test_index', monitor)
    assert len(monitor.displayed_entries) == 3

    monitor.handle_database_entries_change(
        ('added', 'root/simp/test_number', 0))
    f.try_apply('root/simp/test_number', monitor)
    assert len(monitor.displayed_entries) == 5
    assert len(monitor.hidden_entries) == 2
Esempio n. 2
0
def test_format_rule(monitor):
    """Test simplifying some entries through formatting.

    """
    f = FormatRule(suffixes=['index', 'number'], new_entry_suffix='progress',
                   new_entry_formatting='{index}/{number}')

    f.try_apply('root/test_value', monitor)
    assert len(monitor.displayed_entries) == 3

    f.try_apply('root/test_index', monitor)
    assert len(monitor.displayed_entries) == 2
    assert len(monitor.hidden_entries) == 2

    f.hide_entries = False

    monitor.handle_database_change(('added', 'root/simp/test_index', 0))
    f.try_apply('root/simp/test_index', monitor)
    assert len(monitor.displayed_entries) == 3

    monitor.handle_database_change(('added', 'root/simp/test_number', 0))
    f.try_apply('root/simp/test_number', monitor)
    assert len(monitor.displayed_entries) == 5
    assert len(monitor.hidden_entries) == 2
Esempio n. 3
0
def test_handle_database_change3(app, monitor):
    """ Test handling the adding of entries subject to a format rule.

    """
    rule = FormatRule(id='Test', suffixes=['loop', 'index'],
                      new_entry_suffix='progress',
                      new_entry_formatting='{index}/{loop}')
    monitor.rules.append(rule)
    monitor.handle_database_change(('added', 'root/test_loop', 10))

    assert monitor.monitored_entries == ['root/test_loop']
    assert len(monitor.displayed_entries) == 1
    assert not monitor.undisplayed_entries
    assert not monitor.hidden_entries
    assert monitor.displayed_entries[0].depend_on == ['root/test_loop']
    assert monitor._database_values == {'root/test_loop': 10}
    assert 'root/test_loop' in monitor.updaters

    monitor.handle_database_change(('added', 'root/test2_index', 1))

    assert (monitor.monitored_entries == ['root/test_loop',
                                          'root/test2_index'])
    assert len(monitor.displayed_entries) == 2
    assert not monitor.undisplayed_entries
    assert not monitor.hidden_entries
    assert (monitor._database_values == {'root/test_loop': 10,
                                         'root/test2_index': 1})

    monitor.handle_database_change(('added', 'root/test_index', 1))

    assert (monitor.monitored_entries == ['root/test_loop',
                                          'root/test2_index',
                                          'root/test_index'])
    assert len(monitor.displayed_entries) == 2
    assert not monitor.undisplayed_entries
    assert len(monitor.hidden_entries) == 2
    assert (monitor._database_values == {'root/test_loop': 10,
                                         'root/test2_index': 1,
                                         'root/test_index': 1})
    assert len(monitor.updaters['root/test_loop']) == 1
    assert len(monitor.updaters['root/test_index']) == 1

    entry = monitor.displayed_entries[0]
    if entry.name != 'test_progress':
        entry = monitor.displayed_entries[1]

    assert entry.name == 'test_progress'
    assert entry.path == 'root/test_progress'
    assert entry.depend_on == ['root/test_loop', 'root/test_index']
    assert entry.formatting == '{root/test_index}/{root/test_loop}'
    entry.update(monitor._database_values)
    process_app_events()
    assert entry.value == '1/10'

    rule.hide_entries = False
    monitor.handle_database_change(('added', 'root/test2_loop', 10))
    assert (monitor.monitored_entries == ['root/test_loop',
                                          'root/test2_index',
                                          'root/test_index',
                                          'root/test2_loop'])
    assert len(monitor.displayed_entries) == 4
    assert not monitor.undisplayed_entries
    assert len(monitor.hidden_entries) == 2
    assert (monitor._database_values == {'root/test_loop': 10,
                                         'root/test2_index': 1,
                                         'root/test_index': 1,
                                         'root/test2_loop': 10})
    assert len(monitor.updaters['root/test2_loop']) == 2
    assert len(monitor.updaters['root/test2_index']) == 2