|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +def test_setup(_rpi_ws281x): |
| 5 | + from rpi_ws281x import PixelStrip |
| 6 | + strip = PixelStrip(10, 20) |
| 7 | + strip.begin() |
| 8 | + |
| 9 | + |
| 10 | +def test_setup_init_fail(_rpi_ws281x): |
| 11 | + from rpi_ws281x import PixelStrip |
| 12 | + _rpi_ws281x.ws2811_init.return_value = 1 |
| 13 | + strip = PixelStrip(10, 20) |
| 14 | + with pytest.raises(RuntimeError): |
| 15 | + strip.begin() |
| 16 | + |
| 17 | + |
| 18 | +def test_num_pixels(_rpi_ws281x): |
| 19 | + from rpi_ws281x import PixelStrip |
| 20 | + strip = PixelStrip(10, 20) |
| 21 | + strip.begin() |
| 22 | + assert len(strip[:]) == 10 |
| 23 | + assert len(strip) == 10 |
| 24 | + assert strip.numPixels() == 10 |
| 25 | + |
| 26 | + |
| 27 | +def test_set_pixel(_rpi_ws281x): |
| 28 | + from rpi_ws281x import PixelStrip, RGBW |
| 29 | + strip = PixelStrip(10, 20) |
| 30 | + strip.begin() |
| 31 | + strip[0] = RGBW(255, 0, 0) |
| 32 | + assert strip[0] == strip.getPixelColor(0) |
| 33 | + assert strip[0] == RGBW(255, 0, 0) |
| 34 | + assert strip.getPixelColorRGB(0) == RGBW(255, 0, 0) |
| 35 | + assert strip.getPixelColorRGBW(0) == RGBW(255, 0, 0) |
| 36 | + assert strip.getPixelColorRGBW(0).r == 255 |
| 37 | + |
| 38 | + |
| 39 | +def test_set_multiple(_rpi_ws281x): |
| 40 | + from rpi_ws281x import PixelStrip, RGBW |
| 41 | + strip = PixelStrip(10, 20) |
| 42 | + strip.begin() |
| 43 | + strip[:] = RGBW(255, 0, 0) |
| 44 | + assert strip[:] == [RGBW(255, 0, 0)] * 10 |
| 45 | + |
| 46 | + |
| 47 | +def test_set_odd(_rpi_ws281x): |
| 48 | + from rpi_ws281x import PixelStrip, RGBW |
| 49 | + strip = PixelStrip(10, 20) |
| 50 | + strip.begin() |
| 51 | + strip[::2] = RGBW(255, 0, 0) |
| 52 | + assert strip[:] == [RGBW(255, 0, 0), RGBW(0, 0, 0)] * 5 |
0 commit comments