[Checkins] SVN: Sandbox/J1m/customdoctests/ Added spidermonkey-support test and readied for release.

Jim Fulton jim at zope.com
Thu May 19 12:22:46 EDT 2011


Log message for revision 121755:
  Added spidermonkey-support test and readied for release.
  

Changed:
  U   Sandbox/J1m/customdoctests/README.txt
  U   Sandbox/J1m/customdoctests/buildout.cfg
  U   Sandbox/J1m/customdoctests/setup.py
  U   Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt
  U   Sandbox/J1m/customdoctests/src/zc/customdoctests/js.py
  A   Sandbox/J1m/customdoctests/src/zc/customdoctests/spidermonkey.txt
  U   Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py

-=-
Modified: Sandbox/J1m/customdoctests/README.txt
===================================================================
--- Sandbox/J1m/customdoctests/README.txt	2011-05-19 14:57:18 UTC (rev 121754)
+++ Sandbox/J1m/customdoctests/README.txt	2011-05-19 16:22:45 UTC (rev 121755)
@@ -1,20 +1,26 @@
-zc.customdoctests -- customized doctest implementations
-*******************************************************
+zc.customdoctests -- Use doctest with other languages
+*****************************************************
 
-doctest (and recently manuel) provide hooks for using custo doctest
-parsers. This enables writing JavaScript doctests, as in::
+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> function double (x) {
+    ...     return x*2;
+    ... }
     js> double(2)
     4
 
-And with manuel, it facilitates doctests that mix multiple languages,
-such as Python, JavaScript, and sh.
+And with `manuel <http://pypi.python.org/pypi/manuel>`_, it
+facilitates doctests that mix multiple languages, such as Python,
+JavaScript, and sh.
 
+.. contents::
+
 Changes
 *******
 
-0.1.0 (yyyy-mm-dd)
+0.1.0 (2011-05-19)
 ==================
 
 Initial release

Modified: Sandbox/J1m/customdoctests/buildout.cfg
===================================================================
--- Sandbox/J1m/customdoctests/buildout.cfg	2011-05-19 14:57:18 UTC (rev 121754)
+++ Sandbox/J1m/customdoctests/buildout.cfg	2011-05-19 16:22:45 UTC (rev 121755)
@@ -4,7 +4,7 @@
 
 [test]
 recipe = zc.recipe.testrunner
-eggs = zc.customdoctests
+eggs = zc.customdoctests [test]
 
 [py]
 recipe = zc.recipe.egg

Modified: Sandbox/J1m/customdoctests/setup.py
===================================================================
--- Sandbox/J1m/customdoctests/setup.py	2011-05-19 14:57:18 UTC (rev 121754)
+++ Sandbox/J1m/customdoctests/setup.py	2011-05-19 16:22:45 UTC (rev 121755)
@@ -14,12 +14,10 @@
 name, version = 'zc.customdoctests', '0'
 
 install_requires = ['setuptools']
-extras_require = dict(test=['zope.testing'])
+extras_require = dict(test=['zope.testing', 'python-spidermonkey', 'manuel'])
 
-entry_points = """
-"""
-
 from setuptools import setup
+import os
 
 setup(
     author = 'Jim Fulton',
@@ -27,14 +25,23 @@
     license = 'ZPL 2.1',
 
     name = name, version = version,
-    long_description=open('README.txt').read(),
+    long_description=(
+        open('README.txt').read() + '\n\n' +
+        'Detailed dcoumentation\n' +
+        '**********************\n\n' +
+        open(os.path.join(os.path.dirname(__file__),
+                          'src', 'zc', 'customdoctests', 'README.txt')
+             ).read() + '\n\n' +
+        open(os.path.join(os.path.dirname(__file__),
+                          'src', 'zc', 'customdoctests', 'spidermonkey.txt')
+             ).read()
+        ),
     description = open('README.txt').read().strip().split('\n')[0],
     packages = [name.split('.')[0], name],
     namespace_packages = [name.split('.')[0]],
     package_dir = {'': 'src'},
     install_requires = install_requires,
     zip_safe = False,
-    entry_points=entry_points,
     package_data = {name: ['*.txt', '*.test', '*.html']},
     extras_require = extras_require,
     tests_require = extras_require['test'],

Modified: Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt
===================================================================
--- Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt	2011-05-19 14:57:18 UTC (rev 121754)
+++ Sandbox/J1m/customdoctests/src/zc/customdoctests/README.txt	2011-05-19 16:22:45 UTC (rev 121755)
@@ -9,10 +9,12 @@
 ps1
    The first-line prompt, which defaultd to ``'>>>'``.
 
+   This must be a regular expression that matches exact;y 3 characters.
+
    (Note that you can't override the second-line prompt.)
 
 comment_prefix
-   The comment prefix string, which defaults to '#'.
+   The comment prefix regular expression, which defaults to '#'.
 
 transform
    A function used to transform example source, which defaults to a
@@ -20,6 +22,5 @@
 
 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.
+<http://pypi.python.org/pypi/python-spidermonkey>`_. It provides some
+examples of defining custom doctest parsers.

Modified: Sandbox/J1m/customdoctests/src/zc/customdoctests/js.py
===================================================================
--- Sandbox/J1m/customdoctests/src/zc/customdoctests/js.py	2011-05-19 14:57:18 UTC (rev 121754)
+++ Sandbox/J1m/customdoctests/src/zc/customdoctests/js.py	2011-05-19 16:22:45 UTC (rev 121755)
@@ -80,6 +80,7 @@
         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):

Added: Sandbox/J1m/customdoctests/src/zc/customdoctests/spidermonkey.txt
===================================================================
--- Sandbox/J1m/customdoctests/src/zc/customdoctests/spidermonkey.txt	                        (rev 0)
+++ Sandbox/J1m/customdoctests/src/zc/customdoctests/spidermonkey.txt	2011-05-19 16:22:45 UTC (rev 121755)
@@ -0,0 +1,117 @@
+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(),
+            )
+
+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


Property changes on: Sandbox/J1m/customdoctests/src/zc/customdoctests/spidermonkey.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py
===================================================================
--- Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py	2011-05-19 14:57:18 UTC (rev 121754)
+++ Sandbox/J1m/customdoctests/src/zc/customdoctests/tests.py	2011-05-19 16:22:45 UTC (rev 121755)
@@ -18,9 +18,8 @@
 import unittest
 import doctest
 
-import zc.customdoctests
+import zc.customdoctests.js
 
-
 def custom_doctest_parser():
     r"""
     >>> [e] = zc.customdoctests.DocTestParser().get_examples('''
@@ -49,9 +48,24 @@
 
     """
 
-
-
 def test_suite():
-    return doctest.DocTestSuite()
+    suite = unittest.TestSuite([doctest.DocTestSuite()])
+    try:
+        import spidermonkey
+    except ImportError:
+        pass
+    else:
+        import manuel.capture
+        import manuel.doctest
+        import manuel.testing
+        suite.addTest(
+            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)
+            )
+    return suite
 
-



More information about the checkins mailing list