コード例 #1
0
    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'])
コード例 #2
0
 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)