-
-
Notifications
You must be signed in to change notification settings - Fork 691
/
test_volume.py
95 lines (74 loc) · 2.23 KB
/
test_volume.py
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
import cairocffi
import pytest
from libqtile import bar, images
from libqtile.widget import Volume
from test.widgets.conftest import TEST_DIR
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"
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.mute = True
vol._update_drawer()
assert vol.text == "Volume: 50% M"
def test_foregrounds():
foreground = "#dddddd"
mute_foreground = None
vol = Volume(foreground=foreground, mute_foreground=mute_foreground)
vol.volume = 50
vol._update_drawer()
assert vol.foreground == foreground
vol.mute_foreground = mute_foreground = "#888888"
vol.mute = False
vol._update_drawer()
assert vol.foreground == foreground
vol.mute = True
vol._update_drawer()
assert vol.foreground == mute_foreground