File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import pytest
2+
3+
4+ @pytest .mark .skip ("Requires CAN interface setup" )
5+ def test_can_send ():
6+ pass
Original file line number Diff line number Diff line change 1+ import RPi .GPIO as GPIO
2+ import pytest
3+ import time
4+
5+
6+ @pytest .fixture (scope = "module" , autouse = True )
7+ def setup_gpio_module ():
8+ GPIO .setmode (GPIO .BCM )
9+ yield
10+ GPIO .cleanup ()
11+
12+
13+ def test_gpio_library_available ():
14+ assert hasattr (GPIO , "setup" )
15+
16+
17+ def test_gpio_high_low ():
18+
19+ test_pin = 17
20+ GPIO .setup (test_pin , GPIO .OUT )
21+
22+ GPIO .output (test_pin , GPIO .HIGH )
23+ time .sleep (0.1 )
24+
25+ assert GPIO .input (test_pin ) == GPIO .HIGH
26+
27+ GPIO .output (test_pin , GPIO .LOW )
28+ time .sleep (0.1 )
29+
30+ assert GPIO .input (test_pin ) == GPIO .LOW
31+
32+
33+ def test_gpio_loopback ():
34+
35+ out_pin = 17
36+ in_pin = 27
37+
38+ GPIO .setup (out_pin , GPIO .OUT )
39+ GPIO .setup (in_pin , GPIO .IN )
40+
41+ GPIO .output (out_pin , GPIO .HIGH )
42+ time .sleep (0.1 )
43+
44+ assert GPIO .input (in_pin ) == GPIO .HIGH
45+
46+ GPIO .output (out_pin , GPIO .LOW )
47+ time .sleep (0.1 )
48+
49+ assert GPIO .input (in_pin ) == GPIO .LOW
Original file line number Diff line number Diff line change 1+ import smbus
2+ import pytest
3+
4+
5+ def test_i2c_library_available ():
6+
7+ bus = smbus .SMBus (1 )
8+ assert bus is not None
9+
10+
11+ def test_i2c_scan ():
12+
13+ bus = smbus .SMBus (1 )
14+
15+ devices = []
16+
17+ for addr in range (0x03 , 0x77 ):
18+ try :
19+ bus .write_quick (addr )
20+ devices .append (addr )
21+ except :
22+ pass
23+
24+ assert isinstance (devices , list )
Original file line number Diff line number Diff line change 1+ import spidev
2+ import pytest
3+
4+
5+ def test_spi_library_available ():
6+ spi = spidev .SpiDev ()
7+ assert spi is not None
8+
9+
10+ def test_spi_open ():
11+
12+ spi = spidev .SpiDev ()
13+
14+ spi .open (0 , 0 ) # SPI bus 0, device 0
15+ spi .max_speed_hz = 500000
16+
17+ response = spi .xfer2 ([0x00 ])
18+
19+ spi .close ()
20+
21+ assert isinstance (response , list )
You can’t perform that action at this time.
0 commit comments