[Checkins] SVN: Sandbox/J1m/customdoctests/ Added tests for parser.
Jim Fulton
jim at zope.com
Wed May 18 17:06:45 EDT 2011
Log message for revision 121720:
Added tests for parser.
(In doing so, realized that overriding ps2 doesn't work
and it's not worth fixing.)
Changed:
U Sandbox/J1m/customdoctests/buildout.cfg
A Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt
U Sandbox/J1m/customdoctests/src/zc/customdoctests/__init__.py
A Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py
-=-
Modified: Sandbox/J1m/customdoctests/buildout.cfg
===================================================================
--- Sandbox/J1m/customdoctests/buildout.cfg 2011-05-18 19:37:24 UTC (rev 121719)
+++ Sandbox/J1m/customdoctests/buildout.cfg 2011-05-18 21:06:44 UTC (rev 121720)
@@ -4,7 +4,7 @@
[test]
recipe = zc.recipe.testrunner
-eggs =
+eggs = zc.customdoctests
[py]
recipe = zc.recipe.egg
Added: Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt
===================================================================
--- Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt (rev 0)
+++ Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt 2011-05-18 21:06:44 UTC (rev 121720)
@@ -0,0 +1,25 @@
+Custom doctest parsers
+======================
+
+zc.customdoctests provides a little bit of help with creating custom
+doctest parsers that work pretty muct like regular doctests, but that
+use an alternate means of evaluating examples. To use it, you call
+zc.customdoctests.DocTestParser and pass any of the following options:
+
+ps1
+ The first-line prompt, which defaultd to ``'>>>'``.
+
+ (Note that you can't override the second-line prompt.)
+
+comment_prefix
+ The comment prefix string, which defaults to '#'.
+
+transform
+ A function used to transform example source, which defaults to a
+ no-operation function.
+
+The js module provides support for using JavaScript in doctests using
+`python-spidermonkey
+<http://pypi.python.org/pypi/python-spidermonkey>`_ or `selenium
+<http://pypi.python.org/pypi/selenium>`. It provides some examples of
+defining custom doctest parsers.
Property changes on: Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: Sandbox/J1m/customdoctests/src/zc/customdoctests/__init__.py
===================================================================
--- Sandbox/J1m/customdoctests/src/zc/customdoctests/__init__.py 2011-05-18 19:37:24 UTC (rev 121719)
+++ Sandbox/J1m/customdoctests/src/zc/customdoctests/__init__.py 2011-05-18 21:06:44 UTC (rev 121720)
@@ -21,7 +21,6 @@
def __init__(self, *args, **kw):
ps1 = kw.pop('ps1', '>>>')
- ps2 = kw.pop('ps2', r'\.\.\.')
comment_prefix = kw.pop('comment_prefix', '#')
self.transform = kw.pop('transform', lambda s: s)
getattr(doctest.DocTestParser, '__init__', lambda : None)(*args, **kw)
@@ -31,14 +30,14 @@
# Source consists of a PS1 line followed by zero or more PS2 lines.
(?P<source>
(?:^(?P<indent> [ ]*) %(ps1)s .*) # PS1 line
- (?:\n [ ]* %(ps2)s .*)*) # PS2 lines
+ (?:\n [ ]* \.\.\. .*)*) # PS2 lines
\n?
# Want consists of any non-blank lines that do not start with PS1.
(?P<want> (?:(?![ ]*$) # Not a blank line
(?![ ]*%(ps1)s) # Not a line starting with PS1
.*$\n? # But any other line
)*)
- ''' % dict(ps1=ps1, ps2=ps2), re.MULTILINE | re.VERBOSE)
+ ''' % dict(ps1=ps1), re.MULTILINE | re.VERBOSE)
self._OPTION_DIRECTIVE_RE = re.compile(
comment_prefix +r'\s*doctest:\s*([^\n\'"]*)$', re.MULTILINE)
Added: Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py
===================================================================
--- Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py (rev 0)
+++ Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py 2011-05-18 21:06:44 UTC (rev 121720)
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+# from zope.testing import setupstack
+# import manuel.capture
+# import manuel.doctest
+# import manuel.testing
+import unittest
+import doctest
+
+import zc.customdoctests
+
+
+def custom_doctest_parser():
+ r"""
+ >>> [e] = zc.customdoctests.DocTestParser().get_examples('''
+ ...
+ ... >>> 2 + 2 # doctest: +ELLIPSIS
+ ... 5
+ ...
+ ... ''')
+ >>> e.source, e.want, e.options == {doctest.ELLIPSIS: True}
+ ('2 + 2 # doctest: +ELLIPSIS\n', '5\n', True)
+
+ >>> [e] = zc.customdoctests.DocTestParser(
+ ... ps1='js>', comment_prefix='//', transform=lambda s: 'JS(%r)' % s
+ ... ).get_examples('''
+ ...
+ ... js> 2 +
+ ... ... 2 // doctest: +ELLIPSIS
+ ... 5
+ ...
+ ... >>> x
+ ... 1
+ ...
+ ... ''')
+ >>> e.source, e.want, e.options == {doctest.ELLIPSIS: True}
+ ("JS('2 +\\n2 // doctest: +ELLIPSIS\\n')", '5\n', True)
+
+ """
+
+
+
+def test_suite():
+ return doctest.DocTestSuite()
+
+
Property changes on: Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
More information about the checkins
mailing list