Beispiel #1
0
def test_restore_selection_with_previous_selection():
    # By default, we try to restore the selection that was there before a refresh
    table = TestGUITable(10)
    table.refresh()
    table.selected_indexes = [2, 4]
    table.refresh()
    eq_(table.selected_indexes, [2, 4])
Beispiel #2
0
def test_footer_replaces_old_footer():
    table, footer = table_with_footer()
    other = Row(table)
    table.footer = other
    assert table.footer is other
    eq_(len(table), 2)
    assert table[1] is other
Beispiel #3
0
def test_restore_selection_with_previous_selection():
    # By default, we try to restore the selection that was there before a refresh
    table = TestGUITable(10)
    table.refresh()
    table.selected_indexes = [2, 4]
    table.refresh()
    eq_(table.selected_indexes, [2, 4])
Beispiel #4
0
def test_header_replaces_old_header():
    table, header = table_with_header()
    other = Row(table)
    table.header = other
    assert table.header is other
    eq_(len(table), 2)
    assert table[0] is other
Beispiel #5
0
def test_findall_dont_include_self():
    # When calling findall with include_self=False, the node itself is never evaluated.
    t = tree_with_some_nodes()
    del t._name  # so that if the predicate is called on `t`, we crash
    r = t.findall(lambda n: not n.name.startswith('sub'),
                  include_self=False)  # no crash
    eq_(set(r), set([t[0], t[1], t[2]]))
Beispiel #6
0
def test_row_cell_value():
    # *_cell_value() correctly mangles attrnames that are Python reserved words.
    row = Row(Table())
    row.from_ = 'foo'
    eq_(row.get_cell_value('from'), 'foo')
    row.set_cell_value('from', 'bar')
    eq_(row.get_cell_value('from'), 'bar')
def test_selection_range():
    # selection is correctly adjusted on deletion
    sl = SelectableList(['foo', 'bar', 'baz'])
    sl.selected_index = 3
    eq_(sl.selected_index, 2)
    del sl[2]
    eq_(sl.selected_index, 1)
Beispiel #8
0
def test_row_cell_value():
    # *_cell_value() correctly mangles attrnames that are Python reserved words.
    row = Row(Table())
    row.from_ = 'foo'
    eq_(row.get_cell_value('from'), 'foo')
    row.set_cell_value('from', 'bar')
    eq_(row.get_cell_value('from'), 'bar')
Beispiel #9
0
def test_selection_range():
    # selection is correctly adjusted on deletion
    sl = SelectableList(['foo', 'bar', 'baz'])
    sl.selected_index = 3
    eq_(sl.selected_index, 2)
    del sl[2]
    eq_(sl.selected_index, 1)
Beispiel #10
0
def test_footer_replaces_old_footer():
    table, footer = table_with_footer()
    other = Row(table)
    table.footer = other
    assert table.footer is other
    eq_(len(table), 2)
    assert table[1] is other
Beispiel #11
0
def test_header_replaces_old_header():
    table, header = table_with_header()
    other = Row(table)
    table.header = other
    assert table.header is other
    eq_(len(table), 2)
    assert table[0] is other
Beispiel #12
0
def test_restore_selection_custom():
    # After a _fill() called, the virtual _restore_selection() is called so that it's possible for a
    # GUITable subclass to customize its post-refresh selection behavior.
    class MyTable(TestGUITable):
        def _restore_selection(self, previous_selection):
            self.selected_indexes = [6]

    table = MyTable(10)
    table.refresh()
    eq_(table.selected_indexes, [6])
Beispiel #13
0
def test_restore_selection_custom():
    # After a _fill() called, the virtual _restore_selection() is called so that it's possible for a
    # GUITable subclass to customize its post-refresh selection behavior.
    class MyTable(TestGUITable):
        def _restore_selection(self, previous_selection):
            self.selected_indexes = [6]

    table = MyTable(10)
    table.refresh()
    eq_(table.selected_indexes, [6])
def test_update_selection_called():
    # _update_selection_is called after a change in selection. However, we only do so on select()
    # calls. I follow the old behavior of the Table class. At the moment, I don't quite remember
    # why there was a specific select() method for triggering _update_selection(), but I think I
    # remember there was a reason, so I keep it that way.
    sl = SelectableList(['foo', 'bar'])
    sl._update_selection = callcounter()
    sl.select(1)
    eq_(sl._update_selection.callcount, 1)
    sl.selected_index = 0
    eq_(sl._update_selection.callcount, 1) # no call
Beispiel #15
0
def test_update_selection_called():
    # _update_selection_is called after a change in selection. However, we only do so on select()
    # calls. I follow the old behavior of the Table class. At the moment, I don't quite remember
    # why there was a specific select() method for triggering _update_selection(), but I think I
    # remember there was a reason, so I keep it that way.
    sl = SelectableList(['foo', 'bar'])
    sl._update_selection = callcounter()
    sl.select(1)
    eq_(sl._update_selection.callcount, 1)
    sl.selected_index = 0
    eq_(sl._update_selection.callcount, 1)  # no call
Beispiel #16
0
def test_restore_selection_after_cancel_edits():
    # _restore_selection() is called after cancel_edits(). Previously, only _update_selection would
    # be called.
    class MyTable(TestGUITable):
        def _restore_selection(self, previous_selection):
            self.selected_indexes = [6]

    table = MyTable(10)
    table.refresh()
    table.add()
    table.cancel_edits()
    eq_(table.selected_indexes, [6])
Beispiel #17
0
def test_restore_selection_after_cancel_edits():
    # _restore_selection() is called after cancel_edits(). Previously, only _update_selection would
    # be called.
    class MyTable(TestGUITable):
        def _restore_selection(self, previous_selection):
            self.selected_indexes = [6]

    table = MyTable(10)
    table.refresh()
    table.add()
    table.cancel_edits()
    eq_(table.selected_indexes, [6])
Beispiel #18
0
def test_select_one_node():
    t = tree_with_some_nodes()
    t.selected_node = t[0][0]
    assert t.selected_node is t[0][0]
    eq_(t.selected_nodes, [t[0][0]])
    eq_(t.selected_path, [0, 0])
    eq_(t.selected_paths, [[0, 0]])
Beispiel #19
0
def test_select_one_node():
    t = tree_with_some_nodes()
    t.selected_node = t[0][0]
    assert t.selected_node is t[0][0]
    eq_(t.selected_nodes, [t[0][0]])
    eq_(t.selected_path, [0, 0])
    eq_(t.selected_paths, [[0, 0]])
Beispiel #20
0
def test_sort_table_updates_selection():
    table = TestGUITable(10)
    table.refresh()
    table.select([2, 4])
    table.sort_by('index', desc=True)
    # Now, the updated rows should be 7 and 5
    eq_(len(table.updated_rows), 2)
    r1, r2 = table.updated_rows
    eq_(r1.index, 7)
    eq_(r2.index, 5)
Beispiel #21
0
def test_sort_table_updates_selection():
    table = TestGUITable(10)
    table.refresh()
    table.select([2, 4])
    table.sort_by('index', desc=True)
    # Now, the updated rows should be 7 and 5
    eq_(len(table.updated_rows), 2)
    r1, r2 = table.updated_rows
    eq_(r1.index, 7)
    eq_(r2.index, 5)
Beispiel #22
0
def test_header_stays_there_on_insert():
    # Inserting another row at the top puts it below the header
    table, header = table_with_header()
    table.insert(0, Row(table))
    eq_(len(table), 3)
    assert table[0] is header
Beispiel #23
0
def test_select_multiple_paths():
    t = tree_with_some_nodes()
    t.selected_paths = [[0], [1]]
    eq_(t.selected_nodes, [t[0], t[1]])
Beispiel #24
0
def test_restore_selection():
    # By default, after a refresh, selection goes on the last row
    table = TestGUITable(10)
    table.refresh()
    eq_(table.selected_indexes, [9])
Beispiel #25
0
def test_header_setting_to_none_removes_old_one():
    table, header = table_with_header()
    table.header = None
    assert table.header is None
    eq_(len(table), 1)
Beispiel #26
0
def test_findall():
    t = tree_with_some_nodes()
    r = t.findall(lambda n: n.name.startswith('sub'))
    eq_(set(r), set([t[0][0], t[0][1]]))
Beispiel #27
0
def test_header_del_row():
    # Removing the header row sets it to None
    table, header = table_with_header()
    del table[0]
    assert table.header is None
    eq_(len(table), 1)
Beispiel #28
0
def test_footer_stays_there_on_append():
    # Appending another row puts it above the footer
    table, footer = table_with_footer()
    table.append(Row(table))
    eq_(len(table), 3)
    assert table[2] is footer
Beispiel #29
0
def test_findall_dont_include_self():
    # When calling findall with include_self=False, the node itself is never evaluated.
    t = tree_with_some_nodes()
    del t._name # so that if the predicate is called on `t`, we crash
    r = t.findall(lambda n: not n.name.startswith('sub'), include_self=False) # no crash
    eq_(set(r), set([t[0], t[1], t[2]]))
Beispiel #30
0
def test_footer_del_row():
    # Removing the footer row sets it to None
    table, footer = table_with_footer()
    del table[-1]
    assert table.footer is None
    eq_(len(table), 1)
Beispiel #31
0
def test_footer_stays_there_on_insert():
    # Inserting another row puts it above the footer
    table, footer = table_with_footer()
    table.insert(3, Row(table))
    eq_(len(table), 3)
    assert table[2] is footer
Beispiel #32
0
def test_selection():
    t = tree_with_some_nodes()
    assert t.selected_node is None
    eq_(t.selected_nodes, [])
    assert t.selected_path is None
    eq_(t.selected_paths, [])
Beispiel #33
0
def test_header_del_row():
    # Removing the header row sets it to None
    table, header = table_with_header()
    del table[0]
    assert table.header is None
    eq_(len(table), 1)
Beispiel #34
0
def test_header_is_inserted_in_table():
    # A header is inserted at the table's top
    table, header = table_with_header()
    eq_(len(table), 2)
    assert table[0] is header
Beispiel #35
0
def test_header_rows_and_row_count():
    # rows() and row_count() ignore header.
    table, header = table_with_header()
    eq_(table.row_count, 1)
    eq_(table.rows, table[1:])
Beispiel #36
0
def test_header_setting_to_none_removes_old_one():
    table, header = table_with_header()
    table.header = None
    assert table.header is None
    eq_(len(table), 1)
Beispiel #37
0
def test_footer_is_appened_to_table():
    # A footer is appended at the table's bottom
    table, footer = table_with_footer()
    eq_(len(table), 2)
    assert table[1] is footer
Beispiel #38
0
def test_select_none_node():
    # setting selected_node to None clears the selection
    t = Tree()
    t.selected_node = None
    eq_(t.selected_nodes, [])
Beispiel #39
0
def test_footer_rows_and_row_count():
    # rows() and row_count() ignore footer.
    table, footer = table_with_footer()
    eq_(table.row_count, 1)
    eq_(table.rows, table[:-1])
Beispiel #40
0
def test_findall():
    t = tree_with_some_nodes()
    r = t.findall(lambda n: n.name.startswith('sub'))
    eq_(set(r), set([t[0][0], t[0][1]]))
Beispiel #41
0
def test_footer_stays_there_on_insert():
    # Inserting another row puts it above the footer
    table, footer = table_with_footer()
    table.insert(3, Row(table))
    eq_(len(table), 3)
    assert table[2] is footer
Beispiel #42
0
def test_footer_stays_there_on_append():
    # Appending another row puts it above the footer
    table, footer = table_with_footer()
    table.append(Row(table))
    eq_(len(table), 3)
    assert table[2] is footer
Beispiel #43
0
def test_header_is_inserted_in_table():
    # A header is inserted at the table's top
    table, header = table_with_header()
    eq_(len(table), 2)
    assert table[0] is header
Beispiel #44
0
def test_footer_rows_and_row_count():
    # rows() and row_count() ignore footer.
    table, footer = table_with_footer()
    eq_(table.row_count, 1)
    eq_(table.rows, table[:-1])
Beispiel #45
0
def test_header_rows_and_row_count():
    # rows() and row_count() ignore header.
    table, header = table_with_header()
    eq_(table.row_count, 1)
    eq_(table.rows, table[1:])
def test_search_by_prefix():
    sl = SelectableList(['foo', 'bAr', 'baZ'])
    eq_(sl.search_by_prefix('b'), 1)
    eq_(sl.search_by_prefix('BA'), 1)
    eq_(sl.search_by_prefix('BAZ'), 2)
    eq_(sl.search_by_prefix('BAZZ'), -1)
Beispiel #47
0
def test_header_stays_there_on_insert():
    # Inserting another row at the top puts it below the header
    table, header = table_with_header()
    table.insert(0, Row(table))
    eq_(len(table), 3)
    assert table[0] is header
Beispiel #48
0
def test_footer_is_appened_to_table():
    # A footer is appended at the table's bottom
    table, footer = table_with_footer()
    eq_(len(table), 2)
    assert table[1] is footer
Beispiel #49
0
def test_select_none_node():
    # setting selected_node to None clears the selection
    t = Tree()
    t.selected_node = None
    eq_(t.selected_nodes, [])
Beispiel #50
0
def test_footer_del_row():
    # Removing the footer row sets it to None
    table, footer = table_with_footer()
    del table[-1]
    assert table.footer is None
    eq_(len(table), 1)
Beispiel #51
0
def test_search_by_prefix():
    sl = SelectableList(['foo', 'bAr', 'baZ'])
    eq_(sl.search_by_prefix('b'), 1)
    eq_(sl.search_by_prefix('BA'), 1)
    eq_(sl.search_by_prefix('BAZ'), 2)
    eq_(sl.search_by_prefix('BAZZ'), -1)
Beispiel #52
0
def test_restore_selection():
    # By default, after a refresh, selection goes on the last row
    table = TestGUITable(10)
    table.refresh()
    eq_(table.selected_indexes, [9])
Beispiel #53
0
def test_select_multiple_paths():
    t = tree_with_some_nodes()
    t.selected_paths = [[0], [1]]
    eq_(t.selected_nodes, [t[0], t[1]])
Beispiel #54
0
def test_selection():
    t = tree_with_some_nodes()
    assert t.selected_node is None
    eq_(t.selected_nodes, [])
    assert t.selected_path is None
    eq_(t.selected_paths, [])