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
|
import cairocffi
import pytest
from libqtile import bar, images
from libqtile.widget import Volume
from test.widgets.conftest import TEST_DIR, FakeBar
def test_images_fail():
vol = Volume(theme_path=TEST_DIR)
with pytest.raises(images.LoadingError):
vol.setup_images()
def test_images_good(tmpdir, fake_bar, svg_img_as_pypath):
names = (
"audio-volume-high.svg",
"audio-volume-low.svg",
"audio-volume-medium.svg",
"audio-volume-muted.svg",
)
for name in names:
target = tmpdir.join(name)
svg_img_as_pypath.copy(target)
vol = Volume(theme_path=str(tmpdir))
vol.bar = fake_bar
vol.length_type = bar.STATIC
vol.length = 0
vol.setup_images()
assert len(vol.surfaces) == len(names)
for name, surfpat in vol.surfaces.items():
assert isinstance(surfpat, cairocffi.SurfacePattern)
def test_emoji():
vol = Volume(emoji=True)
vol.volume = -1
vol._update_drawer()
assert vol.text == "\U0001f507"
vol.volume = 29
vol._update_drawer()
assert vol.text == "\U0001f508"
vol.volume = 79
vol._update_drawer()
assert vol.text == "\U0001f509"
vol.volume = 80
vol._update_drawer()
assert vol.text == "\U0001f50a"
vol.is_mute = True
vol._update_drawer()
assert vol.text == "\U0001f507"
def test_text():
fmt = "Volume: {}"
vol = Volume(fmt=fmt)
vol.volume = -1
vol._update_drawer()
assert vol.text == "M"
vol.volume = 50
vol._update_drawer()
assert vol.text == "50%"
def test_formats():
unmute_format = "Volume: {volume}%"
mute_format = "Volume: {volume}% M"
vol = Volume(unmute_format=unmute_format, mute_format=mute_format)
vol.volume = 50
vol._update_drawer()
assert vol.text == "Volume: 50%"
vol.is_mute = True
vol._update_drawer()
assert vol.text == "Volume: 50% M"
def test_foregrounds(fake_qtile, fake_window):
foreground = "#dddddd"
mute_foreground = None
vol = Volume(foreground=foreground, mute_foreground=mute_foreground)
fakebar = FakeBar([vol], window=fake_window)
vol._configure(fake_qtile, fakebar)
vol.volume = 50
vol._update_drawer()
assert vol.layout.colour == foreground
vol.mute_foreground = mute_foreground = "#888888"
vol.is_mute = False
vol._update_drawer()
assert vol.layout.colour == foreground
vol.is_mute = True
vol._update_drawer()
assert vol.layout.colour == mute_foreground
|