[Zope3-checkins] CVS: Zope3/src/zope/component/tests - components.py:1.3

Steve Alexander steve@cat-box.net
Mon, 27 Jan 2003 12:32:13 -0500


Update of /cvs-repository/Zope3/src/zope/component/tests
In directory cvs.zope.org:/tmp/cvs-serv1839/src/zope/component/tests

Modified Files:
	components.py 
Log Message:
Added a RecordingAdapter class that is to be used as a base for testing
whether a component gets an adapter appropriately.


=== Zope3/src/zope/component/tests/components.py 1.2 => 1.3 ===
--- Zope3/src/zope/component/tests/components.py:1.2	Wed Dec 25 09:13:32 2002
+++ Zope3/src/zope/component/tests/components.py	Mon Jan 27 12:32:10 2003
@@ -20,6 +20,29 @@
 from zope.interface import Interface
 from zope.interface import Attribute
 
+class RecordingAdapter:
+
+    def __init__(self):
+        self.record = []
+
+    def __call__(self, context):
+        # Note that this sets the context rather than appending to the record
+        # so as not to assume things about adapters being cached, if this
+        # happens in the future.
+        self.context = context
+        return self
+
+    def check(self, *args):
+        record = self.record
+        if len(args) != len(record):
+            raise AssertionError('wrong number of entries in record',
+                                 args, record)
+        for arg, entry in zip(args, record):
+            if arg != entry:
+                raise AssertionError('record entry does not match',
+                                     args, record)
+
+
 class IApp(Interface):
     a = Attribute('test attribute')
     def f(): "test func"