From: Richard Kettlewell Date: Wed, 21 Nov 2007 11:18:34 +0000 (+0000) Subject: sync up with disorder.dev X-Git-Tag: debian-1_5_99dev9~1^2~15 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/0db97c0d2f4568c2b5b5f5f9b791b8025b4732aa?hp=fbcfb25715ddbb522c8efac3faec1eca4811683d sync up with disorder.dev --- diff --git a/tests/alltests b/tests/alltests index 4e3f64d..b115f7d 100755 --- a/tests/alltests +++ b/tests/alltests @@ -40,6 +40,8 @@ import dtest # call dtest.run tests = [] for f in os.listdir(testdir): + if f == 'dtest.py': # special case + continue r = re.search("^(.*)\\.py$", f) if r is not None: isTest = False @@ -55,11 +57,7 @@ tests.sort() # let's have a consistent order for test in tests: print "Test '%s'" % test - m = __import__(test) - dtest.run(getattr(m, "test"), - setup=getattr(m, "setup", None), - report=False, - name=test) + dtest.run(test, report=False) print "%d tests" % dtest.tests if dtest.failures: diff --git a/tests/dbversion.py b/tests/dbversion.py index e5b5c48..9849bf3 100644 --- a/tests/dbversion.py +++ b/tests/dbversion.py @@ -50,4 +50,4 @@ def test(): sys.exit(1) if __name__ == '__main__': - dtest.run(test) + dtest.run() diff --git a/tests/dtest.py b/tests/dtest.py index b5cc9c9..26fca75 100644 --- a/tests/dtest.py +++ b/tests/dtest.py @@ -139,10 +139,7 @@ def stdtracks(): maketrack("misc/blahblahblah.ogg") maketrack("Various/Greatest Hits/01:Jim Whatever - Spong.ogg") maketrack("Various/Greatest Hits/02:Joe Bloggs - Yadda.ogg") - -def notracks(): - pass - + def common_setup(): remove_dir(testroot) os.mkdir(testroot) @@ -160,7 +157,7 @@ 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 +plugins %s/plugins player *.mp3 execraw disorder-decode player *.ogg execraw disorder-decode player *.wav execraw disorder-decode @@ -169,16 +166,16 @@ tracklength *.mp3 disorder-tracklength tracklength *.ogg disorder-tracklength tracklength *.wav disorder-tracklength tracklength *.flac disorder-tracklength -""" % (testroot, testroot, testroot, testroot)) +""" % (testroot, testroot, testroot, testroot, top_builddir)) copyfile("%s/sounds/scratch.ogg" % top_srcdir, "%s/scratch.ogg" % testroot) def start_daemon(): """start_daemon() + Start the daemon.""" - global daemon,errs - assert daemon is None - server = None + global daemon, errs + assert daemon == None print " starting daemon" daemon = subprocess.Popen(["disorderd", "--foreground", @@ -190,7 +187,8 @@ def stop_daemon(): Stop the daemon if it has not stopped already""" global daemon - assert daemon is not None + if daemon == None: + return rc = daemon.poll() if rc == None: print " stopping daemon" @@ -199,26 +197,43 @@ Stop the daemon if it has not stopped already""" print " daemon has stopped" daemon = None -def run(test, setup=None, report=True, name=None): - global tests,errs +def run(module=None, report=True): + """dtest.run(MODULE) + + Run the test in MODULE. This can be a string (in which case the module + will be imported) or a module object.""" + global tests tests += 1 - if setup == None: - setup = stdtracks - errs = open("%s.log" % test.__name__, "w") + # Locate the test module + if module is None: + # We're running a test stand-alone + import __main__ + module = __main__ + name = os.path.splitext(os.path.basename(sys.argv[0]))[0] + else: + # We've been passed a module or a module name + if type(module) == str: + module = __import__(module) + name = module.__name__ + # Open the error log + global errs + errs = open("%s.log" % name, "w") + # Ensure that disorder.py uses the test installation disorder._configfile = "%s/config" % testroot disorder._userconf = False + # Make config file etc common_setup() - setup() + # Create some standard tracks + stdtracks() try: try: - test() + module.test() except AssertionError, e: global failures failures += 1 print e finally: - if daemon is not None: - stop_daemon() + stop_daemon() if report: if failures: print " FAILED" diff --git a/tests/files.py b/tests/files.py index 2f636ec..89375a6 100755 --- a/tests/files.py +++ b/tests/files.py @@ -53,4 +53,4 @@ def test(): sys.exit(1) if __name__ == '__main__': - dtest.run(test) + dtest.run() diff --git a/tests/nothing.py b/tests/nothing.py index a635f7f..f3bdeb9 100755 --- a/tests/nothing.py +++ b/tests/nothing.py @@ -26,4 +26,4 @@ def test(): time.sleep(2) if __name__ == '__main__': - dtest.run(test) + dtest.run() diff --git a/tests/version.py b/tests/version.py index 1eaef87..dbb0df6 100755 --- a/tests/version.py +++ b/tests/version.py @@ -29,4 +29,4 @@ def test(): print "Server version: %s" % v if __name__ == '__main__': - dtest.run(test) + dtest.run()