File: test_output.py

package info (click to toggle)
phosh 0.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 9,868 kB
  • sloc: ansic: 83,377; xml: 3,981; python: 717; sh: 449; makefile: 34; lisp: 22; javascript: 6
file content (74 lines) | stat: -rwxr-xr-x 2,034 bytes parent folder | download | duplicates (2)
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
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python3
#
# (C) 2025 The Phosh Developers
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Author: Guido Günther <agx@sigxcpu.org>

import re
import time
import os
import subprocess
import sys
import pytest

from . import Phosh


@pytest.fixture(scope="class")
def run_phosh():
    topsrcdir = os.environ["TOPSRCDIR"]
    topbuilddir = os.environ["TOPBUILDDIR"]

    success = False
    phosh = Phosh(topsrcdir, topbuilddir).spawn_nested()

    # Close stdout/stderr to avoid blocking
    phosh.process.stdout.close()
    phosh.process.stderr.close()

    yield phosh
    success = phosh.teardown_nested()
    if not success:
        raise Exception("Phosh teardown failed")


class TestSingleOutput:
    """
    Test monitor/output related bits
    """

    def get_output(self):
        out = subprocess.check_output(["wlr-randr"], env=self.env)
        output = out.decode("utf-8").split("\n")[0].split()[0]
        assert output in ["WL-1", "X11-1", "HEADLESS-1"]
        return output

    def check_mode(self, scale):
        output = self.get_output()
        assert (
            subprocess.check_output(
                ["wlr-randr", "--output", output, "--scale", f"{scale}"], env=self.env
            )
            == b""  # noqa: W503
        )
        time.sleep(1)
        # TODO: take screenshot
        out = subprocess.check_output(["wlr-randr"], env=self.env)
        lines = out.decode("utf-8").split("\n")
        new_scale = 0.0
        scale_re = re.compile(r".*Scale: (?P<scale>[0-9.]+)")
        for line in lines:
            m = scale_re.match(line)
            if m:
                print(m, file=sys.stderr)
                new_scale = float(m.group("scale"))
        assert scale != 0.0, f"No scale found in output {lines})"
        assert scale == new_scale

    @pytest.mark.parametrize("scale", [1, 2, 2.75, 1.25, 1])
    def test_scale(self, run_phosh, scale):
        self.env = os.environ.copy()
        self.env["WAYLAND_DISPLAY"] = run_phosh.wl_display
        self.check_mode(scale)