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
|
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()
|