3 # This file is part of DisOrder.
4 # Copyright (C) 2008 Richard Kettlewell
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.
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.
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
21 import dtest,disorder,time,string
24 """Return the current time in whole seconds"""
25 return int(time.time())
28 print " waiting for track to play"
31 while p is None and waited < 10:
35 assert waited < 10, "track played in a reasonable time"
39 print " waiting for nothing to be playing"
42 while p is not None and waited < 20:
46 assert waited < 20, "idled in a reasonable time"
49 """Exercise schedule support"""
55 # Wait until there's no track playing
56 print " waiting for nothing to be playing"
57 while c.playing() is not None:
60 track = "%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest.tracks
61 print " scheduling a track for the future"
63 c.schedule_add(when, "normal", "play", track)
64 print " disorder schedule-list output:"
65 print string.join(dtest.command(["disorder",
66 "--config", disorder._configfile,
67 "--no-per-user-config",
68 "schedule-list"]), ""),
70 assert p["track"] == track, "checking right track played"
71 assert int(p["when"]) >= when, "checking track played at right time"
72 assert c.schedule_list() == [], "checking schedule is empty"
74 print " scheduling an enable-random for the future"
75 c.schedule_add(now() + 3, "junk", "set-global", "random-play", "yes")
76 print " disorder schedule-list output:"
77 print string.join(dtest.command(["disorder",
78 "--config", disorder._configfile,
79 "--no-per-user-config",
80 "schedule-list"]), ""),
82 print " disabling random play"
85 print " scheduling track to play later via command line"
87 dtest.command(["disorder",
88 "--config", disorder._configfile,
89 "--no-per-user-config",
91 time.strftime("%Y-%m-%d %H:%M:%S",
92 time.localtime(when)),
95 print " disorder schedule-list output:"
96 print string.join(dtest.command(["disorder",
97 "--config", disorder._configfile,
98 "--no-per-user-config",
99 "schedule-list"]), ""),
101 assert p["track"] == track, "checking right track played"
102 assert p["when"] >= when, "checking track played at right time"
103 assert c.schedule_list() == [], "checking schedule is empty"
105 print " scheduling an enable-random for later via command line"
106 dtest.command(["disorder",
107 "--config", disorder._configfile,
108 "--no-per-user-config",
109 "schedule-set-global",
110 time.strftime("%Y-%m-%d %H:%M:%S",
111 time.localtime(now() + 3)),
115 print " disorder schedule-list output:"
116 print string.join(dtest.command(["disorder",
117 "--config", disorder._configfile,
118 "--no-per-user-config",
119 "schedule-list"]), ""),
121 print " disabling random play"
123 print " waiting for nothing to be playing"
124 while c.playing() is not None:
127 print " scheduling a track for the future"
128 c.schedule_add(now() + 3, "normal", "play", track)
129 print " schedule via python:"
130 s = c.schedule_list()
132 e = c.schedule_get(event)
133 print "item %s: %s" % (event, e)
134 print " deleting item %s" % s[0]
136 print " checking it's really gone"
137 s = c.schedule_list()
138 assert s == [], "checking schedule is empty"
141 while p is None and waited < 5:
146 assert p is None, "checking deleted scheduled event did not run"
147 print " checking you can't schedule events for the past"
149 c.schedule_add(now() - 4, "normal", "play", track)
150 assert False, "checking schedule_add failed"
151 except disorder.operationError:
153 print " checking scheduled events survive restarts"
155 c.schedule_add(when, "normal", "play", track)
157 print " dumping database"
158 dump = "%s/dumpfile" % dtest.testroot
159 print dtest.command(["disorder-dump", "--config", disorder._configfile,
161 print "restoring database"
162 print dtest.command(["disorder-dump", "--config", disorder._configfile,
165 c = disorder.client()
167 print " waiting for track to play"
168 assert p["track"] == track, "checking right track played"
169 assert p["when"] >= when, "checking track played at right time"
170 assert c.schedule_list() == [], "checking schedule is empty"
171 print " checking junk events do not survive restarts"
172 c.schedule_add(now() + 2, "junk", "play", track)
173 s = c.schedule_list()
178 c = disorder.client()
179 print " checking schedule is empty"
180 s = c.schedule_list()
182 assert s == [], "checking schedule is empty"
184 if __name__ == '__main__':