summaryrefslogtreecommitdiff
path: root/silx/gui/test
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-05-28 08:16:16 +0200
committerPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-05-28 08:16:16 +0200
commita763e5d1b3921b3194f3d4e94ab9de3fbe08bbdd (patch)
tree45d462ed36a5522e9f3b9fde6c4ec4918c2ae8e3 /silx/gui/test
parentcebdc9244c019224846cb8d2668080fe386a6adc (diff)
New upstream version 0.10.1+dfsg
Diffstat (limited to 'silx/gui/test')
-rw-r--r--silx/gui/test/test_colors.py110
1 files changed, 91 insertions, 19 deletions
diff --git a/silx/gui/test/test_colors.py b/silx/gui/test/test_colors.py
index e980068..2f883bc 100644
--- a/silx/gui/test/test_colors.py
+++ b/silx/gui/test/test_colors.py
@@ -29,14 +29,13 @@ from __future__ import absolute_import
__authors__ = ["H.Payno"]
__license__ = "MIT"
-__date__ = "05/10/2018"
+__date__ = "09/11/2018"
import unittest
import numpy
from silx.utils.testutils import ParametricTestCase
from silx.gui import colors
from silx.gui.colors import Colormap
-from silx.gui.colors import preferredColormaps, setPreferredColormaps
from silx.utils.exceptions import NotEditableError
@@ -158,12 +157,12 @@ class TestDictAPI(unittest.TestCase):
self.assertFalse(colormapObject.isAutoscale() == clm_dict['autoscale'])
def testMissingKeysFromDict(self):
- """Make sure we can create a Colormap object from a dictionnary even if
- there is missing keys excepts if those keys are 'colors' or 'name'
+ """Make sure we can create a Colormap object from a dictionary even if
+ there is missing keys except if those keys are 'colors' or 'name'
"""
- colormap = Colormap._fromDict({'name': 'toto'})
+ colormap = Colormap._fromDict({'name': 'blue'})
self.assertTrue(colormap.getVMin() is None)
- colormap = Colormap._fromDict({'colors': numpy.zeros(10)})
+ colormap = Colormap._fromDict({'colors': numpy.zeros((5, 3))})
self.assertTrue(colormap.getName() is None)
with self.assertRaises(ValueError):
@@ -227,15 +226,17 @@ class TestObjectAPI(ParametricTestCase):
def testCopy(self):
"""Make sure the copy function is correctly processing
"""
- colormapObject = Colormap(name='toto',
- colors=numpy.array([12, 13, 14]),
+ colormapObject = Colormap(name='red',
+ colors=numpy.array([[1., 0., 0.],
+ [0., 1., 0.],
+ [0., 0., 1.]]),
vmin=None,
vmax=None,
normalization=Colormap.LOGARITHM)
colormapObject2 = colormapObject.copy()
self.assertTrue(colormapObject == colormapObject2)
- colormapObject.setColormapLUT(numpy.array([0, 1]))
+ colormapObject.setColormapLUT([[0, 0, 0], [255, 255, 255]])
self.assertFalse(colormapObject == colormapObject2)
colormapObject2 = colormapObject.copy()
@@ -361,7 +362,7 @@ class TestObjectAPI(ParametricTestCase):
with self.assertRaises(NotEditableError):
colormap.setName('magma')
with self.assertRaises(NotEditableError):
- colormap.setColormapLUT(numpy.array([0, 1]))
+ colormap.setColormapLUT([[0., 0., 0.], [1., 1., 1.]])
with self.assertRaises(NotEditableError):
colormap._setFromDict(colormap._toDict())
state = colormap.saveState()
@@ -371,7 +372,28 @@ class TestObjectAPI(ParametricTestCase):
def testBadColorsType(self):
"""Make sure colors can't be something else than an array"""
with self.assertRaises(TypeError):
- Colormap(name='temperature', colors=256)
+ Colormap(colors=256)
+
+ def testEqual(self):
+ colormap1 = Colormap()
+ colormap2 = Colormap()
+ self.assertEqual(colormap1, colormap2)
+
+ def testCompareString(self):
+ colormap = Colormap()
+ self.assertNotEqual(colormap, "a")
+
+ def testCompareNone(self):
+ colormap = Colormap()
+ self.assertNotEqual(colormap, None)
+
+ def testSet(self):
+ colormap = Colormap()
+ other = Colormap(name="viridis", vmin=1, vmax=2, normalization=Colormap.LOGARITHM)
+ self.assertNotEqual(colormap, other)
+ colormap.setFromColormap(other)
+ self.assertIsNot(colormap, other)
+ self.assertEqual(colormap, other)
class TestPreferredColormaps(unittest.TestCase):
@@ -379,27 +401,76 @@ class TestPreferredColormaps(unittest.TestCase):
def setUp(self):
# Save preferred colormaps
- self._colormaps = preferredColormaps()
+ self._colormaps = colors.preferredColormaps()
def tearDown(self):
# Restore saved preferred colormaps
- setPreferredColormaps(self._colormaps)
+ colors.setPreferredColormaps(self._colormaps)
def test(self):
colormaps = 'viridis', 'magma'
- setPreferredColormaps(colormaps)
- self.assertEqual(preferredColormaps(), colormaps)
+ colors.setPreferredColormaps(colormaps)
+ self.assertEqual(colors.preferredColormaps(), colormaps)
with self.assertRaises(ValueError):
- setPreferredColormaps(())
+ colors.setPreferredColormaps(())
with self.assertRaises(ValueError):
- setPreferredColormaps(('This is not a colormap',))
+ colors.setPreferredColormaps(('This is not a colormap',))
colormaps = 'red', 'green'
- setPreferredColormaps(('This is not a colormap',) + colormaps)
- self.assertEqual(preferredColormaps(), colormaps)
+ colors.setPreferredColormaps(('This is not a colormap',) + colormaps)
+ self.assertEqual(colors.preferredColormaps(), colormaps)
+
+
+class TestRegisteredLut(unittest.TestCase):
+ """Test get|setPreferredColormaps functions"""
+
+ def setUp(self):
+ # Save preferred colormaps
+ lut = numpy.arange(8 * 3)
+ lut.shape = -1, 3
+ lut = lut / (8.0 * 3)
+ colors.registerLUT("test_8", colors=lut, cursor_color='blue')
+
+ def testColormap(self):
+ colormap = Colormap("test_8")
+ self.assertIsNotNone(colormap)
+
+ def testCursor(self):
+ color = colors.cursorColorForColormap("test_8")
+ self.assertEqual(color, 'blue')
+
+ def testLut(self):
+ colormap = Colormap("test_8")
+ colors = colormap.getNColors(8)
+ self.assertEquals(len(colors), 8)
+
+ def testUint8(self):
+ lut = numpy.array([[255, 0, 0], [200, 0, 0], [150, 0, 0]], dtype="uint")
+ colors.registerLUT("test_type", lut)
+ colormap = colors.Colormap(name="test_type")
+ lut = colormap.getNColors(3)
+ self.assertEqual(lut.shape, (3, 4))
+ self.assertEqual(lut[0, 0], 255)
+
+ def testFloatRGB(self):
+ lut = numpy.array([[1.0, 0, 0], [0.5, 0, 0], [0, 0, 0]], dtype="float")
+ colors.registerLUT("test_type", lut)
+ colormap = colors.Colormap(name="test_type")
+ lut = colormap.getNColors(3)
+ self.assertEqual(lut.shape, (3, 4))
+ self.assertEqual(lut[0, 0], 255)
+
+ def testFloatRGBA(self):
+ lut = numpy.array([[1.0, 0, 0, 128 / 256.0], [0.5, 0, 0, 1.0], [0.0, 0, 0, 1.0]], dtype="float")
+ colors.registerLUT("test_type", lut)
+ colormap = colors.Colormap(name="test_type")
+ lut = colormap.getNColors(3)
+ self.assertEqual(lut.shape, (3, 4))
+ self.assertEqual(lut[0, 0], 255)
+ self.assertEqual(lut[0, 3], 128)
def suite():
@@ -410,6 +481,7 @@ def suite():
test_suite.addTest(loadTests(TestDictAPI))
test_suite.addTest(loadTests(TestObjectAPI))
test_suite.addTest(loadTests(TestPreferredColormaps))
+ test_suite.addTest(loadTests(TestRegisteredLut))
return test_suite