summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_atexit.py
blob: c9d72a78cd552116cda08294852c36ec49aad29e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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)