[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/annotation/ Added
__nonzero__ method to annotations, so we can quickly test
Jim Fulton
jim at zope.com
Mon Jul 19 10:56:53 EDT 2004
Log message for revision 26632:
Added __nonzero__ method to annotations, so we can quickly test
whether we have annotations.
Changed:
U Zope3/trunk/src/zope/app/annotation/attribute.py
U Zope3/trunk/src/zope/app/annotation/interfaces.py
U Zope3/trunk/src/zope/app/annotation/tests/annotations.py
-=-
Modified: Zope3/trunk/src/zope/app/annotation/attribute.py
===================================================================
--- Zope3/trunk/src/zope/app/annotation/attribute.py 2004-07-19 14:28:22 UTC (rev 26631)
+++ Zope3/trunk/src/zope/app/annotation/attribute.py 2004-07-19 14:56:53 UTC (rev 26632)
@@ -36,6 +36,9 @@
def __init__(self, obj):
self.obj = obj
+ def __nonzero__(self):
+ return bool(getattr(self.obj, '__annotations__', 0))
+
def get(self, key, default=None):
"""See zope.app.annotation.interfaces.IAnnotations"""
annotations = getattr(self.obj, '__annotations__', None)
Modified: Zope3/trunk/src/zope/app/annotation/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/annotation/interfaces.py 2004-07-19 14:28:22 UTC (rev 26631)
+++ Zope3/trunk/src/zope/app/annotation/interfaces.py 2004-07-19 14:56:53 UTC (rev 26632)
@@ -47,6 +47,10 @@
"""
+ def __nonzero__():
+ """Test whether there are any annotations
+ """
+
def __getitem__(key):
"""Return the annotation stored under key.
Modified: Zope3/trunk/src/zope/app/annotation/tests/annotations.py
===================================================================
--- Zope3/trunk/src/zope/app/annotation/tests/annotations.py 2004-07-19 14:28:22 UTC (rev 26631)
+++ Zope3/trunk/src/zope/app/annotation/tests/annotations.py 2004-07-19 14:56:53 UTC (rev 26632)
@@ -32,6 +32,13 @@
def setUp(self):
self.obj = {1:2, 3:4}
+ def test_nonzero(self):
+ self.failIf(self.annotations)
+ self.annotations['unittest'] = self.obj
+ self.failUnless(self.annotations)
+ del self.annotations['unittest']
+ self.failIf(self.annotations)
+
def testInterfaceVerifies(self):
verifyObject(IAnnotations, self.annotations)
More information about the Zope3-Checkins
mailing list