chiark / gitweb /
add a nontrivial test that actually works
authorRichard Kettlewell <rjk@greenend.org.uk>
Mon, 19 Nov 2007 21:15:26 +0000 (21:15 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Mon, 19 Nov 2007 21:15:26 +0000 (21:15 +0000)
python/disorder.py.in
tests/Makefile.am
tests/alltests
tests/dtest.py
tests/version.py [new file with mode: 0755]

index eb5850700fbd45a4889889836db4de64e4fbe9e8..5becda13e6dd771e5afdc8a4643e51f1ad4ed733 100644 (file)
@@ -53,6 +53,7 @@ import locale
 
 _configfile = "pkgconfdir/config"
 _dbhome = "pkgstatedir"
 
 _configfile = "pkgconfdir/config"
 _dbhome = "pkgstatedir"
+_userconf = True
 
 # various regexps we'll use
 _ws = re.compile(r"^[ \t\n\r]+")
 
 # 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)
     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'
 
       self._readfile(passfile)
     self.state = 'disconnected'
 
index ae009349587a98da718dd087d689140439fa912f..645dd5416ae9386e1b47fde480dd501d1249db2b 100644 (file)
@@ -24,4 +24,4 @@ check:
                topsrcdir=${top_srcdir} \
                ${PYTHON} ${srcdir}/alltests
 
                topsrcdir=${top_srcdir} \
                ${PYTHON} ${srcdir}/alltests
 
-EXTRA_DIST=alltests dtest.py nothing.py
+EXTRA_DIST=alltests dtest.py nothing.py version.py
index fe0f3836860acc290d18586bacd7e2611aa21e00..c8f04c7574acd07f0d8f7614fd9c270c69f1fda8 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 import dtest
 
 #! /usr/bin/env python
 import dtest
 
-tests = ["nothing"]
+tests = ["nothing", "version"]
 
 for test in tests:
     print "Test '%s'" % test
 
 for test in tests:
     print "Test '%s'" % test
index 85a54ccba2c97711f9a151fece9d50ecdeea46d9..ff19f2a868d70c1ae420ba3c58408dc7aa4a4bf9 100644 (file)
@@ -2,7 +2,7 @@
 
 """Utility module used by tests"""
 
 
 """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)
 
 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)
                                "--foreground",
                                "--config", "%s/config" % testroot],
                               stderr=errs)
+    disorder._configfile = "%s/config" % testroot
+    disorder._userconf = False
 
 def stop():
     """stop()
 
 def stop():
     """stop()
@@ -72,6 +74,7 @@ Stop the daemon if it has not stopped already"""
     global daemon
     rc = daemon.poll()
     if rc == None:
     global daemon
     rc = daemon.poll()
     if rc == None:
+        print " stopping daemon"
         os.kill(daemon.pid, 15)
         rc = daemon.wait()
     print " daemon has stopped"
         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:
     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"
     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
 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)
 """ % (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 (executable)
index 0000000..3566867
--- /dev/null
@@ -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)