コード例 #1
0
 def test_setModel(self):
     w = ColorGradientSelection()
     model = QStringListModel(["A", "B"])
     w.setModel(model)
     self.assertIs(w.model(), model)
     self.assertEqual(w.findData("B", Qt.DisplayRole), 1)
     current = QSignalSpy(w.currentIndexChanged)
     w.setCurrentIndex(1)
     self.assertEqual(w.currentIndex(), 1)
     self.assertSequenceEqual(list(current), [[1]])
コード例 #2
0
    def test_center_visibility(self):
        w = ColorGradientSelection(center=0)
        w.center_box.setVisible = Mock()
        model = itemmodels.ContinuousPalettesModel()
        w.setModel(model)
        for row in range(model.rowCount(QModelIndex())):
            palette = model.data(model.index(row, 0), Qt.UserRole)
            if palette:
                if palette.flags & palette.Diverging:
                    diverging = row
                else:
                    nondiverging = row

        w.setCurrentIndex(diverging)
        w.center_box.setVisible.assert_called_with(True)
        w.setCurrentIndex(nondiverging)
        w.center_box.setVisible.assert_called_with(False)
        w.setCurrentIndex(diverging)
        w.center_box.setVisible.assert_called_with(True)

        w = ColorGradientSelection()
        self.assertIsNone(w.center_box)