test_apa102.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (c) 2014-18 Richard Hull and contributors
  4. # See LICENSE.rst for details.
  5. from luma.led_matrix.device import apa102
  6. from luma.core.render import canvas
  7. from helpers import serial, setup_function # noqa: F401
  8. def padding(n):
  9. return [0] * n * 4
  10. def test_init_cascaded():
  11. device = apa102(serial, cascaded=7)
  12. assert device.width == 7
  13. assert device.height == 1
  14. serial.data.assert_called_with(padding(7) + [0xE0, 0, 0, 0] * 7 + padding(7))
  15. def test_hide():
  16. device = apa102(serial, cascaded=5)
  17. serial.reset_mock()
  18. device.hide()
  19. serial.data.assert_not_called()
  20. def test_show():
  21. device = apa102(serial, cascaded=5)
  22. serial.reset_mock()
  23. device.show()
  24. serial.data.assert_not_called()
  25. def test_contrast():
  26. device = apa102(serial, cascaded=6)
  27. with canvas(device) as draw:
  28. draw.rectangle(device.bounding_box, outline="red")
  29. serial.reset_mock()
  30. device.contrast(0x6B)
  31. serial.data.assert_called_with(padding(6) + [0xE6, 0, 0, 0xFF] * 6 + padding(6))
  32. def test_display():
  33. device = apa102(serial, width=4, height=1)
  34. serial.reset_mock()
  35. with canvas(device) as draw:
  36. draw.rectangle(device.bounding_box, outline=(0x11, 0x22, 0x33, 0x44))
  37. serial.data.assert_called_with(padding(4) + [0xE4, 0x33, 0x22, 0x11] * 4 + padding(4))