[Python-checkins] python/dist/src/Lib/test test_new.py,1.14,1.15
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
Thu, 11 Jul 2002 11:30:29 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv2891/Lib/test
Modified Files:
test_new.py
Log Message:
Extend function() to support an optional closure argument.
Also, simplify some ref counting for other optional arguments.
Index: test_new.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_new.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test_new.py 9 Dec 2001 10:19:25 -0000 1.14
--- test_new.py 11 Jul 2002 18:30:27 -0000 1.15
***************
*** 72,75 ****
--- 72,99 ----
'Could not create a proper function object')
+ # test the various extended flavors of function.new
+ def f(x):
+ def g(y):
+ return x + y
+ return g
+ g = f(4)
+ new.function(f.func_code, {}, "blah")
+ g2 = new.function(g.func_code, {}, "blah", (2,), g.func_closure)
+ verify(g2() == 6)
+ g3 = new.function(g.func_code, {}, "blah", None, g.func_closure)
+ verify(g3(5) == 9)
+ def test_closure(func, closure, exc):
+ try:
+ new.function(func.func_code, {}, "", None, closure)
+ except exc:
+ pass
+ else:
+ print "corrupt closure accepted"
+
+ test_closure(g, None, TypeError) # invalid closure
+ test_closure(g, (1,), TypeError) # non-cell in closure
+ test_closure(g, (1, 1), ValueError) # closure is wrong size
+ test_closure(f, g.func_closure, ValueError) # no closure needed
+
print 'new.code()'
# bogus test of new.code()