__init__.py :  » Development » Epydoc » epydoc-3.0.1 » epydoc » test » 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 » Development » Epydoc 
Epydoc » epydoc 3.0.1 » epydoc » test » __init__.py
# epydoc -- Regression testing
#
# Copyright (C) 2005 Edward Loper
# Author: Edward Loper <edloper@loper.org>
# URL: <http://epydoc.sf.net>
#
# $Id: __init__.py 1502 2007-02-14 08:38:44Z edloper $

"""
Regression testing.
"""
__docformat__ = 'epytext en'

import unittest, doctest, epydoc, os, os.path, re, sys

def main():
    try:
        doctest.register_optionflag
    except:
        print ("\n"
            "The regression test suite requires a more recent version of\n"
            "doctest (e.g., the version that ships with Python 2.4 or 2.5).\n"
            "Please place a new version of doctest on your path before \n"
            "running the test suite.\n")
        return
                          
    
    PY24 = doctest.register_optionflag('PYTHON2.4')
    """Flag indicating that a doctest example requires Python 2.4+"""
    
    PY25 = doctest.register_optionflag('PYTHON2.5')
    """Flag indicating that a doctest example requires Python 2.5+"""
    
    class DocTestParser(doctest.DocTestParser):
        """
        Custom doctest parser that adds support for two new flags
        +PYTHON2.4 and +PYTHON2.5.
        """
        def parse(self, string, name='<string>'):
            pieces = doctest.DocTestParser.parse(self, string, name)
            for i, val in enumerate(pieces):
                if (isinstance(val, doctest.Example) and
                    ((val.options.get(PY24, False) and
                      sys.version[:2] < (2,4)) or
                     (val.options.get(PY25, False) and
                      sys.version[:2] < (2,5)))):
                    pieces[i] = doctest.Example('1', '1')
            return pieces

    # Turn on debugging.
    epydoc.DEBUG = True
    
    # Options for doctest:
    options = doctest.ELLIPSIS
    doctest.set_unittest_reportflags(doctest.REPORT_UDIFF)

    # Use a custom parser
    parser = DocTestParser()
    
    # Find all test cases.
    tests = []
    testdir = os.path.join(os.path.split(__file__)[0])
    if testdir == '': testdir = '.'
    for filename in os.listdir(testdir):
        if (filename.endswith('.doctest') and
            check_requirements(os.path.join(testdir, filename))):
            tests.append(doctest.DocFileSuite(filename, optionflags=options,
                                              parser=parser))
            
    # Run all test cases.
    unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests))

def check_requirements(filename):
    """
    Search for strings of the form::
    
        [Require: <module>]

    If any are found, then try importing the module named <module>.
    If the import fails, then return False.  If all required modules
    are found, return True.  (This includes the case where no
    requirements are listed.)
    """
    s = open(filename).read()
    for m in re.finditer('(?mi)^[ ]*\:RequireModule:(.*)$', s):
        module = m.group(1).strip()
        try:
            __import__(module)
        except ImportError:
            print ('Skipping %r (required module %r not found)' %
                   (os.path.split(filename)[-1], module))
            return False
    return True
            

if __name__=='__main__':
    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.