tests: Clean up test_utils

This commit is contained in:
Florian Bruhin 2016-08-20 22:39:33 +02:00
parent 5bdeacd772
commit bd53d4a410

View File

@ -296,12 +296,11 @@ class TestInterpolateColor:
with pytest.raises(qtutils.QtValueError): with pytest.raises(qtutils.QtValueError):
utils.interpolate_color(colors.white, Color(), 0) utils.interpolate_color(colors.white, Color(), 0)
def test_invalid_percentage(self, colors): @pytest.mark.parametrize('perc', [-1, 101])
def test_invalid_percentage(self, colors, perc):
"""Test an invalid percentage.""" """Test an invalid percentage."""
with pytest.raises(ValueError): with pytest.raises(ValueError):
utils.interpolate_color(colors.white, colors.white, -1) utils.interpolate_color(colors.white, colors.white, perc)
with pytest.raises(ValueError):
utils.interpolate_color(colors.white, colors.white, 101)
def test_invalid_colorspace(self, colors): def test_invalid_colorspace(self, colors):
"""Test an invalid colorspace.""" """Test an invalid colorspace."""
@ -309,30 +308,14 @@ class TestInterpolateColor:
utils.interpolate_color(colors.white, colors.black, 10, utils.interpolate_color(colors.white, colors.black, 10,
QColor.Cmyk) QColor.Cmyk)
def test_valid_percentages_rgb(self, colors): @pytest.mark.parametrize('colorspace', [QColor.Rgb, QColor.Hsv,
"""Test 0% and 100% in the RGB colorspace.""" QColor.Hsl])
def test_0_100(self, colors, colorspace):
"""Test 0% and 100% in different colorspaces."""
white = utils.interpolate_color(colors.white, colors.black, 0, white = utils.interpolate_color(colors.white, colors.black, 0,
QColor.Rgb) colorspace)
black = utils.interpolate_color(colors.white, colors.black, 100, black = utils.interpolate_color(colors.white, colors.black, 100,
QColor.Rgb) colorspace)
assert Color(white) == colors.white
assert Color(black) == colors.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_valid_percentages_hsl(self, colors):
"""Test 0% and 100% in the HSL colorspace."""
white = utils.interpolate_color(colors.white, colors.black, 0,
QColor.Hsl)
black = utils.interpolate_color(colors.white, colors.black, 100,
QColor.Hsl)
assert Color(white) == colors.white assert Color(white) == colors.white
assert Color(black) == colors.black assert Color(black) == colors.black
@ -866,22 +849,17 @@ class TestRaises:
"""Helper function which does nothing.""" """Helper function which does nothing."""
pass pass
def test_raises_single_exc_true(self): @pytest.mark.parametrize('exception, value, expected', [
(ValueError, 'a', True),
((ValueError, TypeError), 'a', True),
((ValueError, TypeError), None, True),
(ValueError, '1', False),
((ValueError, TypeError), 1, False),
])
def test_raises_int(self, exception, value, expected):
"""Test raises with a single exception which gets raised.""" """Test raises with a single exception which gets raised."""
assert utils.raises(ValueError, int, 'a') assert utils.raises(exception, int, value) == expected
def test_raises_single_exc_false(self):
"""Test raises with a single exception which does not get raised."""
assert not utils.raises(ValueError, int, '1')
def test_raises_multiple_exc_true(self):
"""Test raises with multiple exceptions which get raised."""
assert utils.raises((ValueError, TypeError), int, 'a')
assert utils.raises((ValueError, TypeError), int, None)
def test_raises_multiple_exc_false(self):
"""Test raises with multiple exceptions which do not get raised."""
assert not utils.raises((ValueError, TypeError), int, '1')
def test_no_args_true(self): def test_no_args_true(self):
"""Test with no args and an exception which gets raised.""" """Test with no args and an exception which gets raised."""