File: test_cpu.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-- 986 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 sys
from importlib import reload
from types import ModuleType

import pytest

import libqtile.config
import libqtile.widget
from libqtile.bar import Bar


class MockPsutil(ModuleType):
    __version__ = "5.8.0"

    @classmethod
    def cpu_percent(cls):
        return 2.6

    @classmethod
    def cpu_freq(cls):
        class Freq:
            def __init__(self):
                self.current = 500.067
                self.min = 400.0
                self.max = 2800.0

        return Freq()


@pytest.fixture
def cpu_manager(monkeypatch, manager_nospawn, minimal_conf_noscreen):
    monkeypatch.setitem(sys.modules, "psutil", MockPsutil("psutil"))
    from libqtile.widget import cpu

    reload(cpu)

    config = minimal_conf_noscreen
    config.screens = [libqtile.config.Screen(top=Bar([cpu.CPU()], 10))]

    manager_nospawn.start(config)
    yield manager_nospawn


def test_cpu(cpu_manager):
    assert cpu_manager.c.widget["cpu"].info()["text"] == "CPU 0.5GHz 2.6%"