[Zope3-checkins] CVS: Zope3/src/zope/proxy/tests - test_proxy.py:1.4

Fred L. Drake, Jr. fred@zope.com
Tue, 1 Apr 2003 11:31:30 -0500


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

Modified Files:
	test_proxy.py 
Log Message:
- new test of iteration using a proxy returned by __iter__(); patch to
  make this work will be checked in shortly
- added comments explaining the differences between the two proxy
  iteration tests


=== Zope3/src/zope/proxy/tests/test_proxy.py 1.3 => 1.4 ===
--- Zope3/src/zope/proxy/tests/test_proxy.py:1.3	Tue Apr  1 11:08:42 2003
+++ Zope3/src/zope/proxy/tests/test_proxy.py	Tue Apr  1 11:31:30 2003
@@ -166,7 +166,9 @@
             b.append(x)
         self.assertEquals(a, b)
 
-    def test_wrapped_iterator(self):
+    def test_iteration_over_proxy(self):
+        # Wrap an iterator before starting iteration.
+        # PyObject_GetIter() will still be called on the proxy.
         a = [1, 2, 3]
         b = []
         for x in self.new_proxy(iter(a)):
@@ -174,6 +176,24 @@
         self.assertEquals(a, b)
         t = tuple(self.new_proxy(iter(a)))
         self.assertEquals(t, (1, 2, 3))
+
+    def test_iteration_using_proxy(self):
+        # Wrap an iterator within the iteration protocol, expecting it
+        # still to work.  PyObject_GetIter() will not be called on the
+        # proxy, so the tp_iter slot won't unwrap it.
+
+        class Iterable:
+            def __init__(self, test, data):
+                self.test = test
+                self.data = data
+            def __iter__(self):
+                return self.test.new_proxy(iter(self.data))
+
+        a = [1, 2, 3]
+        b = []
+        for x in Iterable(self, a):
+            b.append(x)
+        self.assertEquals(a, b)
 
     def test_bool_wrapped_None(self):
         w = self.new_proxy(None)