From bd53d4a410273eee859b1296954f1d5c6fee02f3 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 20 Aug 2016 22:39:33 +0200 Subject: [PATCH] tests: Clean up test_utils --- tests/unit/utils/test_utils.py | 60 +++++++++++----------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/tests/unit/utils/test_utils.py b/tests/unit/utils/test_utils.py index 9947c56bd..0df217034 100644 --- a/tests/unit/utils/test_utils.py +++ b/tests/unit/utils/test_utils.py @@ -296,12 +296,11 @@ class TestInterpolateColor: with pytest.raises(qtutils.QtValueError): 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.""" with pytest.raises(ValueError): - utils.interpolate_color(colors.white, colors.white, -1) - with pytest.raises(ValueError): - utils.interpolate_color(colors.white, colors.white, 101) + utils.interpolate_color(colors.white, colors.white, perc) def test_invalid_colorspace(self, colors): """Test an invalid colorspace.""" @@ -309,30 +308,14 @@ class TestInterpolateColor: utils.interpolate_color(colors.white, colors.black, 10, QColor.Cmyk) - def test_valid_percentages_rgb(self, colors): - """Test 0% and 100% in the RGB colorspace.""" + @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 = utils.interpolate_color(colors.white, colors.black, 0, - QColor.Rgb) + colorspace) black = utils.interpolate_color(colors.white, colors.black, 100, - QColor.Rgb) - 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) + colorspace) assert Color(white) == colors.white assert Color(black) == colors.black @@ -866,22 +849,17 @@ class TestRaises: """Helper function which does nothing.""" 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.""" - assert utils.raises(ValueError, int, 'a') - - 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') + assert utils.raises(exception, int, value) == expected def test_no_args_true(self): """Test with no args and an exception which gets raised."""