From 17360d2f794cff1015d2ab7366a71503cd6e8462 Mon Sep 17 00:00:00 2001 Message-Id: <17360d2f794cff1015d2ab7366a71503cd6e8462.1714910642.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 24 May 2008 11:58:46 +0100 Subject: [PATCH] Python test script for the scheduling code. Organization: Straylight/Edgeware From: Richard Kettlewell --- python/disorder.py.in | 2 +- tests/Makefile.am | 3 +- tests/schedule.py | 65 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100755 tests/schedule.py diff --git a/python/disorder.py.in b/python/disorder.py.in index 867b901..3cc300c 100644 --- a/python/disorder.py.in +++ b/python/disorder.py.in @@ -905,7 +905,7 @@ class client: 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 diff --git a/tests/Makefile.am b/tests/Makefile.am index d21edcb..9358b19 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ - 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 diff --git a/tests/schedule.py b/tests/schedule.py new file mode 100755 index 0000000..2e5eaac --- /dev/null +++ b/tests/schedule.py @@ -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() -- [mdw]