diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-11 18:30:27 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-11 18:30:27 (GMT) |
commit | df3f7935167d593bc648fe807311c90d206ee34a (patch) | |
tree | b2aea0b91f87de30364df91648d4bea751a0e394 /Lib/test/test_new.py | |
parent | 14cb1e1eff09fc8b93681c4c0b00a21862817159 (diff) | |
download | cpython-df3f7935167d593bc648fe807311c90d206ee34a.zip cpython-df3f7935167d593bc648fe807311c90d206ee34a.tar.gz cpython-df3f7935167d593bc648fe807311c90d206ee34a.tar.bz2 |
Extend function() to support an optional closure argument.
Also, simplify some ref counting for other optional arguments.
Diffstat (limited to 'Lib/test/test_new.py')
-rw-r--r-- | Lib/test/test_new.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py index 641d9c2..eb762f7 100644 --- a/Lib/test/test_new.py +++ b/Lib/test/test_new.py @@ -71,6 +71,30 @@ func() verify(g['c'] == 3, '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() # Note: Jython will never have new.code() |