From: <cg...@us...> - 2008-01-01 06:15:06
|
Revision: 3935 http://jython.svn.sourceforge.net/jython/?rev=3935&view=rev Author: cgroves Date: 2007-12-31 22:15:03 -0800 (Mon, 31 Dec 2007) Log Message: ----------- from http://svn.python.org/projects/python/branches/release23-maint/Lib@59637 Added Paths: ----------- trunk/jython/Lib/test/test_atexit.py Added: trunk/jython/Lib/test/test_atexit.py =================================================================== --- trunk/jython/Lib/test/test_atexit.py (rev 0) +++ trunk/jython/Lib/test/test_atexit.py 2008-01-01 06:15:03 UTC (rev 3935) @@ -0,0 +1,66 @@ +# Test the atexit module. +from test.test_support import TESTFN, vereq, is_jython +import atexit +from os import popen, unlink +import sys + +executable = sys.executable +if is_jython: + executable = "jython" + +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' % (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' % (executable, fname)) +output = p.read() +p.close() +vereq(output, """\ +indirect exit +direct exit +""") + +unlink(fname) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |