[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] New tests for many areas of the system; slight refactor...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.seul.org:/tmp/cvs-serv9171/lib/mixminion

Modified Files:
	test.py testSupport.py 
Log Message:
New tests for many areas of the system; slight refactoring

test:
	- Add helper methods to make/read files
	- Move suspendLog/resumeLog into testSupport
	- Simplify do_header_test interface
	- Adapt _decodeAndEscapeMessage tests for _escapeMessage
	- Add unit tests for MBOX module
	- Add unit tests for SMTP-Via-Mixmaster module
	- Add unit tests for Directorystore testing module
	- Change Keystore tests to test new simplified client keystore code
	- Clarify XXXX comments
	- Normalize whitespace

testSupport:
	- Move suspendLog/resumeLog into testSupport
	- Add queue support to testing module
	- Add replace-attribute code to temporarily override functions and
	  methods



Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- test.py	22 Nov 2002 21:12:05 -0000	1.38
+++ test.py	2 Dec 2002 03:25:46 -0000	1.39
@@ -20,14 +20,19 @@
 import re
 import base64
 import stat
+import types
 import cPickle
 import cStringIO
 
-from mixminion.testSupport import mix_mktemp
+import mixminion.testSupport
+from mixminion.testSupport import mix_mktemp, suspendLog, resumeLog, \
+     replaceAttribute, undoReplacedAttributes, replaceFunction, \
[...1096 lines suppressed...]
+	return suite
+
     suite.addTest(tc(MiscTests))
     suite.addTest(tc(MinionlibCryptoTests))
     suite.addTest(tc(CryptoTests))
@@ -3227,12 +3412,13 @@
 def testAll(name, args):
     init_crypto()
 
-    # Suppress 'files-can't-be-securely-deleted message while testing'
+    # Suppress 'files-can't-be-securely-deleted' message while testing
     getLog().setMinSeverity("FATAL")
     mixminion.Common.secureDelete([],1)
 
     # Disable TRACE and DEBUG log messages, unless somebody overrides from
     # the environment.
     getLog().setMinSeverity(os.environ.get('MM_TEST_LOGLEVEL', "WARN"))
+    #getLog().setMinSeverity(os.environ.get('MM_TEST_LOGLEVEL', "TRACE"))
 
     unittest.TextTestRunner(verbosity=1).run(testSuite())

Index: testSupport.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/testSupport.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- testSupport.py	22 Nov 2002 21:12:05 -0000	1.7
+++ testSupport.py	2 Dec 2002 03:25:46 -0000	1.8
@@ -10,8 +10,10 @@
 import sys
 import stat
 import base64
+import cStringIO
 
-from mixminion.Common import waitForChildren, createPrivateDir
+import mixminion.Common
+from mixminion.Common import waitForChildren, createPrivateDir, getLog
 from mixminion.Config import _parseBoolean, ConfigError
 from mixminion.Modules import DeliveryModule, ImmediateDeliveryQueue, \
      SimpleModuleDeliveryQueue, DELIVER_OK, DELIVER_FAIL_RETRY, \
@@ -37,7 +39,6 @@
 	# loc = sections['Testing/DirectoryDump'].get('Location')
 	pass 
     
-    
     def configure(self, config, manager):
 	self.loc = config['Testing/DirectoryDump'].get('Location')
 	if not self.loc:
@@ -65,7 +66,7 @@
     
     def createDeliveryQueue(self, queueDir):
 	if self.useQueue:
-	    return SimpleModuleDeliveryQueue()#XXXX
+	    return SimpleModuleDeliveryQueue(self, queueDir)
 	else:
 	    return ImmediateDeliveryQueue(self)
 	
@@ -77,6 +78,8 @@
 	elif exitInfo == 'FAIL!':
 	    return DELIVER_FAIL_NORETRY
 
+	getLog().debug("Delivering test message")
+
 	m = _escapeMessageForEmail(message, tag)
 	if m is None:
 	    # Ordinarily, we'd drop these.
@@ -181,3 +184,83 @@
             os.rmdir(d)
         elif os.path.exists(d):
             os.unlink(d)
+
+#----------------------------------------------------------------------
+
+def suspendLog(severity=None):
+    """Temporarily suppress logging output."""
+    log = getLog()
+    if hasattr(log, '_storedHandlers'):
+	resumeLog()
+    buf = cStringIO.StringIO()
+    h = mixminion.Common._ConsoleLogHandler(buf)
+    log._storedHandlers = log.handlers
+    log._storedSeverity = log.severity
+    log._testBuf = buf
+    log.handlers = []
+    if severity is not None:
+	log.setMinSeverity(severity)
+    log.addHandler(h)
+
+def resumeLog():
+    """Resume logging output.  Return all new log messages since the last
+       suspend."""
+    log = getLog()
+    if not hasattr(log, '_storedHandlers'):
+	return None
+    buf = log._testBuf
+    del log._testBuf
+    log.handlers = log._storedHandlers
+    del log._storedHandlers
+    log.setMinSeverity(log._storedSeverity)
+    del log._storedSeverity
+    return buf.getvalue()
+
+#----------------------------------------------------------------------
+
+# list of obj, attr, oldval.
+_REPLACED_OBJECT_STACK = []
+
+def replaceAttribute(object, attribute, value):
+    "DOCDOC"
+    if hasattr(object, attribute):
+	tup = (object, attribute, getattr(object, attribute))
+    else:
+	tup = (object, attribute)
+    _REPLACED_OBJECT_STACK.append(tup)
+    setattr(object, attribute, value)
+
+_CALL_LOG = []
+
+class _ReplacementFunc:
+    def __init__(self, name, fn=None):
+	self.name = name
+	self.fn = fn
+    def __call__(self, *args, **kwargs):
+	_CALL_LOG.append((self.name, args, kwargs))
+	if self.fn:
+	    return self.fn(*args, **kwargs)
+	else:
+	    return None
+
+def replaceFunction(object, attribute, fn=None):
+    replaceAttribute(object, attribute, _ReplacementFunc(attribute, fn))
+
+def getReplacedFunctionCallLog():
+    return _CALL_LOG
+
+def clearReplacedFunctionCallLog():
+    del _CALL_LOG[:]
+
+def undoReplacedAttributes():
+    "DOCDOC"
+    r = _REPLACED_OBJECT_STACK[:]
+    r.reverse()
+    del _REPLACED_OBJECT_STACK[:]
+    for item in r:
+	if len(item) == 2:
+	    o,a = item
+	    delattr(o,a)
+	else:
+	    o,a,v = item
+	    setattr(o,a,v)