def test_replacing_item_preserves_order(self): item_list = IdList() item1 = Item('id1') item2 = Item('id2') item3 = Item('id3') item4 = Item('id4') item_list.add(item1) item_list.add(item2) item_list.add(item3) item_list.replace('id2', item4) assert item_list.items == [item1, item4, item3]
def test_replace_not_present_item_raises_exception(self): item_list = IdList() with pytest.raises(KeyError): item_list.replace('id_doesnt_exist', Item('id1'))