# deck-it - tests for actions # Copyright (C) 2026 Danilo M. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) import subprocess import unittest from deckit.modules import actions class Follow(unittest.TestCase): def test_sleeps_on_lock_and_wakes_on_unlock(self): keys = [] was = actions.follow(lambda: True, keys.append, False) was = actions.follow(lambda: True, keys.append, was) was = actions.follow(lambda: False, keys.append, was) self.assertEqual(keys, ["KEYCODE_SLEEP", "KEYCODE_WAKEUP"]) self.assertFalse(was) def test_nothing_while_unchanged(self): keys = [] actions.follow(lambda: False, keys.append, False) self.assertEqual(keys, []) def test_no_pidof_reads_as_unlocked(self): import os path = os.environ["PATH"] os.environ["PATH"] = "/nonexistent" try: self.assertFalse(actions._locked()) finally: os.environ["PATH"] = path def test_adb_failure_is_ignored(self): def boom(code): raise subprocess.CalledProcessError(1, "adb") self.assertTrue(actions.follow(lambda: True, boom, False)) if __name__ == "__main__": unittest.main()