[Checkins] SVN: grok/branches/0.11/ Backport grok_component() in doctest fix to Grok 0.11 branch.

Martijn Faassen faassen at infrae.com
Tue Nov 20 07:40:48 EST 2007


Log message for revision 81947:
  Backport grok_component() in doctest fix to Grok 0.11 branch.
  

Changed:
  U   grok/branches/0.11/CHANGES.txt
  A   grok/branches/0.11/src/grok/ftests/grok_component.txt
  U   grok/branches/0.11/src/grok/ftests/test_grok_functional.py
  U   grok/branches/0.11/versions.cfg

-=-
Modified: grok/branches/0.11/CHANGES.txt
===================================================================
--- grok/branches/0.11/CHANGES.txt	2007-11-20 12:35:44 UTC (rev 81946)
+++ grok/branches/0.11/CHANGES.txt	2007-11-20 12:40:47 UTC (rev 81947)
@@ -17,6 +17,10 @@
   ``grok.grok_component`` to their correct equivalents in
   ``grok.testing``.
 
+* ``grok.testing.grok_component()`` could not be used in a pure
+  doctest. This needed a bugfix in Martian (since 0.9.2). Add a test
+  that demonstrates this problem.
+
 0.11 (2007-11-08)
 =================
 

Added: grok/branches/0.11/src/grok/ftests/grok_component.txt
===================================================================
--- grok/branches/0.11/src/grok/ftests/grok_component.txt	                        (rev 0)
+++ grok/branches/0.11/src/grok/ftests/grok_component.txt	2007-11-20 12:40:47 UTC (rev 81947)
@@ -0,0 +1,41 @@
+Test grok_component() in an ordinary doctest.
+
+We already have tests for grok_component(), but these were placed
+inside a module. We will now test grok_component() in a pure doctest
+context. This used to demonstrate an error in martian when dealing
+with the __builtin__ module (fixed in martian 0.9.2).
+
+grok.testing.grok_component() can be used to grok individual
+components within a doctest, such as adapters. It sets up just enough
+context for some grokking to work, though more complicated grokkers
+which need module context (such as view grokkers) might not work.
+
+This defines the object we want to provide an adapter for::
+
+  >>> class Bar(object):
+  ...    pass
+
+This is the interface that we want to adapt to::
+
+  >>> from zope.interface import Interface
+  >>> class IFoo(Interface):
+  ...    pass
+
+This is the adapter itself::
+
+  >>> import grok
+  >>> class MyAdapter(grok.Adapter):
+  ...    grok.provides(IFoo)
+  ...    grok.context(Bar)
+
+Now we will register the adapter using grok_component()::
+
+  >>> from grok.testing import grok_component
+  >>> grok_component('MyAdapter', MyAdapter)
+  True
+  
+The adapter should now be available::
+
+  >>> adapted = IFoo(Bar())
+  >>> isinstance(adapted, MyAdapter)
+  True

Modified: grok/branches/0.11/src/grok/ftests/test_grok_functional.py
===================================================================
--- grok/branches/0.11/src/grok/ftests/test_grok_functional.py	2007-11-20 12:35:44 UTC (rev 81946)
+++ grok/branches/0.11/src/grok/ftests/test_grok_functional.py	2007-11-20 12:40:47 UTC (rev 81947)
@@ -72,6 +72,13 @@
     for name in ['view', 'staticdir', 'xmlrpc', 'traversal', 'form', 'url',
                  'security', 'utility', 'catalog', 'admin', 'site', 'rest']:
         suite.addTest(suiteFromPackage(name))
+
+    # this test cannot follow the normal testing pattern, as the
+    # bug it tests for is only exposed in the context of a doctest
+    grok_component = doctest.DocFileSuite('grok_component.txt')
+    grok_component.layer = GrokFunctionalLayer
+    suite.addTest(grok_component)
+    
     return suite
 
 if __name__ == '__main__':

Modified: grok/branches/0.11/versions.cfg
===================================================================
--- grok/branches/0.11/versions.cfg	2007-11-20 12:35:44 UTC (rev 81946)
+++ grok/branches/0.11/versions.cfg	2007-11-20 12:40:47 UTC (rev 81947)
@@ -1,7 +1,7 @@
 [versions]
 ClientForm = 0.2.7
 docutils = 0.4
-martian = 0.9.1
+martian = 0.9.2
 mechanize = 0.1.7b
 Pygments = 0.8.1
 pytz = 2007g



More information about the Checkins mailing list