def test_remove_variable(qtbot): """Test removing of the correct variable.""" variables = {'a': 1, 'b': 2, 'c': 3, 'd': '4', 'e': 5} editor = CollectionsEditorTableView(None, variables.copy()) qtbot.addWidget(editor) editor.setCurrentIndex(editor.model.index(1, 0)) editor.remove_item(force=True) assert editor.model.rowCount() == 4 assert data(editor.model, 0, 0) == 'a' assert data(editor.model, 1, 0) == 'c' assert data(editor.model, 2, 0) == 'd' assert data(editor.model, 3, 0) == 'e' # Reset variables and try removing one again editor.set_data(variables.copy()) editor.adjust_columns() editor.setCurrentIndex(editor.model.index(1, 0)) editor.remove_item(force=True) assert editor.model.rowCount() == 4 assert data(editor.model, 0, 0) == 'a' assert data(editor.model, 1, 0) == 'c' assert data(editor.model, 2, 0) == 'd' assert data(editor.model, 3, 0) == 'e'
def test_rename_and_duplicate_item_in_collection_editor(): collections = {'list': ([1, 2, 3], False, True), 'tuple': ((1, 2, 3), False, False), 'dict': ({'a': 1, 'b': 2}, True, True)} for coll, rename_enabled, duplicate_enabled in collections.values(): coll_copy = copy.copy(coll) editor = CollectionsEditorTableView(None, coll) assert editor.rename_action.isEnabled() assert editor.duplicate_action.isEnabled() editor.setCurrentIndex(editor.model.index(0, 0)) editor.refresh_menu() assert editor.rename_action.isEnabled() == rename_enabled assert editor.duplicate_action.isEnabled() == duplicate_enabled if isinstance(coll, list): editor.duplicate_item() assert editor.source_model.get_data() == coll_copy + [coll_copy[0]]
def test_rename_and_duplicate_item_in_collection_editor(): collections = {'list': ([1, 2, 3], False, True), 'tuple': ((1, 2, 3), False, False), 'dict': ({'a': 1, 'b': 2}, True, True)} for coll, rename_enabled, duplicate_enabled in collections.values(): coll_copy = copy.copy(coll) editor = CollectionsEditorTableView(None, coll) assert editor.rename_action.isEnabled() assert editor.duplicate_action.isEnabled() editor.setCurrentIndex(editor.model.createIndex(0, 0)) editor.refresh_menu() assert editor.rename_action.isEnabled() == rename_enabled assert editor.duplicate_action.isEnabled() == duplicate_enabled if isinstance(coll, list): editor.duplicate_item() assert editor.model.get_data() == coll_copy + [coll_copy[0]]