Exemple #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'])
Exemple #2
0
    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])
Exemple #3
0
    def test_batch_set_data(self):
        """Test the batch_set_data() method of MinimalTableModel."""
        model = MinimalTableModel()

        n_rows = 3
        model.insertRows(0, n_rows)
        n_columns = 3
        model.insertColumns(0, n_columns)
        background = n_rows * n_columns * ['0xdeadbeef']
        indices = list()
        for row in range(n_rows):
            for column in range(n_columns):
                indices.append(model.index(row, column))

        def _handle_data_changed(top_left, bottom_right, roles):
            self.assertEqual(top_left, indices[0])
            self.assertEqual(bottom_right, indices[-1])
            self.assertTrue(Qt.EditRole in roles)
            self.assertTrue(Qt.DisplayRole in roles)

        model.dataChanged.connect(_handle_data_changed)
        self.assertTrue(model.batch_set_data(indices, background))
        for row in range(n_rows):
            for column in range(n_columns):
                index = model.index(row, column)
                self.assertEqual(model.data(index), '0xdeadbeef')
Exemple #4
0
 def test_flags(self):
     """Test the flags() method of MinimalTableModel."""
     model = MinimalTableModel()
     model.insertColumns(0, 1)
     model.insertRows(0, 1)
     index = model.index(0, 0)
     flags = model.flags(index)
     self.assertEqual(
         flags, Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable)
Exemple #5
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)
Exemple #6
0
 def test_row_data(self):
     """Test the row_data() method of MinimalTableModel."""
     model = MinimalTableModel()
     model.insertRows(0, 1)
     n_columns = 3
     model.insertColumns(0, n_columns - 1)
     data = ['a', 'b', 'c']
     for column in range(n_columns):
         index = model.index(0, column)
         model.setData(index, data[column])
     self.assertEqual(model.row_data(0), data)
Exemple #7
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)