[Zope-CVS] CVS: Packages/TestScripts - autotester.py:1.5

Chris Withers chrisw@nipltd.com
Fri, 8 Mar 2002 03:46:57 -0500


Update of /cvs-repository/Packages/TestScripts
In directory cvs.zope.org:/tmp/cvs-serv18967

Modified Files:
	autotester.py 
Log Message:
Added support for environment variable setting and messages/scenario titles.

=== Packages/TestScripts/autotester.py 1.4 => 1.5 ===
 from os.path import join
 from sys import argv
-from os import system, makedirs, rmdir, chdir, environ, getcwd, popen3
+from os import system, makedirs, rmdir, chdir, environ, getcwd, popen3, environ
 from shutil import rmtree
 from mailer import send
 from xml2dict import xml2dict
@@ -86,6 +86,12 @@
     # get the python command
     p = config['python'][0][scenario['python'][0]()][0]()
 
+    # set up the environment
+    old_environment={}
+    for key,value in scenario.get('environment',[{}])[0].items():
+        old_environment[key]=environ.get(key)
+        environ[key]=value[0]()
+
     # get the python version string
     python_version = execute('',p,'',' -c "import sys; print sys.version"')
     
@@ -95,6 +101,13 @@
     # run the tests
     test_result = xml_execute(scenario['test'],p)
     
+    # return the environment state
+    for key,value in old_environment.items():
+        if value is None:
+            del environ[key]
+        else:
+            environ[key]=value
+    
     # write the results to the appropriate StringIO
     address = scenario['email'][0]()
     body = emails.get(address)
@@ -102,8 +115,11 @@
         body = StringIO()
         emails[address]=body
         
-    body.write('='*80+'\n')
-    body.write('='*80+'\n')
+    linewidth=78
+    body.write('='*linewidth+'\n')
+    for message in scenario.get('message',()):
+        body.write(message().strip()+'\n')
+    body.write('='*linewidth+'\n')
     body.write('Python Version:%s\n' % python_version.strip())
     body.write('\n')
     body.write('Modules included:\n')
@@ -112,8 +128,8 @@
     body.write('\n')
     body.write(test_result)
     body.write('\n')
-    body.write('='*80+'\n')
-    body.write('='*80+'\n')
+    body.write('='*linewidth+'\n')
+    body.write('='*linewidth+'\n')
 
 # send the mail
 email = config['email'][0]