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
|
import sys
from importlib import reload
from types import ModuleType
import pytest
from libqtile.widget import df
from test.widgets.conftest import FakeBar
class FakeOS(ModuleType):
class statvfs: # noqa: N801
def __init__(self, *args, **kwargs):
pass
@property
def f_frsize(self):
return 4096
@property
def f_blocks(self):
return 60000000
@property
def f_bfree(self):
return 15000000
@property
def f_bavail(self):
return 10000000
# Patches os.stavfs gives these values for df widget:
# unit: G
# size = 228
# free = 57
# user_free = 38
# ratio (user_free / size) = 83.3333%
@pytest.fixture()
def patched_df(monkeypatch):
monkeypatch.setitem(sys.modules, "os", FakeOS("os"))
reload(df)
@pytest.mark.usefixtures("patched_df")
def test_df_no_warning(fake_qtile, fake_window):
"""Test no text when free space over threshold"""
df1 = df.DF()
fakebar = FakeBar([df1], window=fake_window)
df1._configure(fake_qtile, fakebar)
text = df1.poll()
assert text == ""
df1.draw()
assert df1.layout.colour == df1.foreground
@pytest.mark.usefixtures("patched_df")
def test_df_always_visible(fake_qtile, fake_window):
"""Test text is always displayed"""
df2 = df.DF(visible_on_warn=False)
fakebar = FakeBar([df2], window=fake_window)
df2._configure(fake_qtile, fakebar)
text = df2.poll()
# See values above
assert text == "/ (38G|83%)"
df2.draw()
assert df2.layout.colour == df2.foreground
@pytest.mark.usefixtures("patched_df")
def test_df_warn_space(fake_qtile, fake_window):
"""
Test text is visible and colour changes when space
below threshold
"""
df3 = df.DF(warn_space=40)
fakebar = FakeBar([df3], window=fake_window)
df3._configure(fake_qtile, fakebar)
text = df3.poll()
# See values above
assert text == "/ (38G|83%)"
df3.draw()
assert df3.layout.colour == df3.warn_color
|