[Checkins] SVN: Sandbox/J1m/dozodb/ Custo manuel that allows passing custom doctest parsers.

Jim Fulton jim at zope.com
Mon Jan 10 18:25:31 EST 2011


Log message for revision 119483:
  Custo manuel that allows passing custom doctest parsers.
  

Changed:
  _U  Sandbox/J1m/dozodb/
  U   Sandbox/J1m/dozodb/buildout.cfg
  U   Sandbox/J1m/dozodb/src/zc/dozodb/dozodb.js.test
  U   Sandbox/J1m/dozodb/src/zc/dozodb/tests.py

-=-

Property changes on: Sandbox/J1m/dozodb
___________________________________________________________________
Added: svn:externals
   + manuel svn+ssh://svn.zope.org/repos/main/manuel/branches/jim-custom-doctest-parsers



Modified: Sandbox/J1m/dozodb/buildout.cfg
===================================================================
--- Sandbox/J1m/dozodb/buildout.cfg	2011-01-10 23:24:05 UTC (rev 119482)
+++ Sandbox/J1m/dozodb/buildout.cfg	2011-01-10 23:25:31 UTC (rev 119483)
@@ -1,5 +1,5 @@
 [buildout]
-develop = .
+develop = . manuel
 parts = py dojo-spidermonkey test
 find-links = http://www.riversnake.com/dists
 
@@ -17,7 +17,7 @@
 eggs =
   ZODB3
   bobo
-  zc.dozodb
+  zc.dozodb [test]
   python-spidermonkey
 
 interpreter = py

Modified: Sandbox/J1m/dozodb/src/zc/dozodb/dozodb.js.test
===================================================================
--- Sandbox/J1m/dozodb/src/zc/dozodb/dozodb.js.test	2011-01-10 23:24:05 UTC (rev 119482)
+++ Sandbox/J1m/dozodb/src/zc/dozodb/dozodb.js.test	2011-01-10 23:25:31 UTC (rev 119483)
@@ -5,13 +5,17 @@
 
 To use, you need to require:
 
-    >>> dojo.require('zc.dozodb');
+    js> dojo.require('zc.dozodb');
     [object Object]
 
 Create a store:
 
-    >>> var store = zc.dozodb.Store({url: '/store'});
+    js> var store = zc.dozodb.Store({url: '/store'});
 
+    py> import sys
+    py> sys.platform
+    'linux2'
+
 where the url option names a dozodb web resource.  dozodb web
 resources support loading and saving data via GET and POST ajax
 requests. For these tests, we've stubbed out dojo's xhr interface to
@@ -26,7 +30,7 @@
 some callbacks.  It's up to the server to interpret the query to
 decide which data to return.
 
-    >>> var request = store.fetch({
+    js> var request = store.fetch({
     ...     query: {a: 1, b: 2},
     ...     onBegin: function (n, r) {
     ...         assert(r === request);
@@ -61,7 +65,7 @@
 
 We'll now emulate the server by calling the xhr load callback.
 
-    >>> last_xhr.load({
+    js> last_xhr.load({
     ...     items: [{_p_oid: '1', _p_serial: '1',
     ...              name: 'root', children: []}],
     ...     size: 1
@@ -82,7 +86,7 @@
 
 Now we'll do another fetch, but this time, pass an onItem handler:
 
-    >>> var request = store.fetch({
+    js> var request = store.fetch({
     ...     query: {a: 1, b: 2},
     ...     onBegin: function (n, r) {
     ...         assert(r === request);
@@ -105,7 +109,7 @@
         preventCache: true,
         url: "/store" }
 
-    >>> last_xhr.load({
+    js> last_xhr.load({
     ...     items: [
     ...         {_p_oid: '2', _p_serial: '1', name: 'foo', children: []},
     ...         {_p_oid: '3', _p_serial: '1', name: 'bar',

Modified: Sandbox/J1m/dozodb/src/zc/dozodb/tests.py
===================================================================
--- Sandbox/J1m/dozodb/src/zc/dozodb/tests.py	2011-01-10 23:24:05 UTC (rev 119482)
+++ Sandbox/J1m/dozodb/src/zc/dozodb/tests.py	2011-01-10 23:25:31 UTC (rev 119483)
@@ -14,22 +14,55 @@
 
 import doctest
 import os
+import re
 import spidermonkey
 import sys
 import unittest
+import manuel.capture
+import manuel.doctest
+import manuel.testing
 
 baseUrl = None # Set by test runner.
 
 run_time = spidermonkey.Runtime()
 
-class DocTestParser(doctest.DocTestParser):
-    ""
+class DocTestPyParser(doctest.DocTestParser):
 
+    _EXAMPLE_RE = re.compile(r'''
+        # Source consists of a PS1 line followed by zero or more PS2 lines.
+        (?P<source>
+            (?:^(?P<indent> [ ]*) py>    .*)    # 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
+                     (?![ ]*py>)  # Not a line starting with PS1
+                     .*$\n?       # But any other line
+                  )*)
+        ''', re.MULTILINE | re.VERBOSE)
+
+
+class DocTestJSParser(doctest.DocTestParser):
+    "Doctest parser that creates calls into JavaScript."
+
+    _EXAMPLE_RE = re.compile(r'''
+        # Source consists of a PS1 line followed by zero or more PS2 lines.
+        (?P<source>
+            (?:^(?P<indent> [ ]*) js>    .*)    # 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
+                     (?![ ]*js>)  # Not a line starting with PS1
+                     .*$\n?       # But any other line
+                  )*)
+        ''', re.MULTILINE | re.VERBOSE)
+
     def parse(self, string, name='<string>'):
         r =doctest.DocTestParser.parse(self, string, name)
         for s in r:
             if isinstance(s, doctest.Example):
-                s.source = "JS(%r)" % s.source
+                s.source = "JS(%r)\n" % s.source
         return r
 
 def setUp(test):
@@ -57,9 +90,15 @@
 
 def test_suite():
     return unittest.TestSuite((
-        doctest.DocFileSuite(
+        manuel.testing.TestSuite(
+            manuel.doctest.Manuel(parser=DocTestJSParser()) +
+            manuel.doctest.Manuel(parser=DocTestPyParser()) +
+            manuel.capture.Manuel(),
             'dozodb.js.test',
-            parser=DocTestParser(),
-            setUp=setUp,
-            ),
+            setUp=setUp),
+        # doctest.DocFileSuite(
+        #     'dozodb.js.test',
+        #     parser=DocTestParser(),
+        #     setUp=setUp,
+        #     ),
         ))



More information about the checkins mailing list