[Zope-Checkins] CVS: Zope3/lib/python/Zope/ContextWrapper/tests - test_proxy.py:1.1.4.2 test_wrapper.py:1.1.2.4
Fred L. Drake, Jr.
fdrake@acm.org
Thu, 6 Jun 2002 12:49:29 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/ContextWrapper/tests
In directory cvs.zope.org:/tmp/cvs-serv21818/tests
Modified Files:
Tag: Zope-3x-branch
test_proxy.py test_wrapper.py
Log Message:
Since the __new__ methods parse their arguments, make sure they check *all*
their arguments, not just the positional args.
Added new tests that check their expected behavior.
=== Zope3/lib/python/Zope/ContextWrapper/tests/test_proxy.py 1.1.4.1 => 1.1.4.2 ===
return proxy.proxy(o)
+ def test_constructor(self):
+ o = object()
+ self.assertRaises(TypeError, proxy.proxy, o, o)
+ self.assertRaises(TypeError, proxy.proxy, o, key='value')
+ self.assertRaises(TypeError, proxy.proxy, key='value')
+
+ def test_subclass_constructor(self):
+ class MyProxy(proxy.proxy):
+ def __new__(cls, *args, **kwds):
+ return super(MyProxy, cls).__new__(cls, *args, **kwds)
+ def __init__(self, *args, **kwds):
+ super(MyProxy, self).__init__(*args, **kwds)
+ o1 = object()
+ o2 = object()
+ o = MyProxy((o1, o2))
+ self.assertEquals(o1, o[0])
+ self.assertEquals(o2, o[1])
+
+ self.assertRaises(TypeError, MyProxy, o1, o2)
+ self.assertRaises(TypeError, MyProxy, o1, key='value')
+ self.assertRaises(TypeError, MyProxy, key='value')
+
+ # Check that are passed to __init__() overrides what's passed
+ # to __new__().
+ class MyProxy2(proxy.proxy):
+ def __new__(cls, *args, **kwds):
+ return super(MyProxy2, cls).__new__(cls, 'value')
+
+ p = MyProxy2('splat!')
+ self.assertEquals(list(p), list('splat!'))
+
+ class MyProxy3(MyProxy2):
+ def __init__(self, arg):
+ assert list(self) == list('value')
+ super(MyProxy3, self).__init__('another')
+
+ p = MyProxy3('notused')
+ self.assertEquals(list(p), list('another'))
+
def test_proxy_attributes(self):
o = Thing()
o.foo = 1
=== Zope3/lib/python/Zope/ContextWrapper/tests/test_wrapper.py 1.1.2.3 => 1.1.2.4 ===
return wrapper.Wrapper(o, c)
+ def test_constructor(self):
+ o1 = object()
+ o2 = object()
+ o3 = object()
+ w = self.new_proxy((o1, o2), o3)
+ 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):
+ super(MyWrapper, self).__init__('foo', **kwds)
+
+ w = MyWrapper(1, 2, key='value')
+ self.assertEquals(wrapper.getobject(w), 'foo')
+ self.assertEquals(wrapper.getdict(w), {'key': 'value'})
+
+ # __new__ catches too many positional args:
+ self.assertRaises(TypeError, MyWrapper, 1, 2, 3)
+
def test_wrapper_basics(self):
o1 = 1
o2 = 12