def _assert_model_rows_equal( model: QtCore.QAbstractItemModel, expected: List[Any], role: int = QtCore.Qt.DisplayRole, ): num_rows = model.rowCount() actual = [model.data(model.index(row, 0), role) for row in range(num_rows)] assert actual == expected
def _assert_model_data_equal( model: QtCore.QAbstractItemModel, expected: List[List[Any]], role: int = QtCore.Qt.DisplayRole, ): num_rows = model.rowCount() num_cols = model.columnCount() actual = [[ model.data(model.index(row, column), role) for column in range(num_cols) ] for row in range(num_rows)] assert actual == expected
def context_append_row(model: QAbstractItemModel, num_row: int): """Helper, context manager that add N rows at the end of a model.""" row_count = model.rowCount() model.beginInsertRows(QModelIndex(), row_count, row_count + num_row - 1) yield model.endInsertRows()