[Checkins] SVN: grok/branches/jw-simpler-skin-registration/src/grok/ Add tests for the skin directive. Tried and failed to come up with

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Jul 28 08:24:30 EDT 2008


Log message for revision 88859:
  Add tests for the skin directive. Tried and failed to come up with
  a way to check the directive is called on an Interface, not just
  a class. Make the skin directive available in the grok "namespace".

Changed:
  U   grok/branches/jw-simpler-skin-registration/src/grok/__init__.py
  U   grok/branches/jw-simpler-skin-registration/src/grok/directive.py
  A   grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface.py
  A   grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface_fixture.py

-=-
Modified: grok/branches/jw-simpler-skin-registration/src/grok/__init__.py
===================================================================
--- grok/branches/jw-simpler-skin-registration/src/grok/__init__.py	2008-07-28 10:53:10 UTC (rev 88858)
+++ grok/branches/jw-simpler-skin-registration/src/grok/__init__.py	2008-07-28 12:24:29 UTC (rev 88859)
@@ -49,7 +49,7 @@
     context, name, title, description, provides, global_utility, direct)
 from grok.directive import (
     template, templatedir, local_utility, permissions, require, site,
-    layer, viewletmanager, view, traversable, order)
+    layer, viewletmanager, view, traversable, order, skin)
 from grokcore.component.decorators import subscribe, adapter, implementer
 from martian.error import GrokError, GrokImportError
 

Modified: grok/branches/jw-simpler-skin-registration/src/grok/directive.py
===================================================================
--- grok/branches/jw-simpler-skin-registration/src/grok/directive.py	2008-07-28 10:53:10 UTC (rev 88858)
+++ grok/branches/jw-simpler-skin-registration/src/grok/directive.py	2008-07-28 12:24:29 UTC (rev 88859)
@@ -18,6 +18,8 @@
 import grok
 from zope import interface
 from zope.interface.interfaces import IInterface
+from zope.interface.interface import TAGGED_DATA
+
 from zope.publisher.interfaces.browser import IBrowserView
 
 import martian
@@ -205,8 +207,21 @@
     def get(self, directive, component, default):
         return component.queryTaggedValue(_taggedvaluekey, default)
 
+    def set(self, locals_, directive, value):
+        if directive.dotted_name() in locals_:
+            raise GrokImportError(
+                "The '%s' directive can only be called once per %s." %
+                (directive.name, directive.scope.description))
+        # Make use of the implementation details of interface tagged
+        # values.  Instead of being able to call 'setTaggedValue()'
+        # on an interface object, we only have access to the locals
+        # of the interface object.  We inject whatever setTaggedValue
+        # would've injected.
+        taggeddata = locals_.setdefault(TAGGED_DATA, {})
+        taggeddata[_taggedvaluekey] = value
+
     def setattr(self, context, directive, value):
-        context.setTaggedValue(_taggedvaluekey, value)
+        raise NotImplementedError, 'Do we need this?'
 
 TAGGEDVALUEONCE = TaggedValueStoreOnce()
 
@@ -214,7 +229,9 @@
     description = 'interface'
 
     def check(self, frame):
-        return IInterface.providedBy(frame)
+        # Wraaah - How can we check we're in an Interface, not just
+        # some class???
+        return util.frame_is_class(frame)
 
     def get(self, directive, component, module, default):
         return directive.store.get(directive, component, default)

Added: grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface.py
===================================================================
--- grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface.py	                        (rev 0)
+++ grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface.py	2008-07-28 12:24:29 UTC (rev 88859)
@@ -0,0 +1,8 @@
+"""
+   >>> import grok
+   >>> import grok.tests.directive.directiveoninterface_fixture
+
+   >>> from grok.tests.directive.directiveoninterface_fixture import IIsInterface
+   >>> print grok.skin.bind().get(IIsInterface)
+   skin name
+"""

Added: grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface_fixture.py
===================================================================
--- grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface_fixture.py	                        (rev 0)
+++ grok/branches/jw-simpler-skin-registration/src/grok/tests/directive/directiveoninterface_fixture.py	2008-07-28 12:24:29 UTC (rev 88859)
@@ -0,0 +1,5 @@
+import grok
+from zope import interface
+
+class IIsInterface(interface.Interface):
+    grok.skin('skin name')



More information about the Checkins mailing list