def test_valid_percentages_hsl(self): """Test 0% and 100% in the HSL colorspace.""" white = utils.interpolate_color(self.white, self.black, 0, QColor.Hsl) black = utils.interpolate_color(self.white, self.black, 100, QColor.Hsl) assert Color(white) == self.white assert Color(black) == self.black
def test_valid_percentages_hsv(self, colors): """Test 0% and 100% in the HSV colorspace.""" white = utils.interpolate_color(colors.white, colors.black, 0, QColor.Hsv) black = utils.interpolate_color(colors.white, colors.black, 100, QColor.Hsv) assert Color(white) == colors.white assert Color(black) == colors.black
def test_0_100(self, colors, colorspace): """Test 0% and 100% in different colorspaces.""" white = utils.interpolate_color(colors.white, colors.black, 0, colorspace) black = utils.interpolate_color(colors.white, colors.black, 100, colorspace) assert Color(white) == colors.white assert Color(black) == colors.black
def test_interpolation_hsl(self): """Test an interpolation in the HSL colorspace.""" start = Color() stop = Color() start.setHsl(0, 40, 100) stop.setHsl(0, 20, 200) color = utils.interpolate_color(start, stop, 50, QColor.Hsl) expected = Color() expected.setHsl(0, 30, 150) assert Color(color) == expected
def test_interpolation_rgb(self): """Test an interpolation in the RGB colorspace.""" color = utils.interpolate_color(Color(0, 40, 100), Color(0, 20, 200), 50, QColor.Rgb) assert Color(color) == Color(0, 30, 150)
def test_invalid_colorspace(self, colors): """Test an invalid colorspace.""" with pytest.raises(ValueError): utils.interpolate_color(colors.white, colors.black, 10, QColor.Cmyk)
def test_invalid_percentage(self, colors, perc): """Test an invalid percentage.""" with pytest.raises(ValueError): utils.interpolate_color(colors.white, colors.white, perc)
def test_invalid_end(self, colors): """Test an invalid end color.""" with pytest.raises(qtutils.QtValueError): utils.interpolate_color(colors.white, Color(), 0)
def test_invalid_start(self, colors): """Test an invalid start color.""" with pytest.raises(qtutils.QtValueError): utils.interpolate_color(Color(), colors.white, 0)
def test_interpolation_none(self, percentage, expected): """Test an interpolation with a gradient turned off.""" color = utils.interpolate_color(Color(0, 0, 0), Color(255, 255, 255), percentage, None) assert isinstance(color, QColor) assert Color(color) == Color(*expected)
def test_invalid_percentage(self): """Test an invalid percentage.""" with pytest.raises(ValueError): utils.interpolate_color(self.white, self.white, -1) with pytest.raises(ValueError): utils.interpolate_color(self.white, self.white, 101)