annotate Lib/test/test_atexit.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents ce7b8c317da2
children dc94134186c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
1 import sys
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
2 import unittest
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
3 import StringIO
24249
4a7b3bac3812 The atexit module effectively turned itself off if sys.exitfunc already
Tim Peters <tim.peters@gmail.com>
parents: 15966
diff changeset
4 import atexit
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
5 from test import test_support
13051
f13384105528 Added the atexit module and documentation from Skip Montanaro
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
7 class TestCase(unittest.TestCase):
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
8 def setUp(self):
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
9 s = StringIO.StringIO()
49463
ce7b8c317da2 backport
Skip Montanaro <skip@pobox.com>
parents: 49455
diff changeset
10 self.save_stdout = sys.stdout
ce7b8c317da2 backport
Skip Montanaro <skip@pobox.com>
parents: 49455
diff changeset
11 self.save_stderr = sys.stderr
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
12 sys.stdout = sys.stderr = self.subst_io = s
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
13 self.save_handlers = atexit._exithandlers
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
14 atexit._exithandlers = []
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
15
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
16 def tearDown(self):
49463
ce7b8c317da2 backport
Skip Montanaro <skip@pobox.com>
parents: 49455
diff changeset
17 sys.stdout = self.save_stdout
ce7b8c317da2 backport
Skip Montanaro <skip@pobox.com>
parents: 49455
diff changeset
18 sys.stderr = self.save_stderr
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
19 atexit._exithandlers = self.save_handlers
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
20
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
21 def test_args(self):
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
22 atexit.register(self.h1)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
23 atexit.register(self.h4)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
24 atexit.register(self.h4, 4, kw="abc")
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
25 atexit._run_exitfuncs()
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
26 self.assertEqual(self.subst_io.getvalue(),
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
27 "h4 (4,) {'kw': 'abc'}\nh4 () {}\nh1\n")
13051
f13384105528 Added the atexit module and documentation from Skip Montanaro
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28
49283
f8430b6876fb backport the atexit test for r66563
Benjamin Peterson <benjamin@python.org>
parents: 45872
diff changeset
29 def test_badargs(self):
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
30 atexit.register(lambda: 1, 0, 0, (x for x in (1,2)), 0, 0)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
31 self.assertRaises(TypeError, atexit._run_exitfuncs)
49283
f8430b6876fb backport the atexit test for r66563
Benjamin Peterson <benjamin@python.org>
parents: 45872
diff changeset
32
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
33 def test_order(self):
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
34 atexit.register(self.h1)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
35 atexit.register(self.h2)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
36 atexit.register(self.h3)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
37 atexit._run_exitfuncs()
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
38 self.assertEqual(self.subst_io.getvalue(), "h3\nh2\nh1\n")
24249
4a7b3bac3812 The atexit module effectively turned itself off if sys.exitfunc already
Tim Peters <tim.peters@gmail.com>
parents: 15966
diff changeset
39
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
40 def test_sys_override(self):
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
41 # be sure a preset sys.exitfunc is handled properly
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
42 exfunc = sys.exitfunc
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
43 sys.exitfunc = self.h1
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
44 reload(atexit)
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
45 try:
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
46 atexit.register(self.h2)
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
47 atexit._run_exitfuncs()
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
48 finally:
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
49 sys.exitfunc = exfunc
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
50 self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")
13051
f13384105528 Added the atexit module and documentation from Skip Montanaro
Fred Drake <fdrake@acm.org>
parents:
diff changeset
51
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
52 def test_raise(self):
49455
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
53 atexit.register(self.raise1)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
54 atexit.register(self.raise2)
6679c3252f9b backport
Skip Montanaro <skip@pobox.com>
parents: 49283
diff changeset
55 self.assertRaises(TypeError, atexit._run_exitfuncs)
33920
d82fa932b41b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33896
diff changeset
56
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
57 ### helpers
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
58 def h1(self):
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
59 print "h1"
24249
4a7b3bac3812 The atexit module effectively turned itself off if sys.exitfunc already
Tim Peters <tim.peters@gmail.com>
parents: 15966
diff changeset
60
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
61 def h2(self):
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
62 print "h2"
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
63
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
64 def h3(self):
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
65 print "h3"
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
66
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
67 def h4(self, *args, **kwargs):
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
68 print "h4", args, kwargs
24249
4a7b3bac3812 The atexit module effectively turned itself off if sys.exitfunc already
Tim Peters <tim.peters@gmail.com>
parents: 15966
diff changeset
69
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
70 def raise1(self):
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
71 raise TypeError
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
72
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
73 def raise2(self):
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
74 raise SystemError
24249
4a7b3bac3812 The atexit module effectively turned itself off if sys.exitfunc already
Tim Peters <tim.peters@gmail.com>
parents: 15966
diff changeset
75
33896
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
76 def test_main():
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
77 test_support.run_unittest(TestCase)
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
78
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
79
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
80 if __name__ == "__main__":
710b7e8d2ff2 Fix bug 1052242. Also includes rewrite of test case using unittest and
Skip Montanaro <skip@pobox.com>
parents: 28048
diff changeset
81 test_main()