[Zope3-checkins] CVS: Zope3/src/zope/proxy/context/tests - test_wrapper.py:1.10
Steve Alexander
steve@cat-box.net
Wed, 7 May 2003 05:33:30 -0400
Update of /cvs-repository/Zope3/src/zope/proxy/context/tests
In directory cvs.zope.org:/tmp/cvs-serv16591/src/zope/proxy/context/tests
Modified Files:
test_wrapper.py
Log Message:
__nonzero__ is now supported as a ContextDescriptor
=== Zope3/src/zope/proxy/context/tests/test_wrapper.py 1.9 => 1.10 ===
--- Zope3/src/zope/proxy/context/tests/test_wrapper.py:1.9 Thu May 1 17:37:28 2003
+++ Zope3/src/zope/proxy/context/tests/test_wrapper.py Wed May 7 05:32:59 2003
@@ -11,6 +11,9 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
+"""
+$Id$
+"""
import pickle
import unittest
@@ -18,10 +21,10 @@
from zope.proxy.context import ContextMethod, ContextProperty, ContextAware
from zope.proxy.tests.test_proxy import Thing, ProxyTestCase
-
_marker = object()
class WrapperTestCase(ProxyTestCase):
+
def new_proxy(self, o, c=None):
return wrapper.Wrapper(o, c)
@@ -33,7 +36,6 @@
self.assertEquals(wrapper.getobject(w), (o1, o2))
self.assert_(wrapper.getcontext(w) is o3)
-
def test_subclass_constructor(self):
class MyWrapper(wrapper.Wrapper):
def __init__(self, *args, **kwds):
@@ -163,7 +165,6 @@
class C(ContextAware): pass
self.assertEqual(ContextWrapper(C(), None).__class__, C)
-
def test_ContextMethod_getattr(self):
class Z(object):
def __getattr__(self, name):
@@ -329,6 +330,72 @@
self.assertEquals(p1.retval, (None, ()))
self.assertEquals(p2.retval, (context, ()))
self.assertEquals(p3.retval, (context, ()))
+
+ p1, p2, p3, context = self.make_proxies('__len__', 5)
+ self.assertEquals(bool(p1), True)
+ self.assertEquals(bool(p2), True)
+ self.assertEquals(bool(p3), True)
+ self.assertEquals(p1.retval, (None, ()))
+ self.assertEquals(p2.retval, (context, ()))
+ self.assertEquals(p3.retval, (context, ()))
+
+ p1, p2, p3, context = self.make_proxies('__len__', 0)
+ self.assertEquals(bool(p1), False)
+ self.assertEquals(bool(p2), False)
+ self.assertEquals(bool(p3), False)
+ self.assertEquals(p1.retval, (None, ()))
+ self.assertEquals(p2.retval, (context, ()))
+ self.assertEquals(p3.retval, (context, ()))
+
+ def test_nonzero(self):
+ p1, p2, p3, context = self.make_proxies('__nonzero__', True)
+ self.assertEquals(bool(p1), True)
+ self.assertEquals(bool(p2), True)
+ self.assertEquals(bool(p3), True)
+ self.assertEquals(p1.retval, (None, ()))
+ self.assertEquals(p2.retval, (context, ()))
+ self.assertEquals(p3.retval, (context, ()))
+
+ p1, p2, p3, context = self.make_proxies('__nonzero__', False)
+ self.assertEquals(bool(p1), False)
+ self.assertEquals(bool(p2), False)
+ self.assertEquals(bool(p3), False)
+ self.assertEquals(p1.retval, (None, ()))
+ self.assertEquals(p2.retval, (context, ()))
+ self.assertEquals(p3.retval, (context, ()))
+
+ def test_nonzero_with_len(self):
+ class ThingWithLenAndNonzero(object):
+ len_called = False
+ nonzero_called = False
+ retval = None
+
+ def __len__(self):
+ self.len_called = True
+ self.retval = self
+ return 0
+
+ def __nonzero__(self):
+ self.nonzero_called = True
+ self.retval = self
+ return False
+
+ obj = ThingWithLenAndNonzero()
+ w = self.new_proxy(obj)
+ self.assertEquals(bool(w), False)
+ self.assertEquals(obj.nonzero_called, True)
+ self.assertEquals(obj.len_called, False)
+ self.assert_(obj.retval is obj)
+
+ ThingWithLenAndNonzero.__nonzero__ = ContextMethod(
+ ThingWithLenAndNonzero.__nonzero__.im_func)
+
+ obj = ThingWithLenAndNonzero()
+ w = self.new_proxy(obj)
+ self.assertEquals(bool(w), False)
+ self.assertEquals(obj.nonzero_called, True)
+ self.assertEquals(obj.len_called, False)
+ self.assert_(obj.retval is w)
# Tests for wrapper module globals