cpython/Lib/test/test_atexit.py
Barry Warsaw 408b6d34de Complete the absolute import patch for the test suite. All relative
imports of test modules now import from the test package.  Other
related oddities are also fixed (like DeprecationWarning filters that
weren't specifying the full import part, etc.).  Also did a general
code cleanup to remove all "from test.test_support import *"'s.  Other
from...import *'s weren't changed.
2002-07-30 23:27:12 +00:00

62 lines
963 B
Python

# Test the atexit module.
from test.test_support import TESTFN, vereq
import atexit
from os import popen, unlink
import sys
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 = popen("%s %s" % (sys.executable, 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 = popen("%s %s" % (sys.executable, fname))
output = p.read()
p.close()
vereq(output, """\
indirect exit
direct exit
""")
unlink(fname)