[Checkins] SVN: Sandbox/darrylcousins/mars.adapter/ Took a look, got tests to pass again

Darryl Cousins darryl at darrylcousins.net.nz
Sun Jan 27 23:48:42 EST 2008


Log message for revision 83273:
  Took a look, got tests to pass again

Changed:
  U   Sandbox/darrylcousins/mars.adapter/buildout.cfg
  U   Sandbox/darrylcousins/mars.adapter/src/mars/adapter/adapter.txt
  U   Sandbox/darrylcousins/mars.adapter/src/mars/adapter/meta.py
  U   Sandbox/darrylcousins/mars.adapter/src/mars/adapter/tests.py

-=-
Modified: Sandbox/darrylcousins/mars.adapter/buildout.cfg
===================================================================
--- Sandbox/darrylcousins/mars.adapter/buildout.cfg	2008-01-28 01:41:02 UTC (rev 83272)
+++ Sandbox/darrylcousins/mars.adapter/buildout.cfg	2008-01-28 04:48:41 UTC (rev 83273)
@@ -1,20 +1,8 @@
 [buildout]
 develop = .
 parts = test
-eggs-directory = /opt/buildout/mars/eggs
-develop-eggs-directory = /opt/buildout/mars/develop-eggs
-extends = http://grok.zope.org/releaseinfo/grok-0.10.2.cfg
-versions = versions
-executable = /opt/sandbox/mars/bin/python2.4
+extends = http://grok.zope.org/releaseinfo/grok-0.11.1.cfg
 
-[versions]
-zope.securitypolicy = 3.4.0
-zope.app.securitypolicy = 3.4.3
-
 [test]
 recipe = zc.recipe.testrunner
 eggs = mars.adapter [test]
-
-[zope3]
-location = .
-

Modified: Sandbox/darrylcousins/mars.adapter/src/mars/adapter/adapter.txt
===================================================================
--- Sandbox/darrylcousins/mars.adapter/src/mars/adapter/adapter.txt	2008-01-28 01:41:02 UTC (rev 83272)
+++ Sandbox/darrylcousins/mars.adapter/src/mars/adapter/adapter.txt	2008-01-28 04:48:41 UTC (rev 83273)
@@ -65,8 +65,9 @@
 module is ``grokked`` on start up.
 
   >>> from mars.adapter.meta import AdapterFactoryGrokker
-  >>> AdapterFactoryGrokker().grok('unnamed', UnNamedValueAdapter, Field, None, None)
+  >>> AdapterFactoryGrokker().grok('unnamed', UnNamedValueAdapter, None, config)
   True
+  >>> config.execute_actions()
 
 It should now be possible to retrieve the adapter from the component
 architecture.
@@ -87,13 +88,12 @@
 
 Again we manually ``grok`` the factory.
 
-  >>> AdapterFactoryGrokker().grok('named', NamedValueAdapter, Field, None, None)
+  >>> AdapterFactoryGrokker().grok('named', NamedValueAdapter, None, config)
   True
+  >>> config.execute_actions()
 
 It should now be possible to retrieve the adapter from the component
 architecture using the name defined.
 
   >>> print zope.component.queryAdapter(field, IValue, 'named')
   ValueAdapter
-
-

Modified: Sandbox/darrylcousins/mars.adapter/src/mars/adapter/meta.py
===================================================================
--- Sandbox/darrylcousins/mars.adapter/src/mars/adapter/meta.py	2008-01-28 01:41:02 UTC (rev 83272)
+++ Sandbox/darrylcousins/mars.adapter/src/mars/adapter/meta.py	2008-01-28 04:48:41 UTC (rev 83273)
@@ -4,6 +4,7 @@
 import grok
 
 import martian
+from martian.error import GrokError
 from martian import util
 
 import mars.adapter
@@ -11,18 +12,26 @@
 class AdapterFactoryGrokker(martian.ClassGrokker):
     component_class = mars.adapter.AdapterFactory
 
-    def grok(self, name, factory, context, module_info, templates):
+    def grok(self, name, factory, module_info, config, *kws):
         name = util.class_annotation(factory, 'grok.name', '')
-        factory = util.class_annotation(factory, 'mars.adapter.factory', None)
-        provided = zope.component.registry._getAdapterProvided(factory)
-        required = zope.component.registry._getAdapterRequired(factory, None)
-        #print '\nName: ', name, 'Factory:', factory, \
-        #      'Provided: ', provided, 'Required: ', required, '\n'
-        if factory is None:
-            # error message
-            pass
+        adapter_factory = util.class_annotation(
+                                    factory, 'mars.adapter.factory', None)
+        provides = zope.component.registry._getAdapterProvided(adapter_factory)
+        adapter_context = zope.component.registry._getAdapterRequired(
+                                    adapter_factory, None)
+
+        if adapter_factory is None:
+            raise GrokError(
+                    "mars.adapter.factory must be provided for AdapterFactory"
+                    )
         else:
-            zope.component.provideAdapter(factory, adapts=required, provides=provided,
-                                     name=name)
+            config.action( 
+                discriminator=('adapter', adapter_context[0], provides, name),
+                callable=zope.component.provideAdapter,
+                args=(adapter_factory, adapter_context, provides, name),
+                )
+            #zope.component.provideAdapter(adapter_factory, 
+            #                              adapts=adapter_context, 
+            #                              provides=provides, name=name)
+
         return True
-

Modified: Sandbox/darrylcousins/mars.adapter/src/mars/adapter/tests.py
===================================================================
--- Sandbox/darrylcousins/mars.adapter/src/mars/adapter/tests.py	2008-01-28 01:41:02 UTC (rev 83272)
+++ Sandbox/darrylcousins/mars.adapter/src/mars/adapter/tests.py	2008-01-28 04:48:41 UTC (rev 83273)
@@ -1,17 +1,23 @@
 import unittest
+
 from zope.testing import doctest
+from zope.configuration.config import ConfigurationMachine
 
+from martian import scan
+
 optionflags = doctest.NORMALIZE_WHITESPACE + doctest.ELLIPSIS
 
+def setUp(test):
+    test.globs['config'] = ConfigurationMachine()
+
 def test_suite():
-    suite = unittest.TestSuite()
-    suite.addTests([doctest.DocFileSuite('adapter.txt',
-                             optionflags=optionflags),
-                   ])
+    return doctest.DocFileSuite(
+            'adapter.txt',
+            setUp=setUp,
+            optionflags=optionflags
+            )
 
-    return suite
 
-
 if __name__ == '__main__':
     unittest.main(defaultTest='test_suite')
 



More information about the Checkins mailing list