aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_display.py
blob: 3a974271b4fde7c574dfa642d752f37f231618be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# deck-it - tests for display
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# 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
import tempfile
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import unittest

import deckit.display as display


class Resolution(unittest.TestCase):
    def test_reads_adb(self):
        self.assertEqual(
            display.tablet_resolution({"display": {}}, adb=lambda: "Physical size: 1920x1200"),
            "1920x1200")

    def test_config_override(self):
        self.assertEqual(
            display.tablet_resolution({"display": {"resolution": "2560x1600"}},
                                      adb=lambda: "1920x1200"),
            "2560x1600")


class Below(unittest.TestCase):
    def test_centered_under_the_reference(self):
        ref = {"x": 0, "y": 0, "width": 2560, "height": 1080}
        self.assertEqual(display.below_position(ref, "1280x800"), "640x1080")

    def test_honours_the_reference_offset(self):
        ref = {"x": 0, "y": -540, "width": 2560, "height": 1080}
        self.assertEqual(display.below_position(ref, "1280x800"), "640x540")


class Swaybg(unittest.TestCase):
    def test_finds_the_image_for_an_output(self):
        root = Path(tempfile.mkdtemp())
        d = root / "123"
        d.mkdir()
        (d / "cmdline").write_bytes(b"/usr/bin/swaybg\0-o\0DP-1\0-i\0/a.png\0-m\0fill\0")
        self.assertEqual(display._swaybg_for("DP-1", root), (123, "/a.png", "fill"))
        self.assertIsNone(display._swaybg_for("TAB", root))


if __name__ == "__main__":
    unittest.main()