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 """Exercise schedule support"""
30 # Wait until there's no track playing
31 print " waiting for nothing to be playing"
32 while c
.playing() is not None:
35 now
= int(time
.time())
36 track
= "%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest
.tracks
37 print " scheduling a track for the future"
38 c
.schedule_add(now
+ 4, "normal", "play", track
)
39 print " disorder schedule-list output:"
40 print string
.join(dtest
.command(["disorder",
41 "--config", disorder
._configfile
,
42 "--no-per-user-config",
43 "schedule-list"]), ""),
44 print " waiting for it to play"
47 while p
is None and waited
< 10:
52 assert waited
< 10, "checking track played within a reasonable period"
53 assert waited
> 2, "checking track didn't play immediately"
54 assert p
["track"] == track
, "checking right track played"
55 assert c
.schedule_list() == [], "checking schedule is empty"
56 print " waiting for nothing to be playing"
57 while c
.playing() is not None:
60 print " scheduling an enable-random for the future"
61 now
= int(time
.time())
62 c
.schedule_add(now
+ 4, "normal", "set-global", "random-play", "yes")
63 print " disorder schedule-list output:"
64 print string
.join(dtest
.command(["disorder",
65 "--config", disorder
._configfile
,
66 "--no-per-user-config",
67 "schedule-list"]), ""),
68 print " waiting for it to take effect"
71 while p
is None and waited
< 10:
76 assert waited
< 10, "checking a track played within a reasonable period"
77 assert waited
> 2, "checking a track didn't play immediately"
78 print " disabling random play"
80 print " waiting for nothing to be playing"
81 while c
.playing() is not None:
84 print " scheduling track to play later via command line"
85 now
= int(time
.time())
86 dtest
.command(["disorder",
87 "--config", disorder
._configfile
,
88 "--no-per-user-config",
90 time
.strftime("%Y-%m-%d %H:%M:%S",
91 time
.localtime(now
+ 4)),
94 print " disorder schedule-list output:"
95 print string
.join(dtest
.command(["disorder",
96 "--config", disorder
._configfile
,
97 "--no-per-user-config",
98 "schedule-list"]), ""),
99 print " waiting for it to play"
102 while p
is None and waited
< 10:
107 assert waited
< 10, "checking track played within a reasonable period"
108 assert waited
> 2, "checking track didn't play immediately"
109 assert p
["track"] == track
, "checking right track played"
110 assert c
.schedule_list() == [], "checking schedule is empty"
111 print " waiting for nothing to be playing"
112 while c
.playing() is not None:
115 print " scheduling an enable-random for later via command line"
116 now
= int(time
.time())
117 dtest
.command(["disorder",
118 "--config", disorder
._configfile
,
119 "--no-per-user-config",
120 "schedule-set-global",
121 time
.strftime("%Y-%m-%d %H:%M:%S",
122 time
.localtime(now
+ 4)),
126 print " disorder schedule-list output:"
127 print string
.join(dtest
.command(["disorder",
128 "--config", disorder
._configfile
,
129 "--no-per-user-config",
130 "schedule-list"]), ""),
131 print " waiting for it to take effect"
134 while p
is None and waited
< 10:
139 assert waited
< 10, "checking a track played within a reasonable period"
140 assert waited
> 2, "checking a track didn't play immediately"
141 print " disabling random play"
143 print " waiting for nothing to be playing"
144 while c
.playing() is not None:
147 print " scheduling a track for the future"
148 now
= int(time
.time())
149 c
.schedule_add(now
+ 4, "normal", "play", track
)
150 print " schedule via python:"
151 s
= c
.schedule_list()
153 e
= c
.schedule_get(event
)
154 print "item %s: %s" %
(event
, e
)
155 print " deleting item %s" % s
[0]
157 print " checking it's really gone"
158 s
= c
.schedule_list()
159 assert s
== [], "checking schedule is empty"
162 while p
is None and waited
< 10:
167 assert p
is None, "checking deleted scheduled event did not run"
168 print " checking you can't schedule events for the past"
170 now
= int(time
.time())
171 c
.schedule_add(now
- 4, "normal", "play", track
)
172 assert False, "checking schedule_add failed"
173 except disorder
.operationError
:
175 print " checking scheduled events survive restarts"
176 c
.schedule_add(now
+ 4, "normal", "play", track
)
178 print " dumping database"
179 dump
= "%s/dumpfile" % dtest
.testroot
180 print dtest
.command(["disorder-dump", "--config", disorder
._configfile
,
182 print "restoring database"
183 print dtest
.command(["disorder-dump", "--config", disorder
._configfile
,
186 c
= disorder
.client()
187 print " waiting for track to play"
190 while p
is None and waited
< 10:
195 assert waited
< 10, "checking track played within a reasonable period"
196 assert p
["track"] == track
, "checking right track played"
197 assert c
.schedule_list() == [], "checking schedule is empty"
199 if __name__
== '__main__':