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
|
# deck-it - tests for music
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import unittest
import deckit.modules.music as music
class Music(unittest.TestCase):
def test_parses_metadata(self):
sep = "\x1f"
fake = lambda cmd, timeout=2: {
"metadata": sep.join(["Playing", "Song", "Artist", "Album", "200000000",
"1000000", "", "spotify"]),
"get-volume": "Volume: 0.42",
}[cmd[1]]
m = music.make({"run": fake})
st = m.state()
self.assertEqual(st["title"], "Song")
self.assertEqual(st["status"], "Playing")
self.assertEqual(st["volume"]["level"], 42)
def test_action_commands(self):
self.assertEqual(music.BASE_ACTIONS["next"], ["playerctl", "next"])
def test_seek_runs_playerctl(self):
calls = []
m = music.make({"run": lambda *a, **k: "", "popen": calls.append})
m.actions["seek"]({"position": 12.34})
self.assertEqual(calls[0], ["playerctl", "position", "12.3"])
def test_seek_rejects_bad_positions(self):
m = music.make({"run": lambda *a, **k: "", "popen": lambda cmd: None})
for bad in ({}, {"position": -1}, {"position": "x"}):
with self.assertRaises(music.ModuleError, msg=bad):
m.actions["seek"](bad)
if __name__ == "__main__":
unittest.main()
|