chiark / gitweb /
(c) notice on tests
[disorder] / tests / dtest.py
index fcafb1337cd99726416a980339956d3ed9721901..776a3ad43a8102e1c74822332ca963af92e436ac 100644 (file)
@@ -1,8 +1,27 @@
 #-*-python-*-
+#
+# This file is part of DisOrder.
+# Copyright (C) 2007 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
+#
 
 """Utility module used by tests"""
 
-import os,os.path,subprocess,sys
+import os,os.path,subprocess,sys,disorder
 
 def copyfile(a,b):
     """copyfile(A, B)
@@ -13,7 +32,7 @@ def maketrack(s):
     """maketrack(S)
 
 Make track with relative path S exist"""
-    trackpath = "%s/%s" % (testroot, s)
+    trackpath = "%s/tracks/%s" % (testroot, s)
     trackdir = os.path.dirname(trackpath)
     if not os.path.exists(trackdir):
         os.makedirs(trackdir)
@@ -64,6 +83,8 @@ Start the daemon for test called TEST."""
                                "--foreground",
                                "--config", "%s/config" % testroot],
                               stderr=errs)
+    disorder._configfile = "%s/config" % testroot
+    disorder._userconf = False
 
 def stop():
     """stop()
@@ -72,6 +93,7 @@ Stop the daemon if it has not stopped already"""
     global daemon
     rc = daemon.poll()
     if rc == None:
+        print " stopping daemon"
         os.kill(daemon.pid, 15)
         rc = daemon.wait()
     print " daemon has stopped"
@@ -85,13 +107,14 @@ def run(test, setup=None, report=True, name=None):
     setup()
     start(name)
     try:
-        test()
-    except AssertionError, e:
-        global failures
-        failures += 1
-        print e
-        
-    stop()
+        try:
+            test()
+        except AssertionError, e:
+            global failures
+            failures += 1
+            print e
+    finally:
+        stop()
     if report:
         if failures:
             print " FAILED"
@@ -121,8 +144,8 @@ testroot = "%s/testroot" % os.getcwd()
 topsrcdir = os.path.abspath(os.getenv("topsrcdir"))
 remove_dir(testroot)
 os.mkdir(testroot)
-open("%s/config" % testroot, "w").write("""
-player *.ogg shell 'echo "$TRACK" >> %s/played.log'
+open("%s/config" % testroot, "w").write(
+"""player *.ogg shell 'echo "$TRACK" >> %s/played.log'
 home %s
 collection fs ASCII %s/tracks
 scratch %s/scratch.ogg
@@ -132,6 +155,18 @@ stopword 1 2 3 4 5 6 7 8 9
 stopword 11 12 13 14 15 16 17 18 19 20
 stopword 21 22 23 24 25 26 27 28 29 30
 stopword the a an and to too in on of we i am as im for is
+username fred
+password fredpass
+allow fred fredpass
+plugins ../plugins
+player *.mp3 execraw disorder-decode
+player *.ogg execraw disorder-decode
+player *.wav execraw disorder-decode
+player *.flac execraw disorder-decode
+tracklength *.mp3 disorder-tracklength
+tracklength *.ogg disorder-tracklength
+tracklength *.wav disorder-tracklength
+tracklength *.flac disorder-tracklength
 """ % (testroot, testroot, testroot, testroot))
 copyfile("%s/sounds/scratch.ogg" % topsrcdir,
          "%s/scratch.ogg" % testroot)