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_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_noreplace_duplicate(): a_dict = SortableDict() a_dict[1] = 'a' try: a_dict.add_item(1, 'a2', replace=False) assert False, 'Replaced/inserted duplicate key' except KeyError: pass
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')]