Package epydoc :: Package test
[hide private]
[frames] | no frames]

Source Code for Package epydoc.test

 1  # epydoc -- Regression testing 
 2  # 
 3  # Copyright (C) 2005 Edward Loper 
 4  # Author: Edward Loper <edloper@loper.org> 
 5  # URL: <http://epydoc.sf.net> 
 6  # 
 7  # $Id: __init__.py 1502 2007-02-14 08:38:44Z edloper $ 
 8   
 9  """ 
10  Regression testing. 
11  """ 
12  __docformat__ = 'epytext en' 
13   
14  import unittest, doctest, epydoc, os, os.path, re, sys 
15   
16 -def main():
17 try: 18 doctest.register_optionflag 19 except: 20 print ("\n" 21 "The regression test suite requires a more recent version of\n" 22 "doctest (e.g., the version that ships with Python 2.4 or 2.5).\n" 23 "Please place a new version of doctest on your path before \n" 24 "running the test suite.\n") 25 return 26 27 28 PY24 = doctest.register_optionflag('PYTHON2.4') 29 """Flag indicating that a doctest example requires Python 2.4+""" 30 31 PY25 = doctest.register_optionflag('PYTHON2.5') 32 """Flag indicating that a doctest example requires Python 2.5+""" 33 34 class DocTestParser(doctest.DocTestParser): 35 """ 36 Custom doctest parser that adds support for two new flags 37 +PYTHON2.4 and +PYTHON2.5. 38 """ 39 def parse(self, string, name='<string>'): 40 pieces = doctest.DocTestParser.parse(self, string, name) 41 for i, val in enumerate(pieces): 42 if (isinstance(val, doctest.Example) and 43 ((val.options.get(PY24, False) and 44 sys.version[:2] < (2,4)) or 45 (val.options.get(PY25, False) and 46 sys.version[:2] < (2,5)))): 47 pieces[i] = doctest.Example('1', '1') 48 return pieces
49 50 # Turn on debugging. 51 epydoc.DEBUG = True 52 53 # Options for doctest: 54 options = doctest.ELLIPSIS 55 doctest.set_unittest_reportflags(doctest.REPORT_UDIFF) 56 57 # Use a custom parser 58 parser = DocTestParser() 59 60 # Find all test cases. 61 tests = [] 62 testdir = os.path.join(os.path.split(__file__)[0]) 63 if testdir == '': testdir = '.' 64 for filename in os.listdir(testdir): 65 if (filename.endswith('.doctest') and 66 check_requirements(os.path.join(testdir, filename))): 67 tests.append(doctest.DocFileSuite(filename, optionflags=options, 68 parser=parser)) 69 70 # Run all test cases. 71 unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests)) 72
73 -def check_requirements(filename):
74 """ 75 Search for strings of the form:: 76 77 [Require: <module>] 78 79 If any are found, then try importing the module named <module>. 80 If the import fails, then return False. If all required modules 81 are found, return True. (This includes the case where no 82 requirements are listed.) 83 """ 84 s = open(filename).read() 85 for m in re.finditer('(?mi)^[ ]*\:RequireModule:(.*)$', s): 86 module = m.group(1).strip() 87 try: 88 __import__(module) 89 except ImportError: 90 print ('Skipping %r (required module %r not found)' % 91 (os.path.split(filename)[-1], module)) 92 return False 93 return True
94 95 96 if __name__=='__main__': 97 main() 98