mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
existed at the time atexit first got imported. That's a bug, and this fixes it. Also reworked test_atexit.py to test for this too, and to stop using an "expected output" file, and to test what actually happens at exit instead of just simulating what it thinks atexit will do at exit. Bugfix candidate, but it's messy so I'll backport to 2.2 myself.
61 lines
906 B
Python
61 lines
906 B
Python
# Test the atexit module.
|
|
from test_support import TESTFN, vereq
|
|
import atexit
|
|
import os
|
|
|
|
input = """\
|
|
import atexit
|
|
|
|
def handler1():
|
|
print "handler1"
|
|
|
|
def handler2(*args, **kargs):
|
|
print "handler2", args, kargs
|
|
|
|
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()
|
|
|
|
p = os.popen("python " + fname)
|
|
output = p.read()
|
|
p.close()
|
|
vereq(output, """\
|
|
indirect exit
|
|
direct exit
|
|
""")
|
|
|
|
os.unlink(fname)
|