diff options
Diffstat (limited to 'tests/test_tablet.py')
| -rw-r--r-- | tests/test_tablet.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_tablet.py b/tests/test_tablet.py index f2bbed6..611810a 100644 --- a/tests/test_tablet.py +++ b/tests/test_tablet.py @@ -20,6 +20,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) import unittest +import unittest.mock from deckit.modules import tablet @@ -57,5 +58,26 @@ class Parse(unittest.TestCase): self.assertEqual(tablet.parse_wifi("Wifi is disabled\n"), {"connected": False}) +class Dim(unittest.TestCase): + def test_dim_saves_and_undim_restores(self): + calls, orig = [], tablet._adb + answers = {"settings get system screen_brightness_mode": "1\n", + "settings get system screen_brightness": "200\n"} + tablet._adb = lambda *a, **k: calls.append(a[-1]) or answers.get(a[-1], "") + try: + m = tablet.make({"tablet": {"dim_brightness": 5}}) + with unittest.mock.patch.object(tablet, "_find_tablet", return_value="x"): + m.actions["dim"]({}) + m.actions["dim"]({}) # already dim: the saved level is kept + m.actions["undim"]({}) + m.actions["undim"]({}) # already bright: nothing sent + finally: + tablet._adb = orig + sets = [c for c in calls if "put" in c] + self.assertEqual(sets, [ + "settings put system screen_brightness_mode 0; settings put system screen_brightness 5", + "settings put system screen_brightness 200; settings put system screen_brightness_mode 1"]) + + if __name__ == "__main__": unittest.main() |
