Commit | Line | Data |
---|---|---|
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 | 21 | import dtest,disorder,time,string |
17360d2f RK |
22 | |
23 | def 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" | |
6c13a317 | 53 | assert c.schedule_list() == [], "checking schedule is empty" |
17360d2f RK |
54 | print " waiting for nothing to be playing" |
55 | while c.playing() is not None: | |
56 | time.sleep(1) | |
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") | |
758aa6c3 RK |
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"]), ""), | |
17360d2f RK |
65 | print " waiting for it to take effect" |
66 | waited = 0 | |
67 | p = c.playing() | |
68 | while p is None and waited < 10: | |
69 | time.sleep(1) | |
70 | waited += 1 | |
71 | p = c.playing() | |
72 | assert waited < 10, "checking a track played within a reasonable period" | |
73 | assert waited > 2, "checking a track didn't play immediately" | |
6c13a317 RK |
74 | print " disabling random play" |
75 | c.random_disable() | |
76 | print " waiting for nothing to be playing" | |
77 | while c.playing() is not None: | |
78 | time.sleep(1) | |
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", | |
84 | "schedule-play", | |
85 | str(now + 4), | |
86 | "normal", | |
87 | track]) | |
88 | print " disorder schedule-list output:" | |
89 | print string.join(dtest.command(["disorder", | |
90 | "--config", disorder._configfile, | |
91 | "--no-per-user-config", | |
92 | "schedule-list"]), ""), | |
93 | print " waiting for it to play" | |
94 | waited = 0 | |
95 | p = c.playing() | |
96 | while p is None and waited < 10: | |
97 | time.sleep(1) | |
98 | waited += 1 | |
99 | p = c.playing() | |
100 | assert waited < 10, "checking track played within a reasonable period" | |
101 | assert waited > 2, "checking track didn't play immediately" | |
102 | assert p["track"] == track, "checking right track played" | |
103 | assert c.schedule_list() == [], "checking schedule is empty" | |
104 | print " waiting for nothing to be playing" | |
105 | while c.playing() is not None: | |
106 | time.sleep(1) | |
107 | print " scheduling an enable-random for later via command line" | |
108 | now = int(time.time()) | |
109 | dtest.command(["disorder", | |
110 | "--config", disorder._configfile, | |
111 | "--no-per-user-config", | |
112 | "schedule-set-global", | |
113 | str(now + 4), | |
114 | "normal", | |
115 | "random-play", | |
116 | "yes"]) | |
117 | print " disorder schedule-list output:" | |
118 | print string.join(dtest.command(["disorder", | |
119 | "--config", disorder._configfile, | |
120 | "--no-per-user-config", | |
121 | "schedule-list"]), ""), | |
122 | print " waiting for it to take effect" | |
123 | waited = 0 | |
124 | p = c.playing() | |
125 | while p is None and waited < 10: | |
126 | time.sleep(1) | |
127 | waited += 1 | |
128 | p = c.playing() | |
129 | assert waited < 10, "checking a track played within a reasonable period" | |
130 | assert waited > 2, "checking a track didn't play immediately" | |
131 | print " disabling random play" | |
132 | c.random_disable() | |
133 | print " waiting for nothing to be playing" | |
134 | while c.playing() is not None: | |
135 | time.sleep(1) | |
136 | print " scheduling a track for the future" | |
137 | now = int(time.time()) | |
138 | c.schedule_add(now + 4, "normal", "play", track) | |
139 | print " schedule via python:" | |
140 | s = c.schedule_list() | |
141 | for event in s: | |
142 | e = c.schedule_get(event) | |
143 | print "item %s: %s" % (event, e) | |
144 | print " deleting item %s" % s[0] | |
145 | c.schedule_del(s[0]) | |
146 | print " checking it's really gone" | |
147 | s = c.schedule_list() | |
148 | assert s == [], "checking schedule is empty" | |
149 | waited = 0 | |
150 | p = c.playing() | |
151 | while p is None and waited < 10: | |
152 | time.sleep(1) | |
153 | waited += 1 | |
154 | p = c.playing() | |
155 | assert p is None, "checking deleted scheduled event did not run" | |
156 | print " checking you can't schedule events for the past" | |
157 | try: | |
158 | now = int(time.time()) | |
159 | c.schedule_add(now - 4, "normal", "play", track) | |
160 | assert False, "checking schedule_add failed" | |
161 | except disorder.operationError: | |
162 | pass # good | |
163 | ||
17360d2f RK |
164 | |
165 | if __name__ == '__main__': | |
166 | dtest.run() |