runAll.py :  » PDF » ReportLab » ReportLab_2_4 » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » PDF » ReportLab 
ReportLab » ReportLab_2_4 » tests » runAll.py
#!/usr/bin/env python
#Copyright ReportLab Europe Ltd. 2000-2008
#see license.txt for license details
"""Runs all test files in all subfolders.
"""
__version__=''' $Id: runAll.py 3296 2008-09-17 12:56:33Z jonas $ '''
import os, glob, sys, string, traceback, unittest

#we need to ensure 'tests' is on the path.  It will be if you
#run 'setup.py tests', but won't be if you CD into the tests
#directory and run this directly
if __name__=='__main__':
    P=[]
    try:
        from reportlab.lib.testutils import setOutDir
    except ImportError:
        if __name__=='__main__':
            topDir = os.path.dirname(sys.argv[0])
            if not topDir: topDir = os.getcwd()
        else:
            topDir = os.path.dirname(__file__)
        topDir = os.path.dirname(os.path.abspath(topDir))
        if not os.path.isdir(os.path.join(topDir,'reportlab')):
            topDir=os.path.join(topDir,'src')
            assert os.path.isdir(os.path.join(topDir,'reportlab')), "Cannot find reportlab"
        sys.path.insert(0, topDir)
        P.append(topDir)
        del topDir
        from reportlab.lib.testutils import setOutDir

    setOutDir(__name__)
    from reportlab.lib.testutils import testsFolder
    if topDir:
        topDir = os.path.dirname(topDir)
        if topDir not in sys.path:
            sys.path.insert(0,topDir)
            P.append(topDir)
    del topDir
    from reportlab.lib.testutils import GlobDirectoryWalker,outputfile,printLocation
    pp = os.environ.get('PYTHONPATH','')
    if pp: P.append(pp)
    del pp
    os.environ['PYTHONPATH']=os.pathsep.join(P)
    del P

def makeSuite(folder, exclude=[],nonImportable=[],pattern='test_*.py'):
    "Build a test suite of all available test files."
    allTests = unittest.TestSuite()

    if os.path.isdir(folder): sys.path.insert(0, folder)
    for filename in GlobDirectoryWalker(folder, pattern):
        modname = os.path.splitext(os.path.basename(filename))[0]
        if modname not in exclude:
            try:
                exec 'import %s as module' % modname
                allTests.addTest(module.makeSuite())
            except:
                tt, tv, tb = sys.exc_info()[:]
                nonImportable.append((filename,traceback.format_exception(tt,tv,tb)))
                del tt,tv,tb
    del sys.path[0]

    return allTests


def main(pattern='test_*.py'):
    try:
        folder = os.path.dirname(__file__)
        assert folder
    except:
        folder = os.path.dirname(sys.argv[0]) or os.getcwd()
    #allow for Benn's "screwball cygwin distro":
    if not folder:
        folder = '.'
    from reportlab.lib.utils import isSourceDistro
    haveSRC = isSourceDistro()

    def cleanup(folder,patterns=('*.pdf', '*.log','*.svg','runAll.txt', 'test_*.txt','_i_am_actually_a_*.*')):
        if not folder: return
        for pat in patterns:
            for filename in GlobDirectoryWalker(folder, pattern=pat):
                try:
                    os.remove(filename)
                except:
                    pass

    # special case for tests directory - clean up
    # all PDF & log files before starting run.  You don't
    # want this if reusing runAll anywhere else.
    if string.find(folder, os.sep+'tests') > -1: cleanup(folder)
    cleanup(outputfile(''))
    NI = []
    cleanOnly = '--clean' in sys.argv
    if not cleanOnly:
        testSuite = makeSuite(folder,nonImportable=NI,pattern=pattern+(not haveSRC and 'c' or ''))
        unittest.TextTestRunner().run(testSuite)

    if haveSRC: cleanup(folder,patterns=('*.pyc','*.pyo'))
    if not cleanOnly:
        if NI:
            sys.stderr.write('\n###################### the following tests could not be imported\n')
            for f,tb in NI:
                print 'file: "%s"\n%s\n' % (f,string.join(tb,''))
        printLocation()

def mainEx():
    '''for use in subprocesses'''
    try:
        main()
    finally:
        sys.stdout.flush()
        sys.stderr.flush()
        sys.stdout.close()
        os.close(sys.stderr.fileno())

def runExternally():
    cmd = sys.executable+' -c"from tests import runAll;runAll.mainEx()"'
    i,o,e=os.popen3(cmd)
    i.close()
    out = o.read()
    err=e.read()
    return '\n'.join((out,err))

def checkForFailure(outerr):
    return '\nFAILED' in outerr

if __name__ == '__main__': #noruntests
    main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.