[Checkins] SVN: Sandbox/darrylcousins/mars.adapter/src/mars/adapter/ Added test

Darryl Cousins darryl at darrylcousins.net.nz
Sat Jul 14 20:48:28 EDT 2007


Log message for revision 77987:
  Added test

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

-=-
Modified: Sandbox/darrylcousins/mars.adapter/src/mars/adapter/meta.py
===================================================================
--- Sandbox/darrylcousins/mars.adapter/src/mars/adapter/meta.py	2007-07-15 00:22:40 UTC (rev 77986)
+++ Sandbox/darrylcousins/mars.adapter/src/mars/adapter/meta.py	2007-07-15 00:48:27 UTC (rev 77987)
@@ -16,9 +16,10 @@
         #provides = util.class_annotation(factory, 'grok.provides', None)
         name = util.class_annotation(factory, 'grok.name', '')
         factory = util.class_annotation(factory, 'mars.adapter.factory', None)
-        #print '\nName: ', name, 'Factory:', factory, '\n'
         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

Modified: Sandbox/darrylcousins/mars.adapter/src/mars/adapter/tests/adapter.py
===================================================================
--- Sandbox/darrylcousins/mars.adapter/src/mars/adapter/tests/adapter.py	2007-07-15 00:22:40 UTC (rev 77986)
+++ Sandbox/darrylcousins/mars.adapter/src/mars/adapter/tests/adapter.py	2007-07-15 00:48:27 UTC (rev 77987)
@@ -1,17 +1,63 @@
 """
-Test the claimed directives.
+Test the adapter factory.
 
   >>> import grok
+  >>> import zope.component
   >>> grok.grok('mars.adapter.tests.adapter')
 
-  >>> from zope.testbrowser.testing import Browser
-  >>> browser = Browser()
-  >>> browser.handleErrors = False
+  >>> from mars.adapter.tests.adapter import Field, IValue
+  >>> field = Field()
 
-TODO
+  >>> print zope.component.queryAdapter(field, IValue, name='named')
+  NamedValue
 
+  >>> print zope.component.queryAdapter(field, IValue)
+  UnNamedValue
+
+
 """
+import zope.interface
+import zope.component
 
 import grok
 import mars.adapter
 
+class IValue(zope.interface.Interface):
+    """A value."""
+
+class IField(zope.interface.Interface):
+    """A field"""
+
+class Field(grok.Model):
+    """A field"""
+    zope.interface.implements(IField)
+
+class UnNamedValue(object):
+    """Static value adapter."""
+    zope.component.adapts(IField)
+    zope.interface.implements(IValue)
+
+    def __init__(self, context):
+        self.context = context
+
+    def __repr__(self):
+        return self.__class__.__name__
+
+class UnNamedValueAdapter(mars.adapter.AdapterFactory):
+    mars.adapter.factory(UnNamedValue)
+
+class NamedValue(object):
+    """Static value adapter."""
+    zope.component.adapts(IField)
+    zope.interface.implements(IValue)
+
+    def __init__(self, context):
+        self.context = context
+
+    def __repr__(self):
+        return self.__class__.__name__
+
+class NamedValueAdapter(mars.adapter.AdapterFactory):
+    grok.name('named')
+    mars.adapter.factory(NamedValue)
+



More information about the Checkins mailing list