diff options
Diffstat (limited to 'tests/test_tablet.py')
| -rw-r--r-- | tests/test_tablet.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/test_tablet.py b/tests/test_tablet.py index 611810a..9f5f007 100644 --- a/tests/test_tablet.py +++ b/tests/test_tablet.py @@ -15,6 +15,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import sys +import tempfile from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) @@ -64,15 +65,19 @@ class Dim(unittest.TestCase): 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"): + with tempfile.TemporaryDirectory() as d, \ + unittest.mock.patch.object(tablet, "DIM_FILE", Path(d) / "dim"), \ + unittest.mock.patch.object(tablet, "_find_tablet", return_value="x"): + try: + m = tablet.make({"tablet": {"dim_brightness": 5}}) m.actions["dim"]({}) m.actions["dim"]({}) # already dim: the saved level is kept + m = tablet.make({"tablet": {"dim_brightness": 5}}) # a restarted server m.actions["undim"]({}) m.actions["undim"]({}) # already bright: nothing sent - finally: - tablet._adb = orig + self.assertFalse(tablet.DIM_FILE.exists()) + 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", |
