[Python-checkins] python/dist/src/Lib/test test_atexit.py,1.3,1.3.24.1

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Tue, 16 Jul 2002 13:09:09 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv27814/Lib/test

Modified Files:
      Tag: release22-maint
	test_atexit.py 
Log Message:
The atexit module effectively turned itself off if sys.exitfunc already
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.


Index: test_atexit.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_atexit.py,v
retrieving revision 1.3
retrieving revision 1.3.24.1
diff -C2 -d -r1.3 -r1.3.24.1
*** test_atexit.py	17 Jan 2001 21:51:35 -0000	1.3
--- test_atexit.py	16 Jul 2002 20:09:07 -0000	1.3.24.1
***************
*** 1,4 ****
! # Test the exit module
! from test_support import verbose
  import atexit
  
--- 1,8 ----
! # Test the atexit module.
! from test_support import TESTFN, vereq
! import atexit
! import os
! 
! input = """\
  import atexit
  
***************
*** 9,24 ****
      print "handler2", args, kargs
  
- # save any exit functions that may have been registered as part of the
- # test framework
- _exithandlers = atexit._exithandlers
- atexit._exithandlers = []
- 
  atexit.register(handler1)
  atexit.register(handler2)
  atexit.register(handler2, 7, kw="abc")
  
! # simulate exit behavior by calling atexit._run_exitfuncs directly...
! atexit._run_exitfuncs()
  
! # restore exit handlers
! atexit._exithandlers = _exithandlers
--- 13,61 ----
      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)