def test_pop_at(): a_dict = SortableDict() a_dict['a'] = 1 a_dict['b'] = 2 a_dict['c'] = 3 assert a_dict.pop_at(1) == 2 assert list(a_dict.items()) == [('a', 1), ('c', 3)]
def test_reverse(): a_dict = SortableDict() a_dict['a'] = 1 a_dict['b'] = 2 a_dict['c'] = 3 a_dict.reverse() assert list(a_dict.items()) == [('c', 3), ('b', 2), ('a', 1)]
def test_add_item_replace(): a_dict = SortableDict() a_dict[1] = 'a' a_dict[2] = 'b' a_dict[3] = 'c' a_dict.add_item(1, 'd', replace=True) assert list(a_dict.items()) == [(1, 'd'), (2, 'b'), (3, 'c')]
def test_add_item_move(): a_dict = SortableDict() a_dict[1] = 'a' a_dict[2] = 'b' a_dict[3] = 'c' a_dict.add_item(1, 'a', after=True, pos_key=3) assert list(a_dict.items()) == [(2, 'b'), (3, 'c'), (1, 'a')]
def test_grid_given_column_dict(): cols = SortableDict([('col1', [('c1m1', None), ('c1m2', None)]), ('col2', [('c2m1', None), ('c2m2', None)])]) grid = Grid(columns=cols) assert list(grid.column.keys()) == ['col1', 'col2'] for col, meta in cols.items(): assert list(grid.column[col].items()) == meta
def test_sort(): a_dict = SortableDict() a_dict['t'] = 1 a_dict['d'] = 2 a_dict['h'] = 3 a_dict['x'] = 4 a_dict.sort() assert list(a_dict.items()) == [('d', 2), ('h', 3), ('t', 1), ('x', 4)]
def test_add_item_after(): a_dict = SortableDict() a_dict[1] = 'a' a_dict[2] = 'b' a_dict.add_item(3, 'c', after=True, pos_key=1) assert list(a_dict.items()) == [(1, 'a'), (3, 'c'), (2, 'b')]