3 # This file is part of DisOrder.
4 # Copyright (C) 2008, 2009 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 3 of the License, or
9 # (at your option) any later version.
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.
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/>.
19 import dtest
,disorder
,time
,string
22 """Return the current time in whole seconds"""
23 return int(time
.time())
26 print " waiting for track to play"
29 while p
is None and waited
< 10:
33 assert waited
< 10, "track played in a reasonable time"
37 print " waiting for nothing to be playing"
40 while p
is not None and waited
< 20:
44 assert waited
< 20, "idled in a reasonable time"
47 """Exercise schedule support"""
53 # Wait until there's no track playing
54 print " waiting for nothing to be playing"
55 while c
.playing() is not None:
58 track
= "%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest
.tracks
59 print " scheduling a track for the future"
61 c
.schedule_add(when
, "normal", "play", track
)
62 print " disorder schedule-list output:"
63 print string
.join(dtest
.command(["disorder",
64 "--config", disorder
._configfile
,
65 "--no-per-user-config",
66 "schedule-list"]), ""),
68 assert p
["track"] == track
, "checking right track played"
69 print " when=%d expected at least %d" %
(int(p
["when"]), when
)
70 assert int(p
["when"]) >= when
, "checking track played at right time"
71 assert c
.schedule_list() == [], "checking schedule is empty"
73 print " scheduling an enable-random for the future"
74 c
.schedule_add(now() + 3, "junk", "set-global", "random-play", "yes")
75 print " disorder schedule-list output:"
76 print string
.join(dtest
.command(["disorder",
77 "--config", disorder
._configfile
,
78 "--no-per-user-config",
79 "schedule-list"]), ""),
81 print " disabling random play"
84 print " scheduling track to play later via command line"
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(when
)),
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"]), ""),
100 assert p
["track"] == track
, "checking right track played"
101 assert p
["when"] >= when
, "checking track played at right time"
102 assert c
.schedule_list() == [], "checking schedule is empty"
104 print " scheduling an enable-random for later via command line"
105 dtest
.command(["disorder",
106 "--config", disorder
._configfile
,
107 "--no-per-user-config",
108 "schedule-set-global",
109 time
.strftime("%Y-%m-%d %H:%M:%S",
110 time
.localtime(now() + 3)),
114 print " disorder schedule-list output:"
115 print string
.join(dtest
.command(["disorder",
116 "--config", disorder
._configfile
,
117 "--no-per-user-config",
118 "schedule-list"]), ""),
120 print " disabling random play"
122 print " waiting for nothing to be playing"
123 while c
.playing() is not None:
126 print " scheduling a track for the future"
127 c
.schedule_add(now() + 3, "normal", "play", track
)
128 print " schedule via python:"
129 s
= c
.schedule_list()
131 e
= c
.schedule_get(event
)
132 print "item %s: %s" %
(event
, e
)
133 print " deleting item %s" % s
[0]
135 print " checking it's really gone"
136 s
= c
.schedule_list()
137 assert s
== [], "checking schedule is empty"
140 while p
is None and waited
< 5:
145 assert p
is None, "checking deleted scheduled event did not run"
146 print " checking you can't schedule events for the past"
148 c
.schedule_add(now() - 4, "normal", "play", track
)
149 assert False, "checking schedule_add failed"
150 except disorder
.operationError
:
152 print " checking scheduled events survive restarts"
154 c
.schedule_add(when
, "normal", "play", track
)
156 print " dumping database"
157 dump
= "%s/dumpfile" % dtest
.testroot
158 print dtest
.command(["disorder-dump", "--config", disorder
._configfile
,
160 print "restoring database"
161 print dtest
.command(["disorder-dump", "--config", disorder
._configfile
,
164 c
= disorder
.client()
166 print " waiting for track to play"
167 assert p
["track"] == track
, "checking right track played"
168 assert p
["when"] >= when
, "checking track played at right time"
169 assert c
.schedule_list() == [], "checking schedule is empty"
170 print " checking junk events do not survive restarts"
171 c
.schedule_add(now() + 2, "junk", "play", track
)
172 s
= c
.schedule_list()
177 c
= disorder
.client()
178 print " checking schedule is empty"
179 s
= c
.schedule_list()
181 assert s
== [], "checking schedule is empty"
183 if __name__
== '__main__':