Skip to content

Commit ca93f98

Browse files
committed
Prep for v0.0.1
1 parent 02f2914 commit ca93f98

File tree

5 files changed

+192
-192
lines changed

5 files changed

+192
-192
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
LIBRARY_VERSION=$(shell grep version library/setup.cfg | awk -F" = " '{print $$2}')
22
LIBRARY_NAME=$(shell grep name library/setup.cfg | awk -F" = " '{print $$2}')
3+
PACKAGE_NAME=$(shell grep packages library/setup.cfg | awk -F" = " '{print $$2}')
34

45
.PHONY: usage install uninstall
56
usage:
@@ -27,11 +28,11 @@ check:
2728
@echo "Checking for trailing whitespace"
2829
@! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
2930
@echo "Checking for DOS line-endings"
30-
@! grep -IUrn --color "" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
31+
@! grep -IlUrn --color "" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
3132
@echo "Checking library/CHANGELOG.txt"
3233
@cat library/CHANGELOG.txt | grep ^${LIBRARY_VERSION}
33-
@echo "Checking library/${LIBRARY_NAME}/__init__.py"
34-
@cat library/${LIBRARY_NAME}/__init__.py | grep "^__version__ = '${LIBRARY_VERSION}'"
34+
@echo "Checking library/${PACKAGE_NAME}/__init__.py"
35+
@cat library/${PACKAGE_NAME}/__init__.py | grep "^__version__ = '${LIBRARY_VERSION}'"
3536

3637
tag:
3738
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"

library/tests/conftest.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import sys
2-
import pytest
3-
import mock
4-
5-
6-
@pytest.fixture(scope='function', autouse=True)
7-
def cleanup():
8-
"""This fixture removes modules under test from sys.modules.
9-
10-
This ensures that each module is fully re-imported, along with
11-
the fixtures for each test function.
12-
13-
"""
14-
15-
yield None
16-
del sys.modules["mics6814"]
17-
18-
19-
@pytest.fixture(scope="function", autouse=False)
20-
def ioexpander():
21-
"""Mock the IOExpander library."""
22-
23-
ioexpander = mock.MagicMock()
24-
sys.modules["ioexpander"] = ioexpander
25-
yield ioexpander
26-
del sys.modules["ioexpander"]
27-
28-
29-
@pytest.fixture(scope="function", autouse=False)
30-
def smbus2():
31-
"""Mock smbus2 module."""
32-
33-
smbus2 = mock.MagicMock()
34-
smbus2.i2c_msg.read().__iter__.return_value = [0b00000000]
35-
sys.modules["smbus2"] = smbus2
36-
yield smbus2
37-
del sys.modules["smbus2"]
1+
import sys
2+
import pytest
3+
import mock
4+
5+
6+
@pytest.fixture(scope='function', autouse=True)
7+
def cleanup():
8+
"""This fixture removes modules under test from sys.modules.
9+
10+
This ensures that each module is fully re-imported, along with
11+
the fixtures for each test function.
12+
13+
"""
14+
15+
yield None
16+
del sys.modules["mics6814"]
17+
18+
19+
@pytest.fixture(scope="function", autouse=False)
20+
def ioexpander():
21+
"""Mock the IOExpander library."""
22+
23+
ioexpander = mock.MagicMock()
24+
sys.modules["ioexpander"] = ioexpander
25+
yield ioexpander
26+
del sys.modules["ioexpander"]
27+
28+
29+
@pytest.fixture(scope="function", autouse=False)
30+
def smbus2():
31+
"""Mock smbus2 module."""
32+
33+
smbus2 = mock.MagicMock()
34+
smbus2.i2c_msg.read().__iter__.return_value = [0b00000000]
35+
sys.modules["smbus2"] = smbus2
36+
yield smbus2
37+
del sys.modules["smbus2"]

library/tests/test_io.py

Lines changed: 127 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,127 @@
1-
import mock
2-
3-
4-
def test_set_heater(ioexpander):
5-
from mics6814 import MICS6814
6-
7-
mics6814 = MICS6814()
8-
9-
mics6814.set_heater(True)
10-
mics6814._ioe.output.assert_called_with(1, ioexpander.LOW)
11-
12-
mics6814.set_heater(False)
13-
mics6814._ioe.output.assert_called_with(1, ioexpander.HIGH)
14-
15-
16-
def test_disable_heater(ioexpander):
17-
from mics6814 import MICS6814
18-
19-
mics6814 = MICS6814()
20-
21-
mics6814.disable_heater()
22-
mics6814._ioe.output.assert_called_with(1, ioexpander.HIGH)
23-
mics6814._ioe.set_mode.assert_called_with(1, ioexpander.IN)
24-
25-
26-
def test_get_raw_ref(ioexpander):
27-
from mics6814 import MICS6814
28-
29-
mics6814 = MICS6814()
30-
31-
mics6814.get_raw_ref()
32-
mics6814._ioe.input.assert_called_with(14)
33-
34-
35-
def test_get_raw_red(ioexpander):
36-
from mics6814 import MICS6814
37-
38-
mics6814 = MICS6814()
39-
40-
mics6814.get_raw_red()
41-
mics6814._ioe.input.assert_called_with(12)
42-
43-
44-
def test_get_raw_nh3(ioexpander):
45-
from mics6814 import MICS6814
46-
47-
mics6814 = MICS6814()
48-
49-
mics6814.get_raw_nh3()
50-
mics6814._ioe.input.assert_called_with(11)
51-
52-
53-
def test_get_raw_oxd(ioexpander):
54-
from mics6814 import MICS6814
55-
56-
mics6814 = MICS6814()
57-
58-
mics6814.get_raw_oxd()
59-
mics6814._ioe.input.assert_called_with(13)
60-
61-
62-
def test_get_adc(ioexpander):
63-
from mics6814 import MICS6814
64-
65-
mics6814 = MICS6814()
66-
67-
mics6814.read_adc()
68-
69-
70-
def test_read_all(ioexpander):
71-
from mics6814 import MICS6814, Mics6814Reading
72-
73-
mics6814 = MICS6814()
74-
75-
mics6814._ioe.input.return_value = 2.5
76-
mics6814._ioe.get_adc_vref.return_value = 5.0
77-
78-
reading = mics6814.read_all()
79-
80-
assert type(reading) == Mics6814Reading
81-
mics6814._ioe.input.has_calls((
82-
mock.call(9),
83-
mock.call(12),
84-
mock.call(11),
85-
mock.call(13),
86-
))
87-
88-
assert "Oxidising" in str(reading)
89-
90-
91-
def test_read_oxd_red_nh3(ioexpander):
92-
from mics6814 import MICS6814
93-
94-
mics6814 = MICS6814()
95-
96-
mics6814._ioe.input.return_value = 2.5
97-
mics6814._ioe.get_adc_vref.return_value = 5.0
98-
99-
assert mics6814.read_oxidising() == 56000.0
100-
assert mics6814.read_reducing() == 56000.0
101-
assert mics6814.read_nh3() == 56000.0
102-
103-
104-
def test_read_oxd_red_nh3_zero_division(ioexpander):
105-
from mics6814 import MICS6814
106-
107-
mics6814 = MICS6814()
108-
109-
mics6814._ioe.input.return_value = 5.0
110-
mics6814._ioe.get_adc_vref.return_value = 5.0
111-
112-
assert mics6814.read_oxidising() == 0
113-
assert mics6814.read_reducing() == 0
114-
assert mics6814.read_nh3() == 0
115-
116-
117-
def test_set_led(ioexpander):
118-
from mics6814 import MICS6814
119-
120-
mics6814 = MICS6814()
121-
mics6814.set_led(255, 155, 55)
122-
123-
assert mics6814._ioe.output.has_calls((
124-
mock.call(3, 255),
125-
mock.call(7, 155),
126-
mock.call(2, 55)
127-
))
1+
import mock
2+
3+
4+
def test_set_heater(ioexpander):
5+
from mics6814 import MICS6814
6+
7+
mics6814 = MICS6814()
8+
9+
mics6814.set_heater(True)
10+
mics6814._ioe.output.assert_called_with(1, ioexpander.LOW)
11+
12+
mics6814.set_heater(False)
13+
mics6814._ioe.output.assert_called_with(1, ioexpander.HIGH)
14+
15+
16+
def test_disable_heater(ioexpander):
17+
from mics6814 import MICS6814
18+
19+
mics6814 = MICS6814()
20+
21+
mics6814.disable_heater()
22+
mics6814._ioe.output.assert_called_with(1, ioexpander.HIGH)
23+
mics6814._ioe.set_mode.assert_called_with(1, ioexpander.IN)
24+
25+
26+
def test_get_raw_ref(ioexpander):
27+
from mics6814 import MICS6814
28+
29+
mics6814 = MICS6814()
30+
31+
mics6814.get_raw_ref()
32+
mics6814._ioe.input.assert_called_with(14)
33+
34+
35+
def test_get_raw_red(ioexpander):
36+
from mics6814 import MICS6814
37+
38+
mics6814 = MICS6814()
39+
40+
mics6814.get_raw_red()
41+
mics6814._ioe.input.assert_called_with(12)
42+
43+
44+
def test_get_raw_nh3(ioexpander):
45+
from mics6814 import MICS6814
46+
47+
mics6814 = MICS6814()
48+
49+
mics6814.get_raw_nh3()
50+
mics6814._ioe.input.assert_called_with(11)
51+
52+
53+
def test_get_raw_oxd(ioexpander):
54+
from mics6814 import MICS6814
55+
56+
mics6814 = MICS6814()
57+
58+
mics6814.get_raw_oxd()
59+
mics6814._ioe.input.assert_called_with(13)
60+
61+
62+
def test_get_adc(ioexpander):
63+
from mics6814 import MICS6814
64+
65+
mics6814 = MICS6814()
66+
67+
mics6814.read_adc()
68+
69+
70+
def test_read_all(ioexpander):
71+
from mics6814 import MICS6814, Mics6814Reading
72+
73+
mics6814 = MICS6814()
74+
75+
mics6814._ioe.input.return_value = 2.5
76+
mics6814._ioe.get_adc_vref.return_value = 5.0
77+
78+
reading = mics6814.read_all()
79+
80+
assert type(reading) == Mics6814Reading
81+
mics6814._ioe.input.has_calls((
82+
mock.call(9),
83+
mock.call(12),
84+
mock.call(11),
85+
mock.call(13),
86+
))
87+
88+
assert "Oxidising" in str(reading)
89+
90+
91+
def test_read_oxd_red_nh3(ioexpander):
92+
from mics6814 import MICS6814
93+
94+
mics6814 = MICS6814()
95+
96+
mics6814._ioe.input.return_value = 2.5
97+
mics6814._ioe.get_adc_vref.return_value = 5.0
98+
99+
assert mics6814.read_oxidising() == 56000.0
100+
assert mics6814.read_reducing() == 56000.0
101+
assert mics6814.read_nh3() == 56000.0
102+
103+
104+
def test_read_oxd_red_nh3_zero_division(ioexpander):
105+
from mics6814 import MICS6814
106+
107+
mics6814 = MICS6814()
108+
109+
mics6814._ioe.input.return_value = 5.0
110+
mics6814._ioe.get_adc_vref.return_value = 5.0
111+
112+
assert mics6814.read_oxidising() == 0
113+
assert mics6814.read_reducing() == 0
114+
assert mics6814.read_nh3() == 0
115+
116+
117+
def test_set_led(ioexpander):
118+
from mics6814 import MICS6814
119+
120+
mics6814 = MICS6814()
121+
mics6814.set_led(255, 155, 55)
122+
123+
assert mics6814._ioe.output.has_calls((
124+
mock.call(3, 255),
125+
mock.call(7, 155),
126+
mock.call(2, 55)
127+
))

0 commit comments

Comments
 (0)