def test_data(self):
        model = ContinuousPalettesModel()
        model.items = ["Palettes", self.palette1, self.palette2]
        data = model.data
        index = model.index

        self.assertEqual(data(index(0, 0), Qt.EditRole), "Palettes")
        self.assertEqual(data(index(1, 0), Qt.EditRole),
                         self.palette1.friendly_name)
        self.assertEqual(data(index(2, 0), Qt.EditRole),
                         self.palette2.friendly_name)

        self.assertEqual(data(index(0, 0), Qt.DisplayRole), "Palettes")
        self.assertEqual(data(index(1, 0), Qt.DisplayRole),
                         self.palette1.friendly_name)
        self.assertEqual(data(index(2, 0), Qt.DisplayRole),
                         self.palette2.friendly_name)

        self.assertIsNone(data(index(0, 0), Qt.DecorationRole))
        with patch.object(self.palette1, "color_strip") as color_strip:
            self.assertIs(data(index(1, 0), Qt.DecorationRole),
                          color_strip.return_value)
        with patch.object(self.palette2, "color_strip") as color_strip:
            self.assertIs(data(index(2, 0), Qt.DecorationRole),
                          color_strip.return_value)

        self.assertIsNone(data(index(0, 0), Qt.UserRole))
        self.assertIs(data(index(1, 0), Qt.UserRole), self.palette1)
        self.assertIs(data(index(2, 0), Qt.UserRole), self.palette2)

        self.assertIsNone(data(index(2, 0), Qt.FontRole))
 def testIndexOf(self):
     model = ContinuousPalettesModel()
     model.items = ["Palettes", self.palette1, self.palette2]
     self.assertEqual(model.indexOf(self.palette1), 1)
     self.assertEqual(model.indexOf(self.palette1.name), 1)
     self.assertEqual(model.indexOf(self.palette1.friendly_name), 1)
     self.assertEqual(model.indexOf(self.palette2), 2)
     self.assertEqual(model.indexOf(self.palette2.name), 2)
     self.assertEqual(model.indexOf(self.palette2.friendly_name), 2)
     self.assertIsNone(model.indexOf(42))
 def test_select_flags(self):
     model = ContinuousPalettesModel()
     model.items = ["Palettes", self.palette1, self.palette2]
     self.assertFalse(model.flags(model.index(0, 0)) & Qt.ItemIsSelectable)
     self.assertTrue(model.flags(model.index(1, 0)) & Qt.ItemIsSelectable)
     self.assertTrue(model.flags(model.index(2, 0)) & Qt.ItemIsSelectable)
 def test_count(self):
     model = ContinuousPalettesModel()
     model.items = [self.palette1, self.palette1]
     self.assertEqual(model.rowCount(QModelIndex()), 2)
     self.assertEqual(model.columnCount(QModelIndex()), 1)