def test_create_30x10_rainbow_image(self): size = (29, 10) effect = RainbowEffect(size) start_color = Color(127, 255, 63) end_color = Color(255, 0, 180) effect.draw_vertical_rainbow(start_color, end_color) image = effect.get_image() self.assertEqual(image.getpixel((0, 5)), start_color.get_as_tuple()) self.assertEqual(image.getpixel((28, 9)), end_color.get_as_tuple()) self.assertEqual(image.getpixel((14, 0)), (191, 127, 121))
def test_create_3x2_rainbow_image(self): size = (3, 2) effect = RainbowEffect(size) start_color = Color(255, 0, 0) end_color = Color(0, 0, 255) effect.draw_vertical_rainbow(start_color, end_color) image = effect.get_image() self.assertEqual(image.getpixel((0, 0)), start_color.get_as_tuple()) self.assertEqual(image.getpixel((2, 1)), end_color.get_as_tuple()) self.assertEqual(image.getpixel((1, 1)), (127, 0, 127))
class TestDevice(unittest.TestCase): def setUp(self): self.red = Color(255, 0, 0) self.green = Color(0, 255, 0) self.blue = Color(0, 0, 255) self.stripe_factory = MockStripeFactory() def create_stripe_and_device(self, size): device = Ws281xDevice(self.stripe_factory, size) stripe = self.stripe_factory.get_stripe() return stripe, device def test_3x1_panel(self): size = (3, 1) stripe, device = self.create_stripe_and_device(size) image = ImageFactory.create_rgb_image(size) image.putpixel((0, 0), self.red.get_as_tuple()) image.putpixel((1, 0), self.green.get_as_tuple()) image.putpixel((2, 0), self.blue.get_as_tuple()) device.display_frame(image) self.assertEqual(stripe.getPixelColor(0), self.red.get_as_int()) self.assertEqual(stripe.getPixelColor(1), self.green.get_as_int()) self.assertEqual(stripe.getPixelColor(2), self.blue.get_as_int()) def test_3x2_panel(self): size = (3, 2) stripe, device = self.create_stripe_and_device(size) image = ImageFactory.create_rgb_image(size) image.putpixel((0, 0), self.red.get_as_tuple()) image.putpixel((1, 0), self.green.get_as_tuple()) image.putpixel((2, 0), self.blue.get_as_tuple()) image.putpixel((0, 1), self.red.get_as_tuple()) image.putpixel((1, 1), self.green.get_as_tuple()) image.putpixel((2, 1), self.blue.get_as_tuple()) device.display_frame(image) self.assertEqual(stripe.getPixelColor(5), self.red.get_as_int()) self.assertEqual(stripe.getPixelColor(4), self.green.get_as_int()) self.assertEqual(stripe.getPixelColor(3), self.blue.get_as_int())