[Zope3-checkins] CVS: Zope3/src/zope/security/tests - test_checker.py:1.7.12.2 test_standard_checkers.py:1.2.4.2
Albertas Agejevas
alga@codeworks.lt
Mon, 23 Jun 2003 10:21:13 -0400
Update of /cvs-repository/Zope3/src/zope/security/tests
In directory cvs.zope.org:/tmp/cvs-serv16963/src/zope/security/tests
Modified Files:
Tag: cw-mail-branch
test_checker.py test_standard_checkers.py
Log Message:
One more sync with HEAD.
=== Zope3/src/zope/security/tests/test_checker.py 1.7.12.1 => 1.7.12.2 ===
=== Zope3/src/zope/security/tests/test_standard_checkers.py 1.2.4.1 => 1.2.4.2 ===
--- Zope3/src/zope/security/tests/test_standard_checkers.py:1.2.4.1 Sun Jun 22 10:23:54 2003
+++ Zope3/src/zope/security/tests/test_standard_checkers.py Mon Jun 23 10:20:42 2003
@@ -20,6 +20,7 @@
"""
from zope.security.checker import ProxyFactory, NamesChecker
+from __future__ import generators
def test_dict():
"""Test that we can do everything we expect to be able to do
@@ -205,6 +206,24 @@
"""
+def test_iter():
+ """
+ >>> list(ProxyFactory(iter([1, 2])))
+ [1, 2]
+ >>> list(ProxyFactory(iter((1, 2))))
+ [1, 2]
+ >>> list(ProxyFactory(iter({1:1, 2:2})))
+ [1, 2]
+ >>> def f():
+ ... for i in 1, 2:
+ ... yield i
+ ...
+ >>> list(ProxyFactory(f()))
+ [1, 2]
+ >>> list(ProxyFactory(f)())
+ [1, 2]
+ """
+
def test_new_class():
"""
@@ -401,6 +420,41 @@
1
"""
+def test_iter_of_sequences():
+ """
+ >>> class X:
+ ... d = 1, 2, 3
+ ... def __getitem__(self, i):
+ ... return self.d[i]
+ ...
+ >>> x = X()
+
+ We can iterate over sequences
+
+ >>> list(x)
+ [1, 2, 3]
+ >>> c = NamesChecker(['__getitem__'])
+ >>> p = ProxyFactory(x, c)
+
+ Even if they are proxied
+
+ >>> list(p)
+ [1, 2, 3]
+
+ But if the class has an iter:
+
+ >>> X.__iter__ = lambda self: iter(self.d)
+ >>> list(x)
+ [1, 2, 3]
+
+ We shouldn't be able to iterate if we don't have an assertion:
+
+ >>> list(p)
+ Traceback (most recent call last):
+ ...
+ ForbiddenAttribute: __iter__
+ """
+
from zope.testing.doctestunit import DocTestSuite