File: test_command_graph.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 (53 lines) | stat: -rw-r--r-- 1,684 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
import pytest

from libqtile.command.graph import CommandGraphCall, CommandGraphObject, CommandGraphRoot


def test_root_path():
    node = CommandGraphRoot()
    assert node.selectors == []
    assert node.selector is None
    assert node.parent is None


def test_resolve_nodes():
    root_node = CommandGraphRoot()

    node_1 = root_node.navigate("layout", None).navigate("screen", None)
    assert node_1.selectors == [("layout", None), ("screen", None)]
    assert isinstance(node_1, CommandGraphObject)

    node_2 = node_1.navigate("layout", None).navigate("window", None).navigate("group", None)
    assert node_2.selectors == [
        ("layout", None),
        ("screen", None),
        ("layout", None),
        ("window", None),
        ("group", None),
    ]
    assert isinstance(node_2, CommandGraphObject)

    with pytest.raises(KeyError, match="Given node is not an object"):
        node_1.navigate("root", None)


def test_resolve_selections():
    root_node = CommandGraphRoot()

    node_1 = root_node.navigate("layout", None).navigate("screen", "1")
    assert node_1.selectors == [("layout", None), ("screen", "1")]
    assert isinstance(node_1, CommandGraphObject)


def test_resolve_command():
    root_node = CommandGraphRoot()

    command_1 = root_node.call("cmd_name")
    assert command_1.selectors == []
    assert command_1.name == "cmd_name"
    assert isinstance(command_1, CommandGraphCall)

    command_2 = root_node.navigate("layout", None).navigate("screen", None).call("cmd_name")
    assert command_2.name == "cmd_name"
    assert command_2.selectors == [("layout", None), ("screen", None)]
    assert isinstance(command_2, CommandGraphCall)