def test_use_mapping_invalid(self):
        lcm = LocationColorMap(testimage)
        lcm.use_mapping = True
        lcm.use_mapping = False

        try:
            lcm.use_mapping = ""
            self.fail("Succeeded setting an invalid value for LocationColorMap.use_mapping")
        except TypeError:
            pass

        try:
            lcm.use_mapping = None
            self.fail("Succeeded setting an invalid value for LocationColorMap.use_mapping")
        except TypeError:
            pass
 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))