From: Richard Kettlewell Date: Wed, 21 Nov 2007 10:41:23 +0000 (+0000) Subject: more test fiddling X-Git-Tag: debian-1_5_99dev8~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/5c07ba71b9ea3444dddb22dc373a4afe55ad5568 more test fiddling --- diff --git a/.bzrignore b/.bzrignore index f9d8ac1..230d66a 100644 --- a/.bzrignore +++ b/.bzrignore @@ -117,3 +117,4 @@ server/disorder-stats *.deb *.dsc disobedience/disobedience.html +tests/*.log 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/dtest.py b/tests/dtest.py index 937d83e..552542a 100644 --- a/tests/dtest.py +++ b/tests/dtest.py @@ -105,17 +105,12 @@ def stdtracks(): def notracks(): pass -def start(test): - """start(TEST) +def start(): + """start() -Start the daemon for test called TEST.""" +Start the daemon.""" global daemon assert daemon == None - if test == None: - errs = sys.stderr - else: - errs = open("%s/%s.log" % (testroot, test), "w") - server = None print " starting daemon" daemon = subprocess.Popen(["disorderd", "--foreground", @@ -129,6 +124,8 @@ def stop(): Stop the daemon if it has not stopped already""" global daemon + if daemon == None: + return rc = daemon.poll() if rc == None: print " stopping daemon" @@ -137,16 +134,30 @@ Stop the daemon if it has not stopped already""" print " daemon has stopped" daemon = None -def run(test, setup=None, report=True, name=None): +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 + 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__ + global errs + errs = open("%s.log" % name, "w") + setup = stdtracks setup() - start(name) try: try: - test() + module.test() except AssertionError, e: global failures failures += 1 diff --git a/tests/nothing.py b/tests/nothing.py index 34cc706..aeb0308 100755 --- a/tests/nothing.py +++ b/tests/nothing.py @@ -22,7 +22,9 @@ import dtest,time def test(): """Just start the server and then stop it a few seconds later""" - time.sleep(5) + dtest.start() + time.sleep(2) + dtest.stop() if __name__ == '__main__': - dtest.run(test) + dtest.run() diff --git a/tests/version.py b/tests/version.py index 760a65c..6fd42df 100755 --- a/tests/version.py +++ b/tests/version.py @@ -22,10 +22,12 @@ import dtest,time,disorder def test(): """Ask the server its version number""" + dtest.start() time.sleep(2) # give the daemon a chance to start up c = disorder.client() v = c.version() print "Server version: %s" % v + dtest.stop() if __name__ == '__main__': - dtest.run(test) + dtest.run()