Since this thing is on the innerwebs I suppose it should have a
[python_utils.git] / tests / waitable_presence_test.py
1 #!/usr/bin/env python3
2
3 # © Copyright 2021-2022, Scott Gasch
4
5 """waitable_presence unittest."""
6
7 import unittest
8 from unittest.mock import MagicMock
9
10 import base_presence
11 import unittest_utils  # Needed for --unittests_ignore_perf flag
12 import waitable_presence
13 from type.locations import Location
14
15
16 class TestWaitablePresence(unittest.TestCase):
17     def test_basic_functionality(self):
18         mock_detector = base_presence.PresenceDetection()
19         mock_detector.update = MagicMock()
20         mock_detector.is_anyone_in_location_now = MagicMock(return_value=True)
21         wp = waitable_presence.WaitablePresenceDetectorWithMemory(
22             1.0, Location.HOUSE, mock_detector
23         )
24         changed = wp.wait()
25         (someone_is_home, since) = wp.is_someone_home()
26         mock_detector.update.assert_called_with()
27         mock_detector.is_anyone_in_location_now.assert_called_with(Location.HOUSE)
28         self.assertTrue(changed)
29         self.assertTrue(someone_is_home)
30         self.assertNotEqual(None, since)
31         wp.reset()
32         wp.shutdown()
33
34
35 if __name__ == '__main__':
36     unittest.main()