diff options
Diffstat (limited to 'Lib/test/test_atexit.py')
| -rw-r--r-- | Lib/test/test_atexit.py | 59 |
1 files changed, 48 insertions, 11 deletions
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index 517610b..07f5a7e 100644 --- a/Lib/test/test_atexit.py +++ b/Lib/test/test_atexit.py @@ -1,5 +1,9 @@ -# Test the exit module -from test_support import verbose +# Test the atexit module. +from test_support import TESTFN, vereq +import atexit +import os + +input = """\ import atexit def handler1(): @@ -8,17 +12,50 @@ def handler1(): def handler2(*args, **kargs): print "handler2", args, kargs -# save any exit functions that may have been registered as part of the -# test framework -_exithandlers = atexit._exithandlers -atexit._exithandlers = [] - atexit.register(handler1) atexit.register(handler2) atexit.register(handler2, 7, kw="abc") +""" + +fname = TESTFN + ".py" +f = file(fname, "w") +f.write(input) +f.close() + +p = os.popen("python " + fname) +output = p.read() +p.close() +vereq(output, """\ +handler2 (7,) {'kw': 'abc'} +handler2 () {} +handler1 +""") + +input = """\ +def direct(): + print "direct exit" + +import sys +sys.exitfunc = direct + +# Make sure atexit doesn't drop +def indirect(): + print "indirect exit" + +import atexit +atexit.register(indirect) +""" + +f = file(fname, "w") +f.write(input) +f.close() -# simulate exit behavior by calling atexit._run_exitfuncs directly... -atexit._run_exitfuncs() +p = os.popen("python " + fname) +output = p.read() +p.close() +vereq(output, """\ +indirect exit +direct exit +""") -# restore exit handlers -atexit._exithandlers = _exithandlers +os.unlink(fname) |
