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' """ colormap = Colormap._fromDict({'name': 'toto'}) self.assertTrue(colormap.getVMin() is None) colormap = Colormap._fromDict({'colors': numpy.zeros(10)}) self.assertTrue(colormap.getName() is None) with self.assertRaises(ValueError): Colormap._fromDict({})
def testUnknowNorm(self): """Make sure an error is raised if the given normalization is not knowed """ clm_dict = { 'name': 'temperature', 'vmin': 1.0, 'vmax': 2.0, 'normalization': 'toto', 'colors': None, 'autoscale': False } with self.assertRaises(ValueError): Colormap._fromDict(clm_dict)
def testSetValidDict(self): """Test that if a colormap is created from a dict then it is correctly created and the values are copied (so if some values from the dict is changing, this won't affect the Colormap object""" clm_dict = { 'name': 'temperature', 'vmin': 1.0, 'vmax': 2.0, 'normalization': 'linear', 'colors': None, 'autoscale': False } # Test that the colormap is correctly created colormapObject = Colormap._fromDict(clm_dict) self.assertTrue(colormapObject.getName() == clm_dict['name']) self.assertTrue(colormapObject.getColormapLUT() == clm_dict['colors']) self.assertTrue(colormapObject.getVMin() == clm_dict['vmin']) self.assertTrue(colormapObject.getVMax() == clm_dict['vmax']) self.assertTrue(colormapObject.isAutoscale() == clm_dict['autoscale']) # Check that the colormap has copied the values clm_dict['vmin'] = None clm_dict['vmax'] = None clm_dict['colors'] = [1.0, 2.0] clm_dict['autoscale'] = True clm_dict['normalization'] = Colormap.LOGARITHM clm_dict['name'] = 'viridis' self.assertFalse(colormapObject.getName() == clm_dict['name']) self.assertFalse(colormapObject.getColormapLUT() == clm_dict['colors']) self.assertFalse(colormapObject.getVMin() == clm_dict['vmin']) self.assertFalse(colormapObject.getVMax() == clm_dict['vmax']) self.assertFalse(colormapObject.isAutoscale() == clm_dict['autoscale'])