[Zope3-checkins] CVS: Zope3/src/zope/context/tests - test_wrapper.py:1.20 test_ContextAware.py:NONE
Steve Alexander
steve@cat-box.net
Sat, 7 Jun 2003 09:00:03 -0400
Update of /cvs-repository/Zope3/src/zope/context/tests
In directory cvs.zope.org:/tmp/cvs-serv27748/src/zope/context/tests
Modified Files:
test_wrapper.py
Removed Files:
test_ContextAware.py
Log Message:
Removed the ContextAware mixin marker class.
It's a good idea, but should be implemented as a metaclass that makes
appropriate descriptors into contextdescriptors. That way, its actions
will be more predictable, and the C code to Wrapper can be simpler, and
needn't grow special cases.
=== Zope3/src/zope/context/tests/test_wrapper.py 1.19 => 1.20 ===
--- Zope3/src/zope/context/tests/test_wrapper.py:1.19 Mon Jun 2 07:06:57 2003
+++ Zope3/src/zope/context/tests/test_wrapper.py Sat Jun 7 09:00:02 2003
@@ -16,8 +16,7 @@
"""
import unittest
from zope.proxy import getProxiedObject
-from zope.context import Wrapper, wrapper
-from zope.context import ContextMethod, ContextProperty, ContextAware
+from zope.context import Wrapper, wrapper, ContextMethod, ContextProperty
from zope.proxy.tests.test_proxy import Thing, ProxyTestCase
_marker = object()
@@ -135,17 +134,12 @@
setattr(ContextUnawareObj, slot, doit)
proxy1 = self.new_proxy(ContextUnawareObj(), context)
- class ContextAwareObj(ContextAware):
- pass
- setattr(ContextAwareObj, slot, doit)
- proxy2 = self.new_proxy(ContextAwareObj(), context)
-
class ContextMethodObj(object):
pass
setattr(ContextMethodObj, slot, ContextMethod(doit))
- proxy3 = self.new_proxy(ContextMethodObj(), context)
+ proxy2 = self.new_proxy(ContextMethodObj(), context)
- return proxy1, proxy2, proxy3, context
+ return proxy1, proxy2, context
def test_normal_getattr(self):
class X(object):
@@ -171,35 +165,6 @@
self.assertEquals(p.getArgs(), (x, 'foo'))
self.assert_(p.getArgs()[0] is x)
- def test_ContextAware_getattr(self):
- class Y(ContextAware):
- def __init__(self, retval):
- self.args = None
- self.retval = retval
- def __getattr__(self, name):
- if name == '__del__':
- # We don't want Python's gc to think that we have a
- # __del__, otherwise cycles will not be collected.
- raise AttributeError, name
- self.args = self, name
- return self.__dict__['retval']
- def getArgs(self):
- # Need to get __dict__ from the clean object, because it
- # is a special descriptor and complains bitterly about
- # being got from the wrong kind of object.
- return getProxiedObject(self).__dict__['args']
-
- y = Y(23)
- p = self.new_proxy(y, 23)
- self.assertEquals(p.foo, 23)
- # Nothing special happens; we don't rebind the self of __getattr__
- self.assertEquals(p.getArgs(), (y, 'foo'))
- self.assert_(p.getArgs()[0] is y)
-
- def test_ContextAware_doesnt_mess_up___class__(self):
- class C(ContextAware): pass
- self.assertEqual(Wrapper(C(), None).__class__, C)
-
def test_ContextMethod_getattr(self):
class Z(object):
def __getattr__(self, name):
@@ -243,22 +208,6 @@
self.assertEquals(x.called_with, (p, 24))
self.assert_(x.called_with[0] is p)
- def test_ContextAware_property(self):
- class Y(ContextAware):
- def getFoo(self):
- self.called_with = self
- return 42
- def setFoo(self, value):
- self.called_with = self, value
- foo = property(getFoo, setFoo)
- y = Y()
- p = self.new_proxy(y)
- self.assertEquals(p.foo, 42)
- self.assert_(y.called_with is p)
- p.foo = 24
- self.assertEquals(y.called_with, (p, 24))
- self.assert_(y.called_with[0] is p)
-
def test_setattr(self):
class X(object):
def __setattr__(self, name, value):
@@ -270,14 +219,6 @@
self.assertEqual(x.value_called, (p, 'foo', 'bar'))
self.assert_(x.value_called[0] is x)
- class ContextAwareX(X, ContextAware):
- pass
- cax = ContextAwareX()
- p = self.new_proxy(cax)
- p.foo = 'bar'
- self.assertEqual(cax.value_called, (p, 'foo', 'bar'))
- self.assert_(cax.value_called[0] is cax)
-
X.__setattr__ = ContextMethod(X.__setattr__)
x = X()
p = self.new_proxy(x)
@@ -298,118 +239,96 @@
self.assertRaises(UnicodeError, setattr, p, u'baz\u1234', 23)
def test_getitem(self):
- p1, p2, p3, context = self.make_proxies('__getitem__')
+ p1, p2, context = self.make_proxies('__getitem__')
self.assertEquals(p1[42], (None, (42, )))
self.assertEquals(p2[42], (context, (42, )))
- self.assertEquals(p3[42], (context, (42, )))
# builtin
- p4 = self.new_proxy((1, 2), context)
- self.assertEquals(p4[0], 1)
- self.assertEquals(p4[1], 2)
- self.assertRaises(IndexError, p4.__getitem__, 2)
+ p = self.new_proxy((1, 2), context)
+ self.assertEquals(p[0], 1)
+ self.assertEquals(p[1], 2)
+ self.assertRaises(IndexError, p.__getitem__, 2)
def test_setitem(self):
- p1, p2, p3, context = self.make_proxies('__setitem__')
+ p1, p2, context = self.make_proxies('__setitem__')
p1[24] = 42
p2[24] = 42
- p3[24] = 42
self.assertEquals(p1.retval, (None, (24, 42)))
self.assertEquals(p2.retval, (context, (24, 42)))
- self.assertEquals(p3.retval, (context, (24, 42)))
# builtin
- p4 = self.new_proxy([1, 2], context)
- p4[1] = 3
- self.assertEquals(p4[1], 3)
- self.assertRaises(IndexError, p4.__setitem__, 2, 4)
+ p = self.new_proxy([1, 2], context)
+ p[1] = 3
+ self.assertEquals(p[1], 3)
+ self.assertRaises(IndexError, p.__setitem__, 2, 4)
def test_delitem(self):
- p1, p2, p3, context = self.make_proxies('__delitem__')
+ p1, p2, context = self.make_proxies('__delitem__')
del p1[42]
del p2[42]
- del p3[42]
self.assertEquals(p1.retval, (None, (42, )))
self.assertEquals(p2.retval, (context, (42, )))
- self.assertEquals(p3.retval, (context, (42, )))
# builtin
- p4 = self.new_proxy([1, 2], context)
- del p4[1]
- self.assertEquals(p4, [1])
- self.assertRaises(IndexError, p4.__delitem__, 2)
+ p = self.new_proxy([1, 2], context)
+ del p[1]
+ self.assertEquals(p, [1])
+ self.assertRaises(IndexError, p.__delitem__, 2)
def test_iter(self):
- p1, p2, p3, context = self.make_proxies('__iter__', iter(()))
+ p1, p2, context = self.make_proxies('__iter__', iter(()))
iter(p1)
iter(p2)
- iter(p3)
self.assertEquals(p1.retval, (None, ()))
self.assertEquals(p2.retval, (context, ()))
- self.assertEquals(p3.retval, (context, ()))
def test_call(self):
- p1, p2, p3, context = self.make_proxies('__call__')
+ p1, p2, context = self.make_proxies('__call__')
self.assertEquals(p1('foo', 'bar'), (None, ('foo', 'bar')))
self.assertEquals(p2('foo', 'bar'), (context, ('foo', 'bar')))
- self.assertEquals(p3('foo', 'bar'), (context, ('foo', 'bar')))
def test_str(self):
- p1, p2, p3, context = self.make_proxies('__str__', 'foo')
+ p1, p2, context = self.make_proxies('__str__', 'foo')
self.assertEquals(str(p1), 'foo')
self.assertEquals(str(p2), 'foo')
- self.assertEquals(str(p3), 'foo')
self.assertEquals(p1.retval, (None, ()))
self.assertEquals(p2.retval, (context, ()))
- self.assertEquals(p3.retval, (context, ()))
def test_contains(self):
- p1, p2, p3, context = self.make_proxies('__contains__', 1)
+ p1, p2, context = self.make_proxies('__contains__', 1)
self.assert_(42 in p1)
self.assert_(42 in p2)
- self.assert_(42 in p3)
self.assertEquals(p1.retval, (None, (42, )))
self.assertEquals(p2.retval, (context, (42, )))
- self.assertEquals(p3.retval, (context, (42, )))
def test_len(self):
- p1, p2, p3, context = self.make_proxies('__len__', 5)
+ p1, p2, context = self.make_proxies('__len__', 5)
self.assertEquals(len(p1), 5)
self.assertEquals(len(p2), 5)
- self.assertEquals(len(p3), 5)
self.assertEquals(p1.retval, (None, ()))
self.assertEquals(p2.retval, (context, ()))
- self.assertEquals(p3.retval, (context, ()))
- p1, p2, p3, context = self.make_proxies('__len__', 5)
+ p1, p2, 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)
+ p1, p2, 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)
+ p1, p2, 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)
+ p1, p2, 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):
=== Removed File Zope3/src/zope/context/tests/test_ContextAware.py ===