[Epydoc-commits] SF.net SVN: epydoc: [1502] trunk/epydoc/src/epydoc/test
Brought to you by:
edloper
From: <ed...@us...> - 2007-02-14 08:38:46
|
Revision: 1502 http://svn.sourceforge.net/epydoc/?rev=1502&view=rev Author: edloper Date: 2007-02-14 00:38:44 -0800 (Wed, 14 Feb 2007) Log Message: ----------- - Fixed various test bugs; updated tests so now they run cleanly under Python 2.3 (assuming you're using a recent version of doctest.py) Modified Paths: -------------- trunk/epydoc/src/epydoc/test/__init__.py trunk/epydoc/src/epydoc/test/docbuilder.doctest trunk/epydoc/src/epydoc/test/docintrospecter.doctest trunk/epydoc/src/epydoc/test/docparser.doctest trunk/epydoc/src/epydoc/test/encoding.doctest trunk/epydoc/src/epydoc/test/pyval_repr.doctest trunk/epydoc/src/epydoc/test/restructuredtext.doctest trunk/epydoc/src/epydoc/test/util.py Modified: trunk/epydoc/src/epydoc/test/__init__.py =================================================================== --- trunk/epydoc/src/epydoc/test/__init__.py 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/__init__.py 2007-02-14 08:38:44 UTC (rev 1502) @@ -11,9 +11,42 @@ """ __docformat__ = 'epytext en' -import unittest, doctest, epydoc, os, os.path, re +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 @@ -21,6 +54,9 @@ 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]) @@ -28,7 +64,8 @@ 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)) + tests.append(doctest.DocFileSuite(filename, optionflags=options, + parser=parser)) # Run all test cases. unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests)) @@ -45,8 +82,8 @@ requirements are listed.) """ s = open(filename).read() - for m in re.finditer('(?mi)^[ ]*\:RequireModule:[ ]+(\w+)[ ]*$', s): - module = m.group(1) + for m in re.finditer('(?mi)^[ ]*\:RequireModule:(.*)$', s): + module = m.group(1).strip() try: __import__(module) except ImportError: Modified: trunk/epydoc/src/epydoc/test/docbuilder.doctest =================================================================== --- trunk/epydoc/src/epydoc/test/docbuilder.doctest 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/docbuilder.doctest 2007-02-14 08:38:44 UTC (rev 1502) @@ -177,10 +177,10 @@ +- name = '__init__' +- value +- RoutineDoc for epydoc_test.Foo.__init__ [2] - +- arg_descrs = [([u'x'], [u'first', u'param']), ... + +- arg_descrs = [([u'x'], u'first param'), ([u'y'], u... +- arg_types = {} +- docstring = u'__init__ doc' - +- exception_descrs = [(DottedName(u'ValueError'), ... + +- exception_descrs = [(DottedName(u'ValueError'), <epydoc.... +- kwarg = None +- posargs = [u'x', u'y'] +- vararg = None @@ -242,8 +242,8 @@ | +- type_descr = None | +- value | +- RoutineDoc for epydoc_test.Foo.__init__ [2] - | +- arg_descrs = [([u'a'], [u'init', u'param.'])] - | +- arg_types = {u'a': [u'date']} + | +- arg_descrs = [([u'a'], u'init param.')] + | +- arg_types = {u'a': u'date'} | +- kwarg = None | +- posargs = ['self', 'a'] | +- vararg = None @@ -276,8 +276,8 @@ | +- type_descr = None | +- value | +- RoutineDoc for epydoc_test.Foo.__init__ [2] - | +- arg_descrs = [([u'a'], [u'init', u'param.'])] - | +- arg_types = {u'a': [u'string']} + | +- arg_descrs = [([u'a'], u'init param.')] + | +- arg_types = {u'a': u'string'} | +- kwarg = None | +- posargs = ['self', 'a'] | +- vararg = None @@ -294,6 +294,7 @@ current behavior; but should be replaced when we change the behavior. >>> from epydoc.test.util import buildvaluedoc + >>> from epydoc.compat import * >>> def print_py_reprs(s): ... value_doc = buildvaluedoc(s) ... print 'Var Score Repr\n'+'-'*50 Modified: trunk/epydoc/src/epydoc/test/docintrospecter.doctest =================================================================== --- trunk/epydoc/src/epydoc/test/docintrospecter.doctest 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/docintrospecter.doctest 2007-02-14 08:38:44 UTC (rev 1502) @@ -252,7 +252,8 @@ Decorators & Wrapper Assignments ================================ - >>> runintrospecter(s=""" + >>> runintrospecter( # doctest: +PYTHON2.4 + ... s=""" ... @classmethod ... def f(cls, x): 'docstring for f' ... """, introspect="f") Modified: trunk/epydoc/src/epydoc/test/docparser.doctest =================================================================== --- trunk/epydoc/src/epydoc/test/docparser.doctest 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/docparser.doctest 2007-02-14 08:38:44 UTC (rev 1502) @@ -82,7 +82,7 @@ | | +- ModuleDoc for epydoc_test [0] (defined above) | +- docs_extracted_by = 'parser' | +- parse_repr = u'[1, 2, 3]+ [4, 5]' - | +- toktree = [[(51, u'['), (2, u'1'), (51, u','), ... + | +- toktree = ... +- z => VariableDoc for epydoc_test.z [5] +- container | +- ModuleDoc for epydoc_test [0] (defined above) @@ -98,7 +98,7 @@ | +- ModuleDoc for epydoc_test [0] (defined above) +- docs_extracted_by = 'parser' +- parse_repr = u'f(x, y)' - +- toktree = [(1, u'f'), [(51, u'('), (1, u'x'), (... + +- toktree = ... In this example, DocParser decides that the assignment to y is creating an alias. The same `ValueDoc` is shared by both variables. @@ -466,11 +466,12 @@ Decorators & Wrapper Assignments ================================ - >>> runparser(s=""" + >>> runparser( # doctest: +PYTHON2.4 + ... s=""" ... @classmethod ... def f(cls, x): 'docstring for f' ... """, - ... attribs='variables value docstring posargs') + ... attribs='variables value docstring posargs') ModuleDoc for epydoc_test [0] +- docstring = <UNKNOWN> +- variables Modified: trunk/epydoc/src/epydoc/test/encoding.doctest =================================================================== --- trunk/epydoc/src/epydoc/test/encoding.doctest 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/encoding.doctest 2007-02-14 08:38:44 UTC (rev 1502) @@ -122,7 +122,7 @@ >>> testencoding('''# -*- coding: shift_jis -*- ... """abc ABC 123 \xA1 \xA2 \xA3""" - ... ''') + ... ''') # doctest: +PYTHON2.4 abc ABC 123 。 「 」 Str/Unicode Test Modified: trunk/epydoc/src/epydoc/test/pyval_repr.doctest =================================================================== --- trunk/epydoc/src/epydoc/test/pyval_repr.doctest 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/pyval_repr.doctest 2007-02-14 08:38:44 UTC (rev 1502) @@ -42,7 +42,7 @@ Strings have their quotation marks tagged as 'quote'. Characters are escaped using the 'string-escape' encoding. - >>> color(''.join(chr(i) for i in range(256))) + >>> color(''.join([chr(i) for i in range(256)])) <code class="variable-quote">'''</code><code class="variable-string">\x00\x01\x02\x03\x04\x05\x06\x07\x08\</code>↵ <code class="variable-string">t</code> <code class="variable-string">\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x</code>↵ @@ -129,7 +129,7 @@ >>> def textcontent(elt): ... if isinstance(elt, basestring): return elt - ... else: return ''.join(textcontent(c) for c in elt.children) + ... else: return ''.join([textcontent(c) for c in elt.children]) >>> import re >>> def color_re(s, check_roundtrip=True): Modified: trunk/epydoc/src/epydoc/test/restructuredtext.doctest =================================================================== --- trunk/epydoc/src/epydoc/test/restructuredtext.doctest 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/restructuredtext.doctest 2007-02-14 08:38:44 UTC (rev 1502) @@ -148,8 +148,8 @@ | +- type_descr = None | +- value | +- RoutineDoc for epydoc_test.Foo.__init__ [2] - | +- arg_descrs = [([u'a'], [u'init', u'param.'])] - | +- arg_types = {u'a': [u'string']} + | +- arg_descrs = [([u'a'], u'init param.')] + | +- arg_types = {u'a': u'string'} | +- exception_descrs = [(DottedName(u'ValueError'), ... | +- kwarg = None | +- posargs = ['self', 'a'] Modified: trunk/epydoc/src/epydoc/test/util.py =================================================================== --- trunk/epydoc/src/epydoc/test/util.py 2007-02-14 08:36:59 UTC (rev 1501) +++ trunk/epydoc/src/epydoc/test/util.py 2007-02-14 08:38:44 UTC (rev 1502) @@ -188,7 +188,7 @@ """Conver a parsed docstring into plain text""" if isinstance(docstring, ParsedDocstring): docstring = docstring.to_plaintext(None) - return docstring.rsplit() + return docstring.rstrip() def fun_to_plain(val_doc): """Convert parsed docstrings in text from a RoutineDoc""" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |