[Zope-CVS] CVS: Packages/ContextWrapper - test_wrapper.py:1.3 wrapper.c:1.3
Fred Drake Jr
fdrake@acm.org
Tue, 13 Nov 2001 12:56:22 -0500
Update of /cvs-repository/Packages/ContextWrapper
In directory cvs.zope.org:/tmp/cvs-serv3609
Modified Files:
test_wrapper.py wrapper.c
Log Message:
Add "callability" to the callable wrappers.
=== Packages/ContextWrapper/test_wrapper.py 1.2 => 1.3 ===
wrapper.new)
w = wrapper.new(lambda:3)
- # not yet implemented
- #self.assert_(callable(w))
+ self.assert_(callable(w))
+
+ def test_callable_wrapper_calls(self):
+ # test wrappers with various combinations of positional,
+ # extra, and keyword args
+ w = wrapper.new(lambda:3)
+ self.assert_(w() == 3)
+
+ w = wrapper.new(lambda a:a*3)
+ self.assert_(w(3) == 9)
+
+ w = wrapper.new(lambda **kw:kw)
+ self.assert_(w(foo="bar") == {"foo": "bar"})
+
+ w = wrapper.new(lambda a,*args,**kw:(a*3,args,kw))
+ self.assert_(w(4,5,6,frob="nitz") == (12, (5, 6), {"frob": "nitz"}))
def test_suite():
=== Packages/ContextWrapper/wrapper.c 1.2 => 1.3 ===
}
+static PyObject *
+callable_call(WrapperObject *self, PyObject *args, PyObject *kwds)
+{
+ return PyEval_CallObjectWithKeywords(self->wrap_object, args, kwds);
+}
+
static int
wrap_traverse(WrapperObject *self, visitproc visit, void *arg)
{
@@ -142,7 +148,7 @@
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
- 0, /* tp_call */
+ (ternaryfunc)callable_call, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */