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