File: test_windowtabs.py

package info (click to toggle)
qtile 0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,004 kB
  • sloc: python: 49,959; ansic: 4,371; xml: 324; sh: 260; makefile: 218
file content (128 lines) | stat: -rw-r--r-- 3,542 bytes parent folder | download
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import pytest

import libqtile.config
from libqtile import bar, layout, widget
from libqtile.config import Screen
from libqtile.confreader import Config


def custom_text_parser(name):
    return f"TEST-{name}-TEST"


class WindowTabsConfig(Config):
    auto_fullscreen = True
    groups = [libqtile.config.Group("a"), libqtile.config.Group("b")]
    layouts = [layout.Stack()]
    floating_layout = libqtile.resources.default_config.floating_layout
    keys = []
    mouse = []
    fake_screens = [
        Screen(
            top=bar.Bar(
                [
                    widget.WindowTabs(),
                    widget.WindowTabs(name="customparse", parse_text=custom_text_parser),
                ],
                24,
            ),
            bottom=bar.Bar(
                [
                    widget.WindowTabs(selected="!!"),
                ],
                24,
            ),
            x=0,
            y=0,
            width=900,
            height=960,
        ),
    ]
    screens = []


windowtabs_config = pytest.mark.parametrize("manager", [WindowTabsConfig], indirect=True)


@windowtabs_config
def test_single_window_states(manager):
    def widget_text():
        return manager.c.bar["top"].info()["widgets"][0]["text"]

    # When no windows are spawned the text should be ""
    # Initially TextBox has " " but the Config.set_group function already
    # calls focus_change hook, so the text should be updated to ""
    assert widget_text() == ""

    # Load a window
    proc = manager.test_window("one")
    assert widget_text() == "<b>one</b>"

    # Maximize window
    manager.c.window.toggle_maximize()
    assert widget_text() == "<b>[] one</b>"

    # Minimize window
    manager.c.window.toggle_minimize()
    assert widget_text() == "<b>_ one</b>"

    # Float window
    manager.c.window.toggle_minimize()
    manager.c.window.toggle_floating()
    assert widget_text() == "<b>V one</b>"

    # Kill the window and check empty string again
    manager.kill_window(proc)
    assert widget_text() == ""


@windowtabs_config
def test_multiple_windows(manager):
    def widget_text():
        return manager.c.bar["top"].info()["widgets"][0]["text"]

    window_one = manager.test_window("one")
    assert widget_text() == "<b>one</b>"

    window_two = manager.test_window("two")
    assert widget_text() in ["<b>two</b> | one", "one | <b>two</b>"]

    manager.c.layout.next()
    assert widget_text() in ["<b>one</b> | two", "two | <b>one</b>"]

    manager.kill_window(window_one)
    assert widget_text() == "<b>two</b>"

    manager.kill_window(window_two)
    assert widget_text() == ""


@windowtabs_config
def test_selected(manager):
    # Bottom bar widget has custom "selected" indicator
    def widget_text():
        return manager.c.bar["bottom"].info()["widgets"][0]["text"]

    window_one = manager.test_window("one")
    assert widget_text() == "!!one!!"

    manager.kill_window(window_one)
    assert widget_text() == ""


@windowtabs_config
def test_escaping_text(manager):
    """
    Ampersands can cause a crash if not escaped before passing to
    pangocffi.parse_markup.
    Test that the widget can parse text safely.
    """
    manager.test_window("Text & Text")
    assert manager.c.widget["windowtabs"].info()["text"] == "<b>Text &amp; Text</b>"


@windowtabs_config
def test_custom_text_parser(manager):
    """Test the custom text parser function."""
    manager.test_window("one")
    assert manager.c.widget["customparse"].info()["text"] == "<b>TEST-one-TEST</b>"