|
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