|
| 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