Skip to content

Commit 42e44c6

Browse files
committed
test(tion): add unit tests for __detect_heating_state
1 parent 6434814 commit 42e44c6

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

tests/unit/__init__.py

Whitespace-only changes.

tests/unit/tion.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
import unittest
3+
import unittest.mock as mock
4+
from unittest.mock import MagicMock
5+
sys.modules['bluepy'] = MagicMock()
6+
sys.modules['bluepy.btle'] = MagicMock()
7+
import tion_btle.tion # noqa: E402
8+
9+
10+
class TionTests(unittest.TestCase):
11+
def setUp(self):
12+
self.patch = mock.patch('tion_btle.tion.tion.__init__', return_value=None)
13+
self.patch.start()
14+
self._tion = tion_btle.tion.tion("")
15+
16+
def tearDown(self):
17+
self.patch.stop()
18+
19+
def test___detect_heating_state(self):
20+
# state, in, out, target, heater
21+
_variants = [
22+
["on", -2, 21, 20, "on"],
23+
["on", 15, 21, 20, "on"],
24+
["off", 15, 21, 16, "on"],
25+
["off", 15, 21, 20, "off"],
26+
]
27+
28+
for expect, in_temp, out_temp, target_temp, heater in _variants:
29+
with self.subTest(expect=expect,
30+
in_temp=in_temp, out_temp=out_temp, target_temp=target_temp, heater=heater):
31+
# call private __detect_heating_state from tion class
32+
self._tion._tion__detect_heating_state(in_temp, out_temp, target_temp, heater)
33+
self.assertEqual(self._tion.heating, expect)
34+
35+
36+
if __name__ == '__main__':
37+
unittest.main()

0 commit comments

Comments
 (0)