Skip to content

Commit c5c80df

Browse files
committed
new files
1 parent 28a8a93 commit c5c80df

4 files changed

Lines changed: 100 additions & 0 deletions

File tree

tests/test_can.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
3+
4+
@pytest.mark.skip("Requires CAN interface setup")
5+
def test_can_send():
6+
pass

tests/test_gpio.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

tests/test_i2c.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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)

tests/test_spi.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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)

0 commit comments

Comments
 (0)