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:
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
)
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"]), ""),
43 print " waiting for it to play"
46 while p
is None and waited
< 10:
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 assert c
.schedule_list() == [], "checking schedule is empty"
54 print " waiting for nothing to be playing"
55 while c
.playing() is not None:
57 print " scheduling an enable-random for the future"
58 now
= int(time
.time())
59 c
.schedule_add(now
+ 4, "normal", "set-global", "random-play", "yes")
60 print " disorder schedule-list output:"
61 print string
.join(dtest
.command(["disorder",
62 "--config", disorder
._configfile
,
63 "--no-per-user-config",
64 "schedule-list"]), ""),
65 print " waiting for it to take effect"
68 while p
is None and waited
< 10:
72 assert waited
< 10, "checking a track played within a reasonable period"
73 assert waited
> 2, "checking a track didn't play immediately"
74 print " disabling random play"
76 print " waiting for nothing to be playing"
77 while c
.playing() is not None:
79 print " scheduling track to play later via command line"
80 now
= int(time
.time())
81 dtest
.command(["disorder",
82 "--config", disorder
._configfile
,
83 "--no-per-user-config",
85 time
.strftime("%Y-%m-%d %H:%M:%S",
86 time
.localtime(now
+ 4)),
89 print " disorder schedule-list output:"
90 print string
.join(dtest
.command(["disorder",
91 "--config", disorder
._configfile
,
92 "--no-per-user-config",
93 "schedule-list"]), ""),
94 print " waiting for it to play"
97 while p
is None and waited
< 10:
101 assert waited
< 10, "checking track played within a reasonable period"
102 assert waited
> 2, "checking track didn't play immediately"
103 assert p
["track"] == track
, "checking right track played"
104 assert c
.schedule_list() == [], "checking schedule is empty"
105 print " waiting for nothing to be playing"
106 while c
.playing() is not None:
108 print " scheduling an enable-random for later via command line"
109 now
= int(time
.time())
110 dtest
.command(["disorder",
111 "--config", disorder
._configfile
,
112 "--no-per-user-config",
113 "schedule-set-global",
114 time
.strftime("%Y-%m-%d %H:%M:%S",
115 time
.localtime(now
+ 4)),
119 print " disorder schedule-list output:"
120 print string
.join(dtest
.command(["disorder",
121 "--config", disorder
._configfile
,
122 "--no-per-user-config",
123 "schedule-list"]), ""),
124 print " waiting for it to take effect"
127 while p
is None and waited
< 10:
131 assert waited
< 10, "checking a track played within a reasonable period"
132 assert waited
> 2, "checking a track didn't play immediately"
133 print " disabling random play"
135 print " waiting for nothing to be playing"
136 while c
.playing() is not None:
138 print " scheduling a track for the future"
139 now
= int(time
.time())
140 c
.schedule_add(now
+ 4, "normal", "play", track
)
141 print " schedule via python:"
142 s
= c
.schedule_list()
144 e
= c
.schedule_get(event
)
145 print "item %s: %s" %
(event
, e
)
146 print " deleting item %s" % s
[0]
148 print " checking it's really gone"
149 s
= c
.schedule_list()
150 assert s
== [], "checking schedule is empty"
153 while p
is None and waited
< 10:
157 assert p
is None, "checking deleted scheduled event did not run"
158 print " checking you can't schedule events for the past"
160 now
= int(time
.time())
161 c
.schedule_add(now
- 4, "normal", "play", track
)
162 assert False, "checking schedule_add failed"
163 except disorder
.operationError
:
167 if __name__
== '__main__':