Skip to content

Commit ca80eb9

Browse files
committed
QA: Add basic tests.
1 parent 685fc4d commit ca80eb9

File tree

3 files changed

+64
-14
lines changed

3 files changed

+64
-14
lines changed

.gitignore

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
__pycache__/
1+
build/
2+
_build/
3+
*.o
4+
*.so
5+
*.a
26
*.py[cod]
7+
*.egg-info
38
dist/
4-
sdist/
5-
env/
6-
build/
7-
develop-eggs/
8-
eggs/
9-
*.egg-info/
10-
.installed.cfg
11-
*.egg
9+
__pycache__
10+
.DS_Store
1211
*.deb
1312
*.dsc
1413
*.build
1514
*.changes
1615
*.orig.*
17-
library/debian/
1816
packaging/*tar.xz
19-
pip-log.txt
20-
pip-delete-this-directory.txt
21-
.DS_Store
22-
17+
library/debian/
18+
.coverage
19+
.pytest_cache
20+
.tox

tests/conftest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
import mock
4+
import pytest
5+
6+
7+
@pytest.fixture(scope="function", autouse=True)
8+
def cleanup():
9+
yield
10+
del sys.modules["cap1xxx"]
11+
12+
13+
@pytest.fixture(scope="function")
14+
def smbus2():
15+
sys.modules["smbus2"] = mock.MagicMock()
16+
yield sys.modules["smbus2"]
17+
del sys.modules["smbus2"]
18+
19+
20+
@pytest.fixture(scope="function")
21+
def gpio():
22+
sys.modules["RPi"] = mock.Mock()
23+
sys.modules["RPi.GPIO"] = mock.MagicMock()
24+
yield
25+
del sys.modules["RPi"]
26+
del sys.modules["RPi.GPIO"]

tests/test_setup.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
3+
4+
def test_setup(gpio, smbus2):
5+
import cap1xxx
6+
7+
smbus2.SMBus(1).read_byte_data.return_value = cap1xxx.PID_CAP1208
8+
cap1208 = cap1xxx.Cap1208()
9+
assert cap1208.number_of_leds == 8
10+
11+
smbus2.SMBus(1).read_byte_data.return_value = cap1xxx.PID_CAP1188
12+
cap1188 = cap1xxx.Cap1188()
13+
assert cap1188.number_of_leds == 8
14+
15+
smbus2.SMBus(1).read_byte_data.return_value = cap1xxx.PID_CAP1166
16+
cap1166 = cap1xxx.Cap1166()
17+
assert cap1166.number_of_leds == 6
18+
19+
20+
def test_setup_invalid_pid(gpio, smbus2):
21+
import cap1xxx
22+
23+
smbus2.SMBus(1).read_byte_data.return_value = 0x00
24+
25+
with pytest.raises(RuntimeError):
26+
_ = cap1xxx.Cap1208()

0 commit comments

Comments
 (0)