test_unicornhathd.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (c) 2014-19 Richard Hull and contributors
  4. # See LICENSE.rst for details.
  5. from luma.led_matrix.device import unicornhathd
  6. from luma.core.render import canvas
  7. from helpers import serial
  8. from baseline_data import get_json_data
  9. def test_init():
  10. device = unicornhathd(serial)
  11. assert device.width == 16
  12. assert device.height == 16
  13. serial.data.assert_called_once_with([0x72] + [0] * 256 * 3)
  14. def test_hide():
  15. device = unicornhathd(serial)
  16. serial.reset_mock()
  17. device.hide()
  18. serial.data.assert_called_once_with([0x72] + [0] * 256 * 3)
  19. def test_show():
  20. device = unicornhathd(serial)
  21. device.contrast(0xFF)
  22. with canvas(device) as draw:
  23. draw.rectangle(device.bounding_box, outline="white", fill="white")
  24. device.hide()
  25. serial.reset_mock()
  26. device.show()
  27. serial.data.assert_called_once_with([0x72] + [0xFF] * 256 * 3)
  28. def test_contrast():
  29. device = unicornhathd(serial)
  30. with canvas(device) as draw:
  31. draw.rectangle(device.bounding_box, outline="white", fill="white")
  32. serial.reset_mock()
  33. device.contrast(0x6B)
  34. serial.data.assert_called_once_with([0x72] + [0x6B] * 256 * 3)
  35. def test_display():
  36. device = unicornhathd(serial)
  37. serial.reset_mock()
  38. with canvas(device) as draw:
  39. draw.rectangle(device.bounding_box, outline="white")
  40. serial.data.assert_called_once_with([0x72] + get_json_data('demo_unicornhathd'))
  41. def test_alpha_blending():
  42. device = unicornhathd(serial)
  43. serial.reset_mock()
  44. with canvas(device) as draw:
  45. draw.rectangle(device.bounding_box, outline=(255, 128, 64, 32))
  46. serial.data.assert_called_once_with([0x72] + get_json_data('demo_unicornhathd_alphablend'))