chiark / gitweb /
Switch to GPL v3
[disorder] / tests / queue.py
... / ...
CommitLineData
1#! /usr/bin/env python
2#
3# This file is part of DisOrder.
4# Copyright (C) 2007, 2008 Richard Kettlewell
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19import dtest,time,disorder,re
20
21class wait_monitor(disorder.monitor):
22 def queue(self, q):
23 return False
24
25def test():
26 """Check the queue is padded to the (default) configured length"""
27 dtest.start_daemon()
28 dtest.create_user()
29 c = disorder.client()
30 print " disabling play"
31 c.disable()
32 print " waiting for queue to be populated..."
33 q = c.queue()
34 while len(q) < 5:
35 print " queue at %d tracks" % len(q)
36 wait_monitor().run()
37 q = c.queue()
38 print " getting queue via disorder(1)"
39 q = dtest.command(["disorder",
40 "--config", disorder._configfile, "--no-per-user-config",
41 "queue"])
42 tracks = filter(lambda s: re.match("^track", s), q)
43 assert len(tracks) == 5, "queue is at proper length"
44 print " disabling random play"
45 c.random_disable()
46 print " emptying queue"
47 for t in c.queue():
48 c.remove(t['id'])
49 print " checking queue is now empty"
50 q = c.queue()
51 assert q == [], "checking queue is empty"
52 print " enabling random play"
53 c.random_enable()
54 print " waiting for queue to refill..."
55 q = c.queue()
56 while len(q) < 5:
57 print " queue at %d tracks" % len(q)
58 wait_monitor().run()
59 q = c.queue()
60 print " disabling all play"
61 c.random_disable()
62 c.disable()
63 print " emptying queue"
64 for t in c.queue():
65 c.remove(t['id'])
66 t1 = "%s/Joe Bloggs/Third Album/01:First_track.ogg" % dtest.tracks
67 t2 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
68 t3 = "%s/Joe Bloggs/Third Album/02:Second_track.ogg" % dtest.tracks
69 print " adding tracks"
70 i1 = c.play(t1)
71 i2 = c.play(t2)
72 i3 = c.play(t3)
73 q = c.queue()
74 assert map(lambda e:e['id'], q) == [i1, i2, i3], "checking queue order(1)"
75 print " moving last track to start"
76 c.moveafter(None, [i3])
77 q = c.queue()
78 assert map(lambda e:e['id'], q) == [i3, i1, i2], "checking queue order(2)"
79 print " moving two tracks"
80 c.moveafter(i1, [i2, i3])
81 q = c.queue()
82 assert map(lambda e:e['id'], q) == [i1, i2 ,i3], "checking queue order(3)"
83 print " removing a track"
84 c.remove(i2)
85 q = c.queue()
86 assert map(lambda e:e['id'], q) == [i1 ,i3], "checking queue order(4)"
87
88if __name__ == '__main__':
89 dtest.run()