[Python-modules-commits] [python-zc.customdoctests] 01/04: import python-zc.customdoctests_1.0.1.orig.tar.gz
Julien Muchembled
jmuchemb-guest at moszumanska.debian.org
Tue Dec 6 08:49:29 UTC 2016
This is an automated email from the git hooks/post-receive script.
jmuchemb-guest pushed a commit to branch master
in repository python-zc.customdoctests.
commit 79d82f5ecf7ef138aa9068518d72d566007216c3
Author: Julien Muchembled <jm at jmuchemb.eu>
Date: Mon Dec 5 13:13:59 2016 +0100
import python-zc.customdoctests_1.0.1.orig.tar.gz
---
CHANGES.txt | 21 ++
MANIFEST.in | 9 +
PKG-INFO | 218 +++++++++++++++++++++
README.txt | 19 ++
buildout.cfg | 17 ++
setup.cfg | 5 +
setup.py | 74 +++++++
src/zc.customdoctests.egg-info/PKG-INFO | 218 +++++++++++++++++++++
src/zc.customdoctests.egg-info/SOURCES.txt | 19 ++
.../dependency_links.txt | 1 +
.../namespace_packages.txt | 1 +
src/zc.customdoctests.egg-info/not-zip-safe | 1 +
src/zc.customdoctests.egg-info/requires.txt | 8 +
src/zc.customdoctests.egg-info/top_level.txt | 1 +
src/zc/__init__.py | 5 +
src/zc/customdoctests/README.txt | 26 +++
src/zc/customdoctests/__init__.py | 55 ++++++
src/zc/customdoctests/js.py | 124 ++++++++++++
src/zc/customdoctests/spidermonkey.txt | 120 ++++++++++++
src/zc/customdoctests/tests.py | 71 +++++++
tox.ini | 26 +++
21 files changed, 1039 insertions(+)
diff --git a/CHANGES.txt b/CHANGES.txt
new file mode 100644
index 0000000..522414d
--- /dev/null
+++ b/CHANGES.txt
@@ -0,0 +1,21 @@
+Changelog
+=========
+
+1.0.1 (2013-02-14)
+------------------
+
+- Nothing changed yet.
+
+
+1.0.0 (2013-02-13)
+------------------
+
+- Added Python 3.3 support.
+
+- Cleanup `setup.py`, add `tox.ini` and manifest.
+
+
+0.1.0 (2011-05-19)
+------------------
+
+- Initial release
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..61dad0f
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,9 @@
+include *.rst
+include *.txt
+include tox.ini
+include bootstrap.py
+include buildout.cfg
+
+recursive-include src *
+
+global-exclude *.pyc
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..18dc754
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,218 @@
+Metadata-Version: 1.1
+Name: zc.customdoctests
+Version: 1.0.1
+Summary: =====================================================
+Home-page: http://pypi.python.org/pypi/zc.customdoctests
+Author: Jim Fulton
+Author-email: jim at zope.com
+License: ZPL 2.1
+Description: =====================================================
+ zc.customdoctests -- Use doctest with other languages
+ =====================================================
+
+ doctest (and recently manuel) provide hooks for using custom doctest
+ parsers. `zc.customdoctests` helps to leverage this to support other
+ languages, such as JavaScript::
+
+ js> function double (x) {
+ ... return x*2;
+ ... }
+ js> double(2)
+ 4
+
+ And with `manuel <http://pypi.python.org/pypi/manuel>`_, it
+ facilitates doctests that mix multiple languages, such as Python,
+ JavaScript, and sh.
+
+ .. contents::
+
+
+ Detailed documentation
+ ======================
+
+ 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 ``'>>>'``.
+
+ This must be a regular expression that matches exactly 3 characters.
+
+ (Note that you can't override the second-line prompt.)
+
+ comment_prefix
+ The comment prefix regular expression, 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>`_. It provides some
+ examples of defining custom doctest parsers.
+
+
+ Javascript and Python-Spidermonkey support
+ ------------------------------------------
+
+ .. This file shows some examples of using spidermonkey APIs in doctests.
+
+ To wire this up, you'd use something like::
+
+ import doctest, zc.customdoctests.js
+
+ test_suite = doctest.DocTestSuite(
+ parser=zc.customdoctests.js.parser,
+ setUp=zc.customdoctests.js.spidermonkeySetUp)
+
+ Or, with manuel::
+
+ test_suite = manuel.testing.TestSuite(
+ manuel.doctest.Manuel(parser=zc.customdoctests.js.parser) +
+ manuel.doctest.Manuel(parser=zc.customdoctests.js.eq_parser) +
+ manuel.doctest.Manuel() +
+ manuel.capture.Manuel(),
+ 'spidermonkey.txt',
+ setUp=zc.customdoctests.js.spidermonkeySetUp)
+
+ Note that zc.customdoctests doesn't require spidermonkey, so you need
+ to install spidermonkey seperately if you want to use it.
+
+ An advantage of using manuel is that you can use multiple parsers in
+ the same document. In the example, above, 2 javascript example
+ syntaxes (described below) as well as the standard doctest syntax are
+ supported. This document is run with manuel to allow all 3 syntaxes.
+
+ For the rest of this document, we'll show examples of JavaScript
+ doctests as well as helper APIs used to support JavaScript and to
+ integrate JavaScript and Python.
+
+ Javascript doctests use a "js>" prompt (as used in rhino and the
+ spidermonkey interpreter)::
+
+ js> 2 +
+ ... 'Hi world' // doctest: +ELLIPSIS
+ u'2Hi...
+
+ Assignments return values. This can generate annoying output
+ in doctests::
+
+ js> ob = {a: 1, b: 2}
+ [object Object]
+
+ If you're using manuel, you can avoid this by using js!::
+
+ js! x = 3
+
+ which suppresses expression values.
+
+ load and print functions (similar to those found in rhino) are
+ provided. For example, given a javascript file, double.js::
+
+ function double (x) {
+ return x*2;
+ }
+
+ .. -> src
+
+ >>> with open('double.js', 'w') as f:
+ ... f.write(src)
+
+ We can load the file::
+
+ js> load('double.js')
+ js> double(10)
+ 20
+
+ We can print values::
+
+ js> print('Hi')
+ Hi
+
+ A python object provides access to the open function and the os
+ module::
+
+ js> python.os.path.exists('double.js')
+ True
+
+ js! f = python.open('double.js')
+ js> print(f.read())
+ function double (x) {
+ return x*2;
+ }
+ <BLANKLINE>
+
+ js> f.close()
+
+
+ If you're using manuel, you can intermix Python and and JavaScript
+ examples and there are a number of APIs to facilitate using Python and
+ JavaScript together.
+
+ There's an add_js_global function to copy data from Python::
+
+ >>> add_js_global('y', 1)
+
+ js> y
+ 1
+
+ There's also a js object that provides attribute access to js globals::
+
+ >>> js.x
+ 3
+
+ >>> js.z = 4
+
+ js> z
+ 4
+
+ You can also call this to run JS code without returning the resulting value::
+
+ >>> js('a = x + y')
+
+ js> a
+ 4
+
+
+ Changelog
+ =========
+
+ 1.0.1 (2013-02-14)
+ ------------------
+
+ - Nothing changed yet.
+
+
+ 1.0.0 (2013-02-13)
+ ------------------
+
+ - Added Python 3.3 support.
+
+ - Cleanup `setup.py`, add `tox.ini` and manifest.
+
+
+ 0.1.0 (2011-05-19)
+ ------------------
+
+ - Initial release
+
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Zope Public License
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Natural Language :: English
+Classifier: Operating System :: OS Independent
+Classifier: Topic :: Software Development
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..3617a70
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,19 @@
+=====================================================
+zc.customdoctests -- Use doctest with other languages
+=====================================================
+
+doctest (and recently manuel) provide hooks for using custom doctest
+parsers. `zc.customdoctests` helps to leverage this to support other
+languages, such as JavaScript::
+
+ js> function double (x) {
+ ... return x*2;
+ ... }
+ js> double(2)
+ 4
+
+And with `manuel <http://pypi.python.org/pypi/manuel>`_, it
+facilitates doctests that mix multiple languages, such as Python,
+JavaScript, and sh.
+
+.. contents::
diff --git a/buildout.cfg b/buildout.cfg
new file mode 100644
index 0000000..c196d46
--- /dev/null
+++ b/buildout.cfg
@@ -0,0 +1,17 @@
+[buildout]
+develop = .
+parts = test test3 py
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zc.customdoctests [test,js]
+
+[test3]
+# python-spidermonkey does not run on Python 3 yet.
+recipe = zc.recipe.testrunner
+eggs = zc.customdoctests [test]
+
+[py]
+recipe = zc.recipe.egg
+eggs = ${test:eggs}
+interpreter = py
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..861a9f5
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_build =
+tag_date = 0
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..ebca960
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,74 @@
+##############################################################################
+#
+# Copyright (c) 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.
+#
+##############################################################################
+import os
+from setuptools import setup, find_packages
+
+here = os.path.dirname(__file__)
+
+def read(filename):
+ with open(os.path.join(here, filename)) as f:
+ return f.read()
+
+
+install_requires = ['setuptools']
+
+extras_require = dict(
+ test=['zope.testing', 'manuel'],
+ js=['python-spidermonkey'],
+)
+
+setup(
+ name='zc.customdoctests',
+ version='1.0.1',
+ url='http://pypi.python.org/pypi/zc.customdoctests',
+ license='ZPL 2.1',
+ description=read('README.txt').splitlines(False)[0],
+ author='Jim Fulton',
+ author_email='jim at zope.com',
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.6',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.3',
+ 'Programming Language :: Python :: Implementation :: CPython',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Software Development',
+ ],
+ long_description=''.join([
+ read('README.txt'),
+ '\n\n'
+ 'Detailed documentation\n'
+ '======================\n\n',
+ read('src/zc/customdoctests/README.txt'),
+ '\n\n',
+ read('src/zc/customdoctests/spidermonkey.txt'),
+ '\n\n',
+ read('CHANGES.txt'),
+ ]),
+ packages=find_packages('src'),
+ package_dir={'': 'src'},
+ namespace_packages=['zc',],
+ install_requires=install_requires,
+ package_data={'zc.customdoctests': ['*.txt']},
+ extras_require=extras_require,
+ tests_require=extras_require['test'],
+ test_suite='zc.customdoctests.tests.test_suite',
+ zip_safe=False,
+)
diff --git a/src/zc.customdoctests.egg-info/PKG-INFO b/src/zc.customdoctests.egg-info/PKG-INFO
new file mode 100644
index 0000000..18dc754
--- /dev/null
+++ b/src/zc.customdoctests.egg-info/PKG-INFO
@@ -0,0 +1,218 @@
+Metadata-Version: 1.1
+Name: zc.customdoctests
+Version: 1.0.1
+Summary: =====================================================
+Home-page: http://pypi.python.org/pypi/zc.customdoctests
+Author: Jim Fulton
+Author-email: jim at zope.com
+License: ZPL 2.1
+Description: =====================================================
+ zc.customdoctests -- Use doctest with other languages
+ =====================================================
+
+ doctest (and recently manuel) provide hooks for using custom doctest
+ parsers. `zc.customdoctests` helps to leverage this to support other
+ languages, such as JavaScript::
+
+ js> function double (x) {
+ ... return x*2;
+ ... }
+ js> double(2)
+ 4
+
+ And with `manuel <http://pypi.python.org/pypi/manuel>`_, it
+ facilitates doctests that mix multiple languages, such as Python,
+ JavaScript, and sh.
+
+ .. contents::
+
+
+ Detailed documentation
+ ======================
+
+ 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 ``'>>>'``.
+
+ This must be a regular expression that matches exactly 3 characters.
+
+ (Note that you can't override the second-line prompt.)
+
+ comment_prefix
+ The comment prefix regular expression, 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>`_. It provides some
+ examples of defining custom doctest parsers.
+
+
+ Javascript and Python-Spidermonkey support
+ ------------------------------------------
+
+ .. This file shows some examples of using spidermonkey APIs in doctests.
+
+ To wire this up, you'd use something like::
+
+ import doctest, zc.customdoctests.js
+
+ test_suite = doctest.DocTestSuite(
+ parser=zc.customdoctests.js.parser,
+ setUp=zc.customdoctests.js.spidermonkeySetUp)
+
+ Or, with manuel::
+
+ test_suite = manuel.testing.TestSuite(
+ manuel.doctest.Manuel(parser=zc.customdoctests.js.parser) +
+ manuel.doctest.Manuel(parser=zc.customdoctests.js.eq_parser) +
+ manuel.doctest.Manuel() +
+ manuel.capture.Manuel(),
+ 'spidermonkey.txt',
+ setUp=zc.customdoctests.js.spidermonkeySetUp)
+
+ Note that zc.customdoctests doesn't require spidermonkey, so you need
+ to install spidermonkey seperately if you want to use it.
+
+ An advantage of using manuel is that you can use multiple parsers in
+ the same document. In the example, above, 2 javascript example
+ syntaxes (described below) as well as the standard doctest syntax are
+ supported. This document is run with manuel to allow all 3 syntaxes.
+
+ For the rest of this document, we'll show examples of JavaScript
+ doctests as well as helper APIs used to support JavaScript and to
+ integrate JavaScript and Python.
+
+ Javascript doctests use a "js>" prompt (as used in rhino and the
+ spidermonkey interpreter)::
+
+ js> 2 +
+ ... 'Hi world' // doctest: +ELLIPSIS
+ u'2Hi...
+
+ Assignments return values. This can generate annoying output
+ in doctests::
+
+ js> ob = {a: 1, b: 2}
+ [object Object]
+
+ If you're using manuel, you can avoid this by using js!::
+
+ js! x = 3
+
+ which suppresses expression values.
+
+ load and print functions (similar to those found in rhino) are
+ provided. For example, given a javascript file, double.js::
+
+ function double (x) {
+ return x*2;
+ }
+
+ .. -> src
+
+ >>> with open('double.js', 'w') as f:
+ ... f.write(src)
+
+ We can load the file::
+
+ js> load('double.js')
+ js> double(10)
+ 20
+
+ We can print values::
+
+ js> print('Hi')
+ Hi
+
+ A python object provides access to the open function and the os
+ module::
+
+ js> python.os.path.exists('double.js')
+ True
+
+ js! f = python.open('double.js')
+ js> print(f.read())
+ function double (x) {
+ return x*2;
+ }
+ <BLANKLINE>
+
+ js> f.close()
+
+
+ If you're using manuel, you can intermix Python and and JavaScript
+ examples and there are a number of APIs to facilitate using Python and
+ JavaScript together.
+
+ There's an add_js_global function to copy data from Python::
+
+ >>> add_js_global('y', 1)
+
+ js> y
+ 1
+
+ There's also a js object that provides attribute access to js globals::
+
+ >>> js.x
+ 3
+
+ >>> js.z = 4
+
+ js> z
+ 4
+
+ You can also call this to run JS code without returning the resulting value::
+
+ >>> js('a = x + y')
+
+ js> a
+ 4
+
+
+ Changelog
+ =========
+
+ 1.0.1 (2013-02-14)
+ ------------------
+
+ - Nothing changed yet.
+
+
+ 1.0.0 (2013-02-13)
+ ------------------
+
+ - Added Python 3.3 support.
+
+ - Cleanup `setup.py`, add `tox.ini` and manifest.
+
+
+ 0.1.0 (2011-05-19)
+ ------------------
+
+ - Initial release
+
+Platform: UNKNOWN
+Classifier: Development Status :: 4 - Beta
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Zope Public License
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.6
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Natural Language :: English
+Classifier: Operating System :: OS Independent
+Classifier: Topic :: Software Development
diff --git a/src/zc.customdoctests.egg-info/SOURCES.txt b/src/zc.customdoctests.egg-info/SOURCES.txt
new file mode 100644
index 0000000..3c338f7
--- /dev/null
+++ b/src/zc.customdoctests.egg-info/SOURCES.txt
@@ -0,0 +1,19 @@
+CHANGES.txt
+MANIFEST.in
+README.txt
+buildout.cfg
+setup.py
+tox.ini
+src/zc/__init__.py
+src/zc.customdoctests.egg-info/PKG-INFO
+src/zc.customdoctests.egg-info/SOURCES.txt
+src/zc.customdoctests.egg-info/dependency_links.txt
+src/zc.customdoctests.egg-info/namespace_packages.txt
+src/zc.customdoctests.egg-info/not-zip-safe
+src/zc.customdoctests.egg-info/requires.txt
+src/zc.customdoctests.egg-info/top_level.txt
+src/zc/customdoctests/README.txt
+src/zc/customdoctests/__init__.py
+src/zc/customdoctests/js.py
+src/zc/customdoctests/spidermonkey.txt
+src/zc/customdoctests/tests.py
\ No newline at end of file
diff --git a/src/zc.customdoctests.egg-info/dependency_links.txt b/src/zc.customdoctests.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/zc.customdoctests.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/src/zc.customdoctests.egg-info/namespace_packages.txt b/src/zc.customdoctests.egg-info/namespace_packages.txt
new file mode 100644
index 0000000..7647cfa
--- /dev/null
+++ b/src/zc.customdoctests.egg-info/namespace_packages.txt
@@ -0,0 +1 @@
+zc
diff --git a/src/zc.customdoctests.egg-info/not-zip-safe b/src/zc.customdoctests.egg-info/not-zip-safe
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/src/zc.customdoctests.egg-info/not-zip-safe
@@ -0,0 +1 @@
+
diff --git a/src/zc.customdoctests.egg-info/requires.txt b/src/zc.customdoctests.egg-info/requires.txt
new file mode 100644
index 0000000..6d17395
--- /dev/null
+++ b/src/zc.customdoctests.egg-info/requires.txt
@@ -0,0 +1,8 @@
+setuptools
+
+[test]
+zope.testing
+manuel
+
+[js]
+python-spidermonkey
\ No newline at end of file
diff --git a/src/zc.customdoctests.egg-info/top_level.txt b/src/zc.customdoctests.egg-info/top_level.txt
new file mode 100644
index 0000000..7647cfa
--- /dev/null
+++ b/src/zc.customdoctests.egg-info/top_level.txt
@@ -0,0 +1 @@
+zc
diff --git a/src/zc/__init__.py b/src/zc/__init__.py
new file mode 100644
index 0000000..d407605
--- /dev/null
+++ b/src/zc/__init__.py
@@ -0,0 +1,5 @@
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
diff --git a/src/zc/customdoctests/README.txt b/src/zc/customdoctests/README.txt
new file mode 100644
index 0000000..f1b8724
--- /dev/null
+++ b/src/zc/customdoctests/README.txt
@@ -0,0 +1,26 @@
+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 ``'>>>'``.
+
+ This must be a regular expression that matches exactly 3 characters.
+
+ (Note that you can't override the second-line prompt.)
+
+comment_prefix
+ The comment prefix regular expression, 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>`_. It provides some
+examples of defining custom doctest parsers.
diff --git a/src/zc/customdoctests/__init__.py b/src/zc/customdoctests/__init__.py
new file mode 100644
index 0000000..c83a1ee
--- /dev/null
+++ b/src/zc/customdoctests/__init__.py
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2011 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.
+#
+##############################################################################
+import doctest
+import re
+import sys
+
+class DocTestParser(doctest.DocTestParser):
+ "Doctest parser that creates calls into JavaScript."
+
+ def __init__(self, *args, **kw):
+ ps1 = kw.pop('ps1', '>>>')
+ comment_prefix = kw.pop('comment_prefix', '#')
+ self.transform = kw.pop('transform', lambda s: s)
+ try:
+ getattr(
+ doctest.DocTestParser, '__init__', lambda : None)(*args, **kw)
+ except TypeError:
+ # Python 3 support.
+ super(doctest.DocTestParser, self).__init__(*args, **kw)
+ self._EXAMPLE_RE = re.compile(
+ r'''
+ # Source consists of a PS1 line followed by zero or more PS2 lines.
+ (?P<source>
+ (?:^(?P<indent> [ ]*) %(ps1)s .*) # PS1 line
+ (?:\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), re.MULTILINE | re.VERBOSE)
+
+ self._OPTION_DIRECTIVE_RE = re.compile(
+ comment_prefix +r'\s*doctest:\s*([^\n\'"]*)$', re.MULTILINE)
+
+
+
+ def parse(self, string, name='<string>'):
+ r =doctest.DocTestParser.parse(self, string, name)
+ for s in r:
+ if isinstance(s, doctest.Example):
+ s.source = self.transform(s.source)
+ return r
diff --git a/src/zc/customdoctests/js.py b/src/zc/customdoctests/js.py
new file mode 100644
index 0000000..1359892
--- /dev/null
+++ b/src/zc/customdoctests/js.py
@@ -0,0 +1,124 @@
+##############################################################################
+#
+# Copyright (c) 2011 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.
+#
+##############################################################################
+import doctest
+import os
+import re
+import sys
+import zc.customdoctests
+
+run_time = None
+
+def transform(s, f='JS'):
+ if s[-1] == '\n':
+ return (r'%s(r"""%s"""+"\n")' % (f, s)) + '\n'
+ else:
+ return r'%s(r"""%s""")' % (f, s)
+
+parser = zc.customdoctests.DocTestParser(
+ ps1='js>', comment_prefix='//', transform=transform)
+
+# parser_ is like parser, except adds: var _ = to
+# the fron of the executed code.
+eq_parser = zc.customdoctests.DocTestParser(
+ ps1='js!', comment_prefix='//',
+ transform=lambda s: transform(s, 'JS_'))
+
+
+# spidermonkey hacks below:
+
+class JavaScriptError(Exception):
+
+ def __str__(self):
+ try:
+ return "%s\nJS Traceback:%s" % (
+ self.args[0].message,
+ '\n'.join(reversed(self.args[0].stack.split('\n')))
+ )
+ except:
+ return str(self.args[0])
+
+
+class ContextConvenience(object):
+
+ def __init__(self, context):
+ object.__setattr__(self, '_context', context)
+
+ def __getattr__(self, name):
+ return self._context.execute(name)
+
+ def __setattr__(self, name, v):
+ self._context.add_global(name, v)
+
+ def __call__(self, src):
+ self._context.execute(load_template % src)
+ if self.spidermonkey_error is not None:
+ raise JavaScriptError(self.spidermonkey_error)
+
+def spidermonkeySetUp(test_or_self=None):
+ global run_time
+ if run_time is None:
+ import spidermonkey
+ run_time = spidermonkey.Runtime()
+ cx = run_time.new_context()
+ JS = cx.execute
+
+ js = ContextConvenience(cx)
+
+ if test_or_self is not None:
+ globs = getattr(test_or_self, 'globs', test_or_self.__dict__)
+ globs['JS'] = JS
+ globs['JS_'] = js
+ globs['js'] = js
+ globs['add_js_global'] = cx.add_global
+
+ def load_(name):
+ if name.startswith('file://'):
+ name = name[7:]
+ return JS(load_template % open(name).read(), name)
+
+ # Rhino & spidermonkey/js compatability functions
+ cx.add_global('python', dict(
+ os = os,
+ open = open,
+ ))
+ cx.add_global('load_', load_)
+ JS(load_js)
+ cx.add_global('print',
+ lambda *s: sys.stdout.write(('%s\n' % ' '.join(map(unicode, s))).encode('utf-8'))
+ )
+ cx.add_global('printe',
+ lambda *s: sys.stderr.write('%s\n' % ' '.join(map(unicode, s)))
+ )
+ return js
+
+
+load_template = ("spidermonkey_error = undefined; "
+ "try { %s } catch (e) {spidermonkey_error = e;}")
+
+load_js = """
+function load(p) {
+ if (p.slice(0, 7) == 'file://') {
+ p = p.slice(7);
+ }
+ try { console.debug('loading', p); } catch (e) {}
+ if (! python.os.path.exists(p)) {
+ throw "Doesn't exist: "+p;
+ }
+ var result = load_(p);
+ if (spidermonkey_error) {
+ throw spidermonkey_error;
+ }
+ return result;
+}
+"""
diff --git a/src/zc/customdoctests/spidermonkey.txt b/src/zc/customdoctests/spidermonkey.txt
new file mode 100644
index 0000000..2882cb1
--- /dev/null
+++ b/src/zc/customdoctests/spidermonkey.txt
@@ -0,0 +1,120 @@
+Javascript and Python-Spidermonkey support
+------------------------------------------
+
+.. This file shows some examples of using spidermonkey APIs in doctests.
+
+To wire this up, you'd use something like::
+
+ import doctest, zc.customdoctests.js
+
+ test_suite = doctest.DocTestSuite(
+ parser=zc.customdoctests.js.parser,
+ setUp=zc.customdoctests.js.spidermonkeySetUp)
+
+Or, with manuel::
+
+ test_suite = manuel.testing.TestSuite(
+ manuel.doctest.Manuel(parser=zc.customdoctests.js.parser) +
+ manuel.doctest.Manuel(parser=zc.customdoctests.js.eq_parser) +
+ manuel.doctest.Manuel() +
+ manuel.capture.Manuel(),
+ 'spidermonkey.txt',
+ setUp=zc.customdoctests.js.spidermonkeySetUp)
+
+Note that zc.customdoctests doesn't require spidermonkey, so you need
+to install spidermonkey seperately if you want to use it.
+
+An advantage of using manuel is that you can use multiple parsers in
+the same document. In the example, above, 2 javascript example
+syntaxes (described below) as well as the standard doctest syntax are
+supported. This document is run with manuel to allow all 3 syntaxes.
+
+For the rest of this document, we'll show examples of JavaScript
+doctests as well as helper APIs used to support JavaScript and to
... 196 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-zc.customdoctests.git
More information about the Python-modules-commits
mailing list