chiark / gitweb /
Support schedule-* commands from command-line client. Exiguously tested.
[disorder] / tests / schedule.py
CommitLineData
17360d2f
RK
1#! /usr/bin/env python
2#
3# This file is part of DisOrder.
4# Copyright (C) 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 2 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, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# 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, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19# USA
20#
758aa6c3 21import dtest,disorder,time,string
17360d2f
RK
22
23def test():
24 """Exercise schedule support"""
25 dtest.start_daemon()
26 dtest.create_user()
27 c = disorder.client()
28 c.random_disable()
29 dtest.rescan()
30 # Wait until there's no track playing
31 print " waiting for nothing to be playing"
32 while c.playing() is not None:
33 time.sleep(1)
34 now = int(time.time())
35 track = "%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest.tracks
36 print " scheduling a track for the future"
37 c.schedule_add(now + 4, "normal", "play", track)
758aa6c3
RK
38 print " disorder schedule-list output:"
39 print string.join(dtest.command(["disorder",
40 "--config", disorder._configfile,
41 "--no-per-user-config",
42 "schedule-list"]), ""),
17360d2f
RK
43 print " waiting for it to play"
44 waited = 0
45 p = c.playing()
46 while p is None and waited < 10:
47 time.sleep(1)
48 waited += 1
49 p = c.playing()
50 assert waited < 10, "checking track played within a reasonable period"
51 assert waited > 2, "checking track didn't play immediately"
52 assert p["track"] == track, "checking right track played"
53 print " waiting for nothing to be playing"
54 while c.playing() is not None:
55 time.sleep(1)
56 print " scheduling an enable-random for the future"
57 now = int(time.time())
58 c.schedule_add(now + 4, "normal", "set-global", "random-play", "yes")
758aa6c3
RK
59 print " disorder schedule-list output:"
60 print string.join(dtest.command(["disorder",
61 "--config", disorder._configfile,
62 "--no-per-user-config",
63 "schedule-list"]), ""),
17360d2f
RK
64 print " waiting for it to take effect"
65 waited = 0
66 p = c.playing()
67 while p is None and waited < 10:
68 time.sleep(1)
69 waited += 1
70 p = c.playing()
71 assert waited < 10, "checking a track played within a reasonable period"
72 assert waited > 2, "checking a track didn't play immediately"
73
74if __name__ == '__main__':
75 dtest.run()