chiark / gitweb /
Python test script for the scheduling code.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 24 May 2008 10:58:46 +0000 (11:58 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 24 May 2008 10:58:46 +0000 (11:58 +0100)
python/disorder.py.in
tests/Makefile.am
tests/schedule.py [new file with mode: 0755]

index 867b901c046547387146f047e7b02505a7ae78ec..3cc300c27c25bd9171d0d097bfd2f7a78bbb5deb 100644 (file)
@@ -905,7 +905,7 @@ class client:
 
   def schedule_add(self, when, priority, action, *rest):
     """Add a scheduled event"""
 
   def schedule_add(self, when, priority, action, *rest):
     """Add a scheduled event"""
-    self._simple("schedule-add", when, priorty, action, *rest)
+    self._simple("schedule-add", str(when), priority, action, *rest)
 
   ########################################################################
   # I/O infrastructure
 
   ########################################################################
   # I/O infrastructure
index d21edcbdbd57fd0c106d7a10d44273dfd5df4524..9358b196b8609e0d8ce3ce8f1c3b7aa3a0f8ff7c 100644 (file)
@@ -27,7 +27,8 @@ disorder_udplog_LDADD=$(LIBOBJS) ../lib/libdisorder.a
 disorder_udplog_DEPENDENCIES=../lib/libdisorder.a
 
 TESTS=cookie.py dbversion.py dump.py files.py play.py queue.py \
 disorder_udplog_DEPENDENCIES=../lib/libdisorder.a
 
 TESTS=cookie.py dbversion.py dump.py files.py play.py queue.py \
-       recode.py search.py user-upgrade.py user.py aliases.py
+       recode.py search.py user-upgrade.py user.py aliases.py  \
+       schedule.py
 
 TESTS_ENVIRONMENT=${PYTHON} -u
 
 
 TESTS_ENVIRONMENT=${PYTHON} -u
 
diff --git a/tests/schedule.py b/tests/schedule.py
new file mode 100755 (executable)
index 0000000..2e5eaac
--- /dev/null
@@ -0,0 +1,65 @@
+#! /usr/bin/env python
+#
+# This file is part of DisOrder.
+# Copyright (C) 2008 Richard Kettlewell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+import dtest,disorder,time
+
+def test():
+    """Exercise schedule support"""
+    dtest.start_daemon()
+    dtest.create_user()
+    c = disorder.client()
+    c.random_disable()
+    dtest.rescan()
+    # Wait until there's no track playing
+    print " waiting for nothing to be playing"
+    while c.playing() is not None:
+        time.sleep(1)
+    now = int(time.time())
+    track = "%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest.tracks
+    print " scheduling a track for the future"
+    c.schedule_add(now + 4, "normal", "play", track)
+    print " waiting for it to play"
+    waited = 0
+    p = c.playing()
+    while p is None and waited < 10:
+        time.sleep(1)
+        waited += 1
+        p = c.playing()
+    assert waited < 10, "checking track played within a reasonable period"
+    assert waited > 2, "checking track didn't play immediately"
+    assert p["track"] == track, "checking right track played"
+    print " waiting for nothing to be playing"
+    while c.playing() is not None:
+        time.sleep(1)
+    print " scheduling an enable-random for the future"
+    now = int(time.time())
+    c.schedule_add(now + 4, "normal", "set-global", "random-play", "yes")
+    print " waiting for it to take effect"
+    waited = 0
+    p = c.playing()
+    while p is None and waited < 10:
+        time.sleep(1)
+        waited += 1
+        p = c.playing()
+    assert waited < 10, "checking a track played within a reasonable period"
+    assert waited > 2, "checking a track didn't play immediately"
+
+if __name__ == '__main__':
+    dtest.run()