diff options
author | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2019-12-23 13:45:09 +0100 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2019-12-23 13:45:09 +0100 |
commit | 5d647cf9a6159afd2933da594b9c79ad93d3cd9b (patch) | |
tree | 2571025a602f68fc8933b01104dc712d41f84034 /silx/gui/test | |
parent | 654a6ac93513c3cc1ef97cacd782ff674c6f4559 (diff) |
New upstream version 0.12.0~b0+dfsg
Diffstat (limited to 'silx/gui/test')
-rwxr-xr-x[-rw-r--r--] | silx/gui/test/test_colors.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/silx/gui/test/test_colors.py b/silx/gui/test/test_colors.py index 6e4fc73..12387a3 100644..100755 --- 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)) |