From eee9d4b35bfae67b6e988d72abf01da4a6282278 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Mon, 19 Nov 2007 21:15:26 +0000 Subject: [PATCH] add a nontrivial test that actually works Organization: Straylight/Edgeware From: Richard Kettlewell --- python/disorder.py.in | 3 ++- tests/Makefile.am | 2 +- tests/alltests | 2 +- tests/dtest.py | 23 +++++++++++++++-------- tests/version.py | 12 ++++++++++++ 5 files changed, 31 insertions(+), 11 deletions(-) create mode 100755 tests/version.py diff --git a/python/disorder.py.in b/python/disorder.py.in index eb58507..5becda1 100644 --- a/python/disorder.py.in +++ b/python/disorder.py.in @@ -53,6 +53,7 @@ import locale _configfile = "pkgconfdir/config" _dbhome = "pkgstatedir" +_userconf = True # various regexps we'll use _ws = re.compile(r"^[ \t\n\r]+") @@ -291,7 +292,7 @@ class client: self._readfile(_configfile) if os.path.exists(privconf): self._readfile(privconf) - if os.path.exists(passfile): + if os.path.exists(passfile) and _userconf: self._readfile(passfile) self.state = 'disconnected' diff --git a/tests/Makefile.am b/tests/Makefile.am index ae00934..645dd54 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,4 +24,4 @@ check: topsrcdir=${top_srcdir} \ ${PYTHON} ${srcdir}/alltests -EXTRA_DIST=alltests dtest.py nothing.py +EXTRA_DIST=alltests dtest.py nothing.py version.py diff --git a/tests/alltests b/tests/alltests index fe0f383..c8f04c7 100755 --- a/tests/alltests +++ b/tests/alltests @@ -1,7 +1,7 @@ #! /usr/bin/env python import dtest -tests = ["nothing"] +tests = ["nothing", "version"] for test in tests: print "Test '%s'" % test diff --git a/tests/dtest.py b/tests/dtest.py index 85a54cc..ff19f2a 100644 --- a/tests/dtest.py +++ b/tests/dtest.py @@ -2,7 +2,7 @@ """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) @@ -64,6 +64,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 +74,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 +88,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" @@ -132,6 +136,9 @@ 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 """ % (testroot, testroot, testroot, testroot)) copyfile("%s/sounds/scratch.ogg" % topsrcdir, "%s/scratch.ogg" % testroot) diff --git a/tests/version.py b/tests/version.py new file mode 100755 index 0000000..3566867 --- /dev/null +++ b/tests/version.py @@ -0,0 +1,12 @@ +#! /usr/bin/env python +import dtest,time,disorder + +def test(): + """Ask the server its version number""" + time.sleep(2) # give the daemon a chance to start up + c = disorder.client() + v = c.version() + print "Server version: %s" % v + +if __name__ == '__main__': + dtest.run(test) -- [mdw]