File: test_lifecycle.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 (45 lines) | stat: -rw-r--r-- 1,325 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
import pytest

from libqtile.core.lifecycle import Behavior, LifeCycle
from libqtile.log_utils import init_log


def fake_os_execv(executable, args):
    assert args == [
        "arg1",
        "arg2",
        "--no-spawn",
        "--with-state=/tmp/test/fake_statefile",
    ]


def no_op(*args, **kwargs):
    pass


@pytest.fixture
def patched_lifecycle(monkeypatch):
    init_log()
    monkeypatch.setattr("libqtile.core.lifecycle.sys.argv", ["arg1", "arg2"])
    monkeypatch.setattr("libqtile.core.lifecycle.atexit.register", no_op)
    monkeypatch.setattr("libqtile.core.lifecycle.os.execv", fake_os_execv)
    yield LifeCycle()


def test_restart_behaviour(patched_lifecycle, caplog):
    patched_lifecycle.behavior = Behavior.RESTART
    patched_lifecycle.state_file = "/tmp/test/fake_statefile"
    patched_lifecycle._atexit()
    assert caplog.record_tuples == [("libqtile", 30, "Restarting Qtile with os.execv(...)")]


def test_terminate_behavior(patched_lifecycle, caplog):
    patched_lifecycle.behavior = Behavior.TERMINATE
    patched_lifecycle._atexit()
    assert caplog.record_tuples == [("libqtile", 30, "Qtile will now terminate")]


def test_none_behavior(patched_lifecycle, caplog):
    patched_lifecycle.behavior = Behavior.NONE
    patched_lifecycle._atexit()
    assert caplog.record_tuples == []