From 5d647cf9a6159afd2933da594b9c79ad93d3cd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Picca=20Fr=C3=A9d=C3=A9ric-Emmanuel?= Date: Mon, 23 Dec 2019 13:45:09 +0100 Subject: New upstream version 0.12.0~b0+dfsg --- silx/gui/test/test_colors.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) mode change 100644 => 100755 silx/gui/test/test_colors.py (limited to 'silx/gui/test') diff --git a/silx/gui/test/test_colors.py b/silx/gui/test/test_colors.py old mode 100644 new mode 100755 index 6e4fc73..12387a3 --- a/silx/gui/test/test_colors.py +++ b/silx/gui/test/test_colors.py @@ -39,28 +39,39 @@ from silx.gui.colors import Colormap from silx.utils.exceptions import NotEditableError -class TestRGBA(ParametricTestCase): +class TestColor(ParametricTestCase): """Basic tests of rgba function""" + TEST_COLORS = { # name: (colors, expected values) + 'blue': ('blue', (0., 0., 1., 1.)), + '#010203': ('#010203', (1. / 255., 2. / 255., 3. / 255., 1.)), + '#01020304': ('#01020304', (1. / 255., 2. / 255., 3. / 255., 4. / 255.)), + '3 x uint8': (numpy.array((1, 255, 0), dtype=numpy.uint8), + (1 / 255., 1., 0., 1.)), + '4 x uint8': (numpy.array((1, 255, 0, 1), dtype=numpy.uint8), + (1 / 255., 1., 0., 1 / 255.)), + '3 x float overflow': ((3., 0.5, 1.), (1., 0.5, 1., 1.)), + } + def testRGBA(self): """"Test rgba function with accepted values""" - tests = { # name: (colors, expected values) - 'blue': ('blue', (0., 0., 1., 1.)), - '#010203': ('#010203', (1. / 255., 2. / 255., 3. / 255., 1.)), - '#01020304': ('#01020304', (1. / 255., 2. / 255., 3. / 255., 4. / 255.)), - '3 x uint8': (numpy.array((1, 255, 0), dtype=numpy.uint8), - (1 / 255., 1., 0., 1.)), - '4 x uint8': (numpy.array((1, 255, 0, 1), dtype=numpy.uint8), - (1 / 255., 1., 0., 1 / 255.)), - '3 x float overflow': ((3., 0.5, 1.), (1., 0.5, 1., 1.)), - } - - for name, test in tests.items(): + for name, test in self.TEST_COLORS.items(): color, expected = test with self.subTest(msg=name): result = colors.rgba(color) self.assertEqual(result, expected) + def testQColor(self): + """"Test getQColor function with accepted values""" + for name, test in self.TEST_COLORS.items(): + color, expected = test + with self.subTest(msg=name): + result = colors.asQColor(color) + self.assertAlmostEqual(result.redF(), expected[0], places=4) + self.assertAlmostEqual(result.greenF(), expected[1], places=4) + self.assertAlmostEqual(result.blueF(), expected[2], places=4) + self.assertAlmostEqual(result.alphaF(), expected[3], places=4) + class TestApplyColormapToData(ParametricTestCase): """Tests of applyColormapToData function""" @@ -477,7 +488,7 @@ def suite(): test_suite = unittest.TestSuite() loadTests = unittest.defaultTestLoader.loadTestsFromTestCase test_suite.addTest(loadTests(TestApplyColormapToData)) - test_suite.addTest(loadTests(TestRGBA)) + test_suite.addTest(loadTests(TestColor)) test_suite.addTest(loadTests(TestDictAPI)) test_suite.addTest(loadTests(TestObjectAPI)) test_suite.addTest(loadTests(TestPreferredColormaps)) -- cgit v1.2.3