[Checkins] SVN: grok/trunk/src/grok/ftests/ Actually demonstrate the bug that Martian 0.9.2 fixes. The previous

Martijn Faassen faassen at infrae.com
Tue Nov 20 07:34:27 EST 2007


Log message for revision 81945:
  Actually demonstrate the bug that Martian 0.9.2 fixes. The previous 
  test also worked with Martian 0.9.1, but this one doesn't as it's a pure
  doctest, which triggered the bug.
  

Changed:
  A   grok/trunk/src/grok/ftests/grok_component.txt
  U   grok/trunk/src/grok/ftests/test_grok_functional.py
  D   grok/trunk/src/grok/ftests/testing/

-=-
Added: grok/trunk/src/grok/ftests/grok_component.txt
===================================================================
--- grok/trunk/src/grok/ftests/grok_component.txt	                        (rev 0)
+++ grok/trunk/src/grok/ftests/grok_component.txt	2007-11-20 12:34:26 UTC (rev 81945)
@@ -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/trunk/src/grok/ftests/test_grok_functional.py
===================================================================
--- grok/trunk/src/grok/ftests/test_grok_functional.py	2007-11-20 12:23:29 UTC (rev 81944)
+++ grok/trunk/src/grok/ftests/test_grok_functional.py	2007-11-20 12:34:26 UTC (rev 81945)
@@ -70,9 +70,15 @@
 def test_suite():
     suite = unittest.TestSuite()
     for name in ['view', 'staticdir', 'xmlrpc', 'traversal', 'form', 'url',
-                 'security', 'utility', 'catalog', 'admin', 'site', 'rest',
-                 'testing']:
+                 '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__':



More information about the Checkins mailing list