diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-02-10 18:44:27 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-02-10 18:44:27 +0100 |
commit | 588ff43ac857631bbacc3ecf27564a0166d16ca1 (patch) | |
tree | 0d7bc56999e632032c4c31aba9333d99f445dd8d /tests/unit/utils/test_qtutils.py | |
parent | 71ac42488ed78c8d9b0fe907b033edb3f7ebff2c (diff) | |
download | qutebrowser-588ff43ac857631bbacc3ecf27564a0166d16ca1.tar.gz qutebrowser-588ff43ac857631bbacc3ecf27564a0166d16ca1.zip |
tests: Move Color to testutils
Diffstat (limited to 'tests/unit/utils/test_qtutils.py')
-rw-r--r-- | tests/unit/utils/test_qtutils.py | 63 |
1 files changed, 26 insertions, 37 deletions
diff --git a/tests/unit/utils/test_qtutils.py b/tests/unit/utils/test_qtutils.py index eb1233332..745f35b5a 100644 --- a/tests/unit/utils/test_qtutils.py +++ b/tests/unit/utils/test_qtutils.py @@ -34,6 +34,7 @@ from PyQt5.QtGui import QColor from qutebrowser.utils import qtutils, utils, usertypes import overflow_test_cases +from tests import utils as testutils if utils.is_linux: # Those are not run on macOS because that seems to cause a hang sometimes. @@ -941,38 +942,28 @@ class TestEventLoop: assert not self.loop._executing -class Color(QColor): - - """A QColor with a nicer repr().""" - - def __repr__(self): - return utils.get_repr(self, constructor=True, red=self.red(), - green=self.green(), blue=self.blue(), - alpha=self.alpha()) - - class TestInterpolateColor: @dataclasses.dataclass class Colors: - white: Color - black: Color + white: testutils.Color + black: testutils.Color @pytest.fixture def colors(self): """Example colors to be used.""" - return self.Colors(Color('white'), Color('black')) + return self.Colors(testutils.Color('white'), testutils.Color('black')) def test_invalid_start(self, colors): """Test an invalid start color.""" with pytest.raises(qtutils.QtValueError): - qtutils.interpolate_color(Color(), colors.white, 0) + qtutils.interpolate_color(testutils.Color(), colors.white, 0) def test_invalid_end(self, colors): """Test an invalid end color.""" with pytest.raises(qtutils.QtValueError): - qtutils.interpolate_color(colors.white, Color(), 0) + qtutils.interpolate_color(colors.white, testutils.Color(), 0) @pytest.mark.parametrize('perc', [-1, 101]) def test_invalid_percentage(self, colors, perc): @@ -985,52 +976,50 @@ class TestInterpolateColor: with pytest.raises(ValueError): qtutils.interpolate_color(colors.white, colors.black, 10, QColor.Cmyk) - @pytest.mark.parametrize('colorspace', [QColor.Rgb, QColor.Hsv, - QColor.Hsl]) + @pytest.mark.parametrize('colorspace', [QColor.Rgb, QColor.Hsv, QColor.Hsl]) def test_0_100(self, colors, colorspace): """Test 0% and 100% in different colorspaces.""" white = qtutils.interpolate_color(colors.white, colors.black, 0, colorspace) black = qtutils.interpolate_color(colors.white, colors.black, 100, colorspace) - assert Color(white) == colors.white - assert Color(black) == colors.black + assert testutils.Color(white) == colors.white + assert testutils.Color(black) == colors.black def test_interpolation_rgb(self): """Test an interpolation in the RGB colorspace.""" color = qtutils.interpolate_color( - Color(0, 40, 100), Color(0, 20, 200), 50, QColor.Rgb) - assert Color(color) == Color(0, 30, 150) + testutils.Color(0, 40, 100), testutils.Color(0, 20, 200), 50, QColor.Rgb) + assert testutils.Color(color) == testutils.Color(0, 30, 150) def test_interpolation_hsv(self): """Test an interpolation in the HSV colorspace.""" - start = Color() - stop = Color() + start = testutils.Color() + stop = testutils.Color() start.setHsv(0, 40, 100) stop.setHsv(0, 20, 200) color = qtutils.interpolate_color(start, stop, 50, QColor.Hsv) - expected = Color() + expected = testutils.Color() expected.setHsv(0, 30, 150) - assert Color(color) == expected + assert testutils.Color(color) == expected def test_interpolation_hsl(self): """Test an interpolation in the HSL colorspace.""" - start = Color() - stop = Color() + start = testutils.Color() + stop = testutils.Color() start.setHsl(0, 40, 100) stop.setHsl(0, 20, 200) color = qtutils.interpolate_color(start, stop, 50, QColor.Hsl) - expected = Color() + expected = testutils.Color() expected.setHsl(0, 30, 150) - assert Color(color) == expected + assert testutils.Color(color) == expected - @pytest.mark.parametrize('colorspace', [QColor.Rgb, QColor.Hsv, - QColor.Hsl]) + @pytest.mark.parametrize('colorspace', [QColor.Rgb, QColor.Hsv, QColor.Hsl]) def test_interpolation_alpha(self, colorspace): """Test interpolation of colorspace's alpha.""" - start = Color(0, 0, 0, 30) - stop = Color(0, 0, 0, 100) + start = testutils.Color(0, 0, 0, 30) + stop = testutils.Color(0, 0, 0, 100) color = qtutils.interpolate_color(start, stop, 50, colorspace) - expected = Color(0, 0, 0, 65) - assert Color(color) == expected + expected = testutils.Color(0, 0, 0, 65) + assert testutils.Color(color) == expected @pytest.mark.parametrize('percentage, expected', [ (0, (0, 0, 0)), @@ -1040,6 +1029,6 @@ class TestInterpolateColor: def test_interpolation_none(self, percentage, expected): """Test an interpolation with a gradient turned off.""" color = qtutils.interpolate_color( - Color(0, 0, 0), Color(255, 255, 255), percentage, None) + testutils.Color(0, 0, 0), testutils.Color(255, 255, 255), percentage, None) assert isinstance(color, QColor) - assert Color(color) == Color(*expected) + assert testutils.Color(color) == testutils.Color(*expected) |