def test_removeColumns(self): """Test the removeColumns() method of MinimalTableModel.""" model = MinimalTableModel() self.assertFalse(model.removeColumns(-1, 1)) self.assertFalse(model.removeColumns(0, 1)) model.insertRows(0, 1) model.insertColumns(0, 4) data = ['a', 'b', 'c', 'd', 'e'] for column, value in enumerate(data): index = model.index(0, column) model.setData(index, value) self.assertTrue(model.removeColumns(4, 1)) self.assertEqual(model.columnCount(), 4) def check_data(expecteds): for column, expected in enumerate(expecteds): index = model.index(0, column) self.assertEqual(model.data(index), expected) check_data(['a', 'b', 'c', 'd']) self.assertTrue(model.removeColumns(0, 1)) self.assertEqual(model.columnCount(), 3) check_data(['b', 'c', 'd']) self.assertTrue(model.removeColumns(1, 1)) self.assertEqual(model.columnCount(), 2) check_data(['b', 'd'])
def test_insertColumns(self): """Test the insertColumns() method of MinimalTableModel.""" model = MinimalTableModel() model.insertRows(0, 1) self.assertEqual(model.columnCount(), 1) index = model.index(0, 0) model.setData(index, 'a') self.assertTrue(model.insertColumns(0, 1)) self.assertEqual(model.columnCount(), 2) def check_data(expecteds): for column, expected in enumerate(expecteds): index = model.index(0, column) if expected is not None: self.assertEqual(model.data(index), expected) else: self.assertIsNone(model.data(index)) check_data([None, 'a']) index = model.index(0, 0) model.setData(index, 'b') self.assertTrue(model.insertColumns(1, 1)) self.assertEqual(model.columnCount(), 3) check_data(['b', None, 'a']) index = model.index(0, 1) model.setData(index, 'c') self.assertTrue(model.insertColumns(3, 1)) self.assertEqual(model.columnCount(), 4) check_data(['b', 'c', 'a', None])
def test_columnCount(self): """Test the columnCount() method of MinimalTableModel.""" model = MinimalTableModel() self.assertEqual(model.columnCount(), 0) model.insertRows(0, 1) self.assertEqual(model.columnCount(), 1) model.insertColumns(0, 13) self.assertEqual(model.columnCount(), 14) model.removeColumns(0, 1) self.assertEqual(model.columnCount(), 13)
def test_clear(self): """Test the clear() method of MinimalTableModel.""" model = MinimalTableModel() model.insertColumns(0, 1) model.insertRows(0, 1) index = model.index(0, 0) model.setData(index, 23) self.assertEqual(model.rowCount(), 1) self.assertEqual(model.columnCount(), 1) model.clear() self.assertEqual(model.rowCount(), 0) self.assertEqual(model.columnCount(), 0)