0001 # Test the atexit module. 0002 from test.test_support import TESTFN, vereq, is_jython 0003 import atexit 0004 from os import popen, unlink 0005 import sys 0006 0007 executable = sys.executable 0008 if is_jython: 0009 executable = "jython" 0010 0011 input = """\ 0012 import atexit 0013 0014 def handler1(): 0015 print "handler1" 0016 0017 def handler2(*args, **kargs): 0018 print "handler2", args, kargs 0019 0020 atexit.register(handler1) 0021 atexit.register(handler2) 0022 atexit.register(handler2, 7, kw="abc") 0023 """ 0024 0025 fname = TESTFN + ".py" 0026 f = file(fname, "w") 0027 f.write(input) 0028 f.close() 0029 0030 p = popen('"%s" %s' % (executable, fname)) 0031 output = p.read() 0032 p.close() 0033 vereq(output, """\ 0034 handler2 (7,) {'kw': 'abc'} 0035 handler2 () {} 0036 handler1 0037 """) 0038 0039 input = """\ 0040 def direct(): 0041 print "direct exit" 0042 0043 import sys 0044 sys.exitfunc = direct 0045 0046 # Make sure atexit doesn't drop 0047 def indirect(): 0048 print "indirect exit" 0049 0050 import atexit 0051 atexit.register(indirect) 0052 """ 0053 0054 f = file(fname, "w") 0055 f.write(input) 0056 f.close() 0057 0058 p = popen('"%s" %s' % (executable, fname)) 0059 output = p.read() 0060 p.close() 0061 vereq(output, """\ 0062 indirect exit 0063 direct exit 0064 """) 0065 0066 unlink(fname) 0067
Generated by PyXR 0.9.4