3 # This file is part of DisOrder.
4 # Copyright (C) 2007 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 2 of the License, or
9 # (at your option) any later version.
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.
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
22 """Utility module used by tests"""
24 import os
,os
.path
,subprocess
,sys
,re
27 """Write an error message and exit"""
28 sys
.stderr
.write("ERROR: %s\n" % s
)
31 # Identify the top build directory
33 if os
.path
.exists("config.h"):
35 elif os
.path
.exists("alltests"):
36 top_builddir
= os
.path
.dirname(cwd
)
38 fatal("cannot identify build directory")
40 # Make sure the Python build directory is on the module search path
41 sys
.path
.insert(0, os
.path
.join(top_builddir
, "python"))
44 # Make sure the server build directory is on the executable search path
45 ospath
= os
.environ
["PATH"].split(os
.pathsep
)
46 ospath
.insert(0, os
.path
.join(top_builddir
, "server"))
47 os
.environ
["PATH"] = os
.pathsep
.join(ospath
)
49 # Parse the makefile in the current directory to identify the source directory
51 for l
in file("Makefile"):
52 r
= re
.match("top_srcdir *= *(.*)", l
)
54 top_srcdir
= r
.group(1)
57 fatal("cannot identify source directory")
59 # The tests source directory must be on the module search path already since
62 # -----------------------------------------------------------------------------
67 open(b
,"w").write(open(a
).read())
72 Make track with relative path S exist"""
73 trackpath
= "%s/tracks/%s" %
(testroot
, s
)
74 trackdir
= os
.path
.dirname(trackpath
)
75 if not os
.path
.exists(trackdir
):
77 copyfile("%s/sounds/slap.ogg" % top_srcdir
, trackpath
)
80 maketrack("Joe Bloggs/First Album/01:First track.ogg")
81 maketrack("Joe Bloggs/First Album/02:Second track.ogg")
82 maketrack("Joe Bloggs/First Album/03:Third track.ogg")
83 maketrack("Joe Bloggs/First Album/04:Fourth track.ogg")
84 maketrack("Joe Bloggs/First Album/05:Fifth track.ogg")
85 maketrack("Joe Bloggs/First Album/05:Fifth track.ogg")
86 maketrack("Joe Bloggs/Second Album/01:First track.ogg")
87 maketrack("Joe Bloggs/Second Album/02:Second track.ogg")
88 maketrack("Joe Bloggs/Second Album/03:Third track.ogg")
89 maketrack("Joe Bloggs/Second Album/04:Fourth track.ogg")
90 maketrack("Joe Bloggs/Second Album/05:Fifth track.ogg")
91 maketrack("Joe Bloggs/Second Album/05:Fifth track.ogg")
92 maketrack("Joe Bloggs/First Album/01:First track.ogg")
93 maketrack("Joe Bloggs/First Album/02:Second track.ogg")
94 maketrack("Joe Bloggs/First Album/03:Third track.ogg")
95 maketrack("Joe Bloggs/First Album/04:Fourth track.ogg")
96 maketrack("Joe Bloggs/First Album/05:Fifth track.ogg")
97 maketrack("Fred Smith/Boring/01:Dull.ogg")
98 maketrack("Fred Smith/Boring/02:Tedious.ogg")
99 maketrack("Fred Smith/Boring/03:Drum Solo.ogg")
100 maketrack("Fred Smith/Boring/04:Yawn.ogg")
101 maketrack("misc/blahblahblah.ogg")
102 maketrack("Various/Greatest Hits/01:Jim Whatever - Spong.ogg")
103 maketrack("Various/Greatest Hits/02:Joe Bloggs - Yadda.ogg")
111 Start the daemon for test called TEST."""
113 assert daemon
== None
117 errs
= open("%s/%s.log" %
(testroot
, test
), "w")
119 print " starting daemon"
120 daemon
= subprocess
.Popen(["disorderd",
122 "--config", "%s/config" % testroot
],
124 disorder
._configfile
= "%s/config" % testroot
125 disorder
._userconf
= False
130 Stop the daemon if it has not stopped already"""
134 print " stopping daemon"
135 os
.kill(daemon
.pid
, 15)
137 print " daemon has stopped"
140 def run(test
, setup
=None, report
=True, name
=None):
150 except AssertionError, e
:
166 Recursively delete directory D"""
167 if os
.path
.lexists(d
):
169 for dd
in os
.listdir(d
):
170 remove_dir("%s/%s" %
(d
, dd
))
175 # -----------------------------------------------------------------------------
181 testroot
= "%s/tests/testroot" % top_builddir
184 open("%s/config" % testroot
, "w").write(
185 """player *.ogg shell 'echo "$TRACK" >> %s/played.log'
187 collection fs ASCII %s/tracks
188 scratch %s/scratch.ogg
190 stopword 01 02 03 04 05 06 07 08 09 10
191 stopword 1 2 3 4 5 6 7 8 9
192 stopword 11 12 13 14 15 16 17 18 19 20
193 stopword 21 22 23 24 25 26 27 28 29 30
194 stopword the a an and to too in on of we i am as im for is
199 player *.mp3 execraw disorder-decode
200 player *.ogg execraw disorder-decode
201 player *.wav execraw disorder-decode
202 player *.flac execraw disorder-decode
203 tracklength *.mp3 disorder-tracklength
204 tracklength *.ogg disorder-tracklength
205 tracklength *.wav disorder-tracklength
206 tracklength *.flac disorder-tracklength
207 """ %
(testroot
, testroot
, testroot
, testroot
, top_builddir
))
208 copyfile("%s/sounds/scratch.ogg" % top_srcdir
,
209 "%s/scratch.ogg" % testroot
)