test_extra.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 » test_extra.py
"""This executes tests defined outside the normal test suite.
See docstring for class ExternalTestCase for more information.
"""
from reportlab.lib.testutils import setOutDir,SecureTestCase,printLocation
setOutDir(__name__)
import os, string, fnmatch, re, sys, unittest
EXTRA_FILE = 'extra.txt'

class ExternalTestCase(SecureTestCase):
    """Test case starting cases external to the normal RL suite.

    This test case runs additional test cases defined in external
    modules which must also be using the unittest framework.
    These additional modules must be defined in a file named
    'extra.txt' which needs to be located in the tests
    folder and contains one path per line.

    The paths of these modules can contain stuff from the Unix
    world like '~', '.', '..' and '$HOME' and can have absolute
    or relative paths. If they are relative they start from the
    tests folder.

    This is a sample 'extra.txt' file:

        foo.py
        ./foo.py
        bar/foo.py
        ../foo.py
        /bar/foo.py
        ~/foo.py
        ~/bar/foo.py
        ~/../foo.py
        $HOME/bar/foo.py
    """

    def test0(self):
        "Execute external test cases."

        cwd = os.getcwd()

        # look for a file named 'extra.txt' in test directory,
        # exit if not found
        from reportlab.lib.testutils import RL_HOME
        extraFilename = os.path.join(RL_HOME, 'test', EXTRA_FILE)
        if not os.path.exists(extraFilename):
            return

        # read module paths from file
        extraModulenames = open(extraFilename).readlines()
        extraModulenames = map(string.strip, extraModulenames)

        # expand pathnames as much as possible
        for f in extraModulenames:
            if f == '':
                continue
            if f[0] == '#':
                continue
            f = os.path.expanduser(f)
            f = os.path.expandvars(f)
            f = os.path.abspath(f)

            if os.path.exists(f):
                # look for a makeSuite function and execute it if present
                folder = os.path.abspath(os.path.dirname(f))
                modname = os.path.splitext(os.path.basename(f))[0]
                os.chdir(folder)
                sys.path.insert(0, folder)

                module = __import__(modname) # seems to fail sometimes...
                if 'makeSuite' in dir(module):
                    print "running", f
                    testSuite = module.makeSuite()
                    unittest.TextTestRunner().run(testSuite)
                os.chdir(cwd)
                sys.path = sys.path[1:]


def makeSuite():
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    if sys.platform[:4] != 'java':
        suite.addTest(loader.loadTestsFromTestCase(ExternalTestCase))

    return suite


#noruntests
if __name__ == "__main__":
    if len(sys.argv) > 1:
        EXTRA_FILE = sys.argv[1]
        assert os.path.isfile(EXTRA_FILE), 'file %s not found!' % EXTRA_FILE
    # otherwise, extra.txt will be used
    unittest.TextTestRunner().run(makeSuite())
    printLocation()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.