1import cairocffi
2import pytest
3
4from libqtile import images
5from libqtile.widget import Volume
6from test.widgets.conftest import TEST_DIR
7
8
9def test_images_fail():
10    vol = Volume(theme_path=TEST_DIR)
11    with pytest.raises(images.LoadingError):
12        vol.setup_images()
13
14
15def test_images_good(tmpdir, fake_bar, svg_img_as_pypath):
16    names = (
17        'audio-volume-high.svg',
18        'audio-volume-low.svg',
19        'audio-volume-medium.svg',
20        'audio-volume-muted.svg',
21    )
22    for name in names:
23        target = tmpdir.join(name)
24        svg_img_as_pypath.copy(target)
25
26    vol = Volume(theme_path=str(tmpdir))
27    vol.bar = fake_bar
28    vol.setup_images()
29    assert len(vol.surfaces) == len(names)
30    for name, surfpat in vol.surfaces.items():
31        assert isinstance(surfpat, cairocffi.SurfacePattern)
32
33
34def test_emoji():
35    vol = Volume(emoji=True)
36    vol.volume = -1
37    vol._update_drawer()
38    assert vol.text == '\U0001f507'
39
40    vol.volume = 29
41    vol._update_drawer()
42    assert vol.text == '\U0001f508'
43
44    vol.volume = 79
45    vol._update_drawer()
46    assert vol.text == '\U0001f509'
47
48    vol.volume = 80
49    vol._update_drawer()
50    assert vol.text == '\U0001f50a'
51
52
53def test_text():
54    fmt = "Volume: {}"
55    vol = Volume(fmt=fmt)
56    vol.volume = -1
57    vol._update_drawer()
58    assert vol.text == 'M'
59
60    vol.volume = 50
61    vol._update_drawer()
62    assert vol.text == '50%'
63