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

Chris Withers chrisw@nipltd.com
Wed, 30 Jan 2002 08:04:37 -0500


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

Added Files:
	autotester.py 
Log Message:
Here's an auto-test runner than works on Windows as well. I intend to run it daily on weekdays using the 'at' command and mail the results to zope-coders@zope.org.

=== Added File Packages/TestScripts/autotester.py ===
# System Requirements
# -------------------
# 1. CVS accessible via the command line
# 2. Python 2.1 or above available via the command line
# 3. MS VC++ 6.0 or above installed and available via
#    the command line if running on windows

from os.path import join
from os import system, mkdir, rmdir, chdir, environ, getcwd
# tweak stuff here for your setup

# Mail info
email_address = 'chrisw@nipltd.com'
email_subject = 'Win32 Zope Test Results'
email_smtp    = 'smtp.nipltd.com'

# Set up any necessary environment variables
environ['CVSROOT']=':pserver:anonymous@cvs.zope.org:/cvs-repository'

# CVS info
cvs_command = r'cvs'

# this maps python version string to command line to use
python = {
    '2.1':'python',
    }

# Where stuff happens, this must exist
wd = r"E:\ZopeTests\\"

# This is a list of scenarios to test
# Each scenario is, in turn, a tupe of the form:
# (python_version, modules)
#
# where:
#
# python_version if a key into the 'python' dictionary
# modules is a list of tuples of the form:
#
# (module,name,tag,location)
# 
# where:
#
# module   is the CVS module to checkout
# name     is the name to check the module out as
# tag      is the tag to use when checking the module out
# location is the location to check the module out relative
#          to the working directory

scenarios = [
    # Zope Head + CMF
    (
    '2.1',
    [
    ('Zope', 'Zope', 'HEAD', ''),
    ('CMF/CMFCore',     'CMFCore',     'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFCalendar', 'CMFCalendar', 'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFCollector','CMFCollector','HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFDecor',    'CMFDecor',    'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFDefault',  'CMFDefault',  'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFTopic',    'CMFTopic',    'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFTracker',  'CMFTracker',  'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFWiki',     'CMFWiki',     'HEAD', join('Zope','lib','python','Products')),
    ('CMF/DCWorkflow',  'DCWorkflow',  'HEAD', join('Zope','lib','python','Products')),
    ]
    ),
    # Zope 2.5 branch + CMF
    (
    '2.1',
    [
    ('Zope', 'Zope', 'Zope-2_5-branch', ''),
    ('CMF/CMFCore',     'CMFCore',     'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFCalendar', 'CMFCalendar', 'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFCollector','CMFCollector','HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFDecor',    'CMFDecor',    'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFDefault',  'CMFDefault',  'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFTopic',    'CMFTopic',    'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFTracker',  'CMFTracker',  'HEAD', join('Zope','lib','python','Products')),
    ('CMF/CMFWiki',     'CMFWiki',     'HEAD', join('Zope','lib','python','Products')),
    ('CMF/DCWorkflow',  'DCWorkflow',  'HEAD', join('Zope','lib','python','Products')),
    ]
    ),
    ]
    
# the module containing Zope
zope_module = "Zope"

# THE CODE
#
# nothing tweakable below here
from shutil import rmtree
from mailer import send



chdir(wd)
body = open('body.txt','w')

for python_version, scenario in scenarios:

    chdir(wd)
    
    # blow away whatever was there, if there was anything there
    try:
        rmtree(zope_module)
    except:
        pass

    # do the CVS checkouts
    for (module,name,tag,location) in scenario:
        # change dir to the right place
        chdir(join(wd,location))
        # do the checkout
        system(cvs_command+" export -r "+tag+" -d "+name+" "+module)

    # get the python command
    p = python[python_version]
    
    # change to the Zope location
    chdir(join(wd,zope_module))

    # build Zope
    system(p+' '+join('Utilities','ExtensionBuilder.py')+" -z")

    # get the python version string
    system(p+' -c "import sys; print sys.version" > version.txt')
    
    # run the tests
    system(p+' '+join('Utilities','testrunner.py')+' -v 0 -a -o result.txt')

    # append the results to body.txt
    body.write('='*80+'\n')
    body.write('='*80+'\n')
    body.write('Python Version:%s\n' % open('version.txt').read().strip())
    body.write('\n')
    body.write('Modules included:\n')
    for (module,name,tag,l) in scenario:
        body.write("%s (%s)\n" % (module,tag))
    body.write('\n')
    body.write(open('result.txt').read())
    body.write('\n')
    body.write('='*80+'\n')
    body.write('='*80+'\n')

# close off the results file
body.close()
chdir(wd)

# send the mail
send(email_address,
     email_subject,
     open('body.txt').read(),
     smtp_server=email_smtp)