Esempio n. 1
0
    def test_removeRows(self):
        """Test the removeRows() method of MinimalTableModel."""
        model = MinimalTableModel()
        self.assertFalse(model.removeRows(-1, 1))
        self.assertFalse(model.removeRows(0, 1))
        data = ['a', 'b', 'c', 'd', 'e']
        model.insertRows(0, len(data))
        for row, value in enumerate(data):
            index = model.index(row, 0)
            model.setData(index, value)
        self.assertTrue(model.removeRows(1, 2))
        self.assertEqual(model.rowCount(), 3)

        def check_data(expecteds):
            for row, expected in enumerate(expecteds):
                index = model.index(row, 0)
                self.assertEqual(model.data(index), expected)

        check_data(['a', 'd', 'e'])
        self.assertTrue(model.removeRows(2, 1))
        self.assertEqual(model.rowCount(), 2)
        check_data(['a', 'd'])
        self.assertTrue(model.removeRows(0, 1))
        self.assertEqual(model.rowCount(), 1)
        check_data(['d'])
        self.assertTrue(model.removeRows(0, 1))
        self.assertEqual(model.rowCount(), 0)
Esempio n. 2
0
    def test_insertRows(self):
        """Test the insertRows() method of MinimalTableModel."""
        model = MinimalTableModel()
        self.assertEqual(model.rowCount(), 0)
        self.assertFalse(model.insertRows(1, 1))
        self.assertTrue(model.insertRows(0, 2))
        self.assertEqual(model.rowCount(), 2)

        def check_data(expecteds):
            for row, expected in enumerate(expecteds):
                index = model.index(row, 0)
                if expected is not None:
                    self.assertEqual(model.data(index), expected)
                else:
                    self.assertIsNone(model.data(index))

        index = model.index(0, 0)
        model.setData(index, 'a')
        index = model.index(1, 0)
        model.setData(index, 'b')
        self.assertTrue(model.insertRows(1, 1))
        self.assertEqual(model.rowCount(), 3)
        check_data(['a', None, 'b'])
        index = model.index(1, 0)
        model.setData(index, 'c')
        self.assertTrue(model.insertRows(3, 1))
        self.assertEqual(model.rowCount(), 4)
        check_data(['a', 'c', 'b', None])
Esempio n. 3
0
 def test_rowCount(self):
     """Test the rowCount() method of MinimalTableModel."""
     model = MinimalTableModel()
     self.assertEqual(model.rowCount(), 0)
     model.insertRows(0, 1)
     self.assertEqual(model.rowCount(), 1)
     model.insertRows(1, 10)
     self.assertEqual(model.rowCount(), 11)
     model.removeRows(0, 5)
     self.assertEqual(model.rowCount(), 6)
Esempio n. 4
0
 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)