def test_colormap_rgb(self): lcm = LocationColorMap([[(0,0,255), (0,255,0), (255,0,0)]]) lcm.colormap = "RGB" print("RGB colormap:") print(lcm.colormap) self.assertEqual(lcm.colormap[(0,0,255)], 255) self.assertEqual(lcm.colormap[(0,255,0)], 255*256) self.assertEqual(lcm.colormap[(255,0,0)], 255*256*256)
def test_colormap_default(self): lcm = LocationColorMap(testimage) lcm.colormap = "default" print("Default colormap:") print(lcm.colormap) self.assertEqual(lcm.colormap[(0,)], 0) self.assertEqual(lcm.colormap[(2,)], 1) self.assertEqual(lcm.colormap[(30,)], len(all_colors)-1)
def test_rgb_mapping(self): lcm = LocationColorMap([[(0,0,255), (0,255,0), (255,0,0), (1,2,4), (0,0,0)]]) lcm.colormap = "RGB" lcm.use_mapping = True self.assertEqual(lcm.get_color_at(-2, 0), 255) self.assertEqual(lcm.get_color_at(-1, 0), 255*256) self.assertEqual(lcm.get_color_at(0, 0), 255*256*256) self.assertEqual(lcm.get_color_at(1, 0), 4 + 2*256 + 1*256*256)
def test_get_mapped_colors(self): lcm = LocationColorMap(testimage) codes = dict(zip([(c,) for c in all_colors], all_colors)) # map each (c,) to c lcm.colormap = codes self.assertEqual(lcm.get_color_at(-3, -2, use_mapping=True), 0) lcm.use_mapping = True self.assertEqual(lcm.get_color_at(0, 0), 30) self.assertEqual(lcm.get_color_at(2, 1), 15) self.assertIsNone(lcm.get_color_at(4, 0)) self.assertIsNone(lcm.get_color_at(4, 0, use_mapping=True))
def test_colormap_missing_colors(self): lcm = LocationColorMap(testimage) codes = {} i = 0 for c in {0, 2, 5, 10}: codes[(c,)] = i i += 1 try: lcm.colormap = codes self.fail("Succeeded setting an invalid value") except ValueError: pass
def test_colormap_good(self): lcm = LocationColorMap(testimage) lcm.colormap = self.get_good_colormap()