diff options
| author | Scott Gasch <[email protected]> | 2022-02-06 13:45:21 -0800 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-02-06 13:45:21 -0800 |
| commit | b22b39493c5b6c747b16e9430f3833bb8869cef6 (patch) | |
| tree | c494285c0b302d95ef7b428d026a72d268d1d0b6 /tests | |
| parent | d2376b4dd7a8bba0dfc878578086faeab83c6f5b (diff) | |
Add a simple test for waitable presence.
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/waitable_presence_test.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/waitable_presence_test.py b/tests/waitable_presence_test.py new file mode 100755 index 0000000..ff4225c --- /dev/null +++ b/tests/waitable_presence_test.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +import re +import unittest +from unittest.mock import MagicMock + +import base_presence +import unittest_utils # Needed for --unittests_ignore_perf flag +import waitable_presence +from type.locations import Location + + +class TestWaitablePresence(unittest.TestCase): + def test_basic_functionality(self): + mock_detector = base_presence.PresenceDetection() + mock_detector.update = MagicMock() + mock_detector.is_anyone_in_location_now = MagicMock(return_value=True) + wp = waitable_presence.WaitablePresenceDetectorWithMemory( + 1.0, Location.HOUSE, mock_detector + ) + changed = wp.wait() + (someone_is_home, since) = wp.is_someone_home() + mock_detector.update.assert_called_with() + mock_detector.is_anyone_in_location_now.assert_called_with(Location.HOUSE) + self.assertTrue(changed) + self.assertTrue(someone_is_home) + self.assertNotEqual(None, since) + wp.reset() + wp.shutdown() + + +if __name__ == '__main__': + unittest.main() |
