summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_atexit.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-12-14 21:40:40 (GMT)
committerGitHub <noreply@github.com>2020-12-14 21:40:40 (GMT)
commit83d52044ae4def1e8611a4b1b9263b850ca5c458 (patch)
treecdc3b90536390556290ca0fc2f12ea54a0135289 /Lib/test/test_atexit.py
parentfdb9efce6ac211f973088eef508740c3fa2bd182 (diff)
downloadcpython-83d52044ae4def1e8611a4b1b9263b850ca5c458.zip
cpython-83d52044ae4def1e8611a4b1b9263b850ca5c458.tar.gz
cpython-83d52044ae4def1e8611a4b1b9263b850ca5c458.tar.bz2
bpo-42639: Cleanup atexitmodule.c (GH-23770)
* Rename "atexitmodule_state" to "struct atexit_state". * Rename "modstate" to "state". * Rename "self" parameter to "module". * test_atexit uses textwrap.dedent(). * Remove _Py_PyAtExit() function: inline it into atexit_exec(). * PyInterpreterState: rename pyexitfunc to atexit_func, rename pyexitmodule to atexit_module.
Diffstat (limited to 'Lib/test/test_atexit.py')
-rw-r--r--Lib/test/test_atexit.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py
index 3105f6c..906f96d 100644
--- a/Lib/test/test_atexit.py
+++ b/Lib/test/test_atexit.py
@@ -1,8 +1,9 @@
-import sys
-import unittest
-import io
import atexit
+import io
import os
+import sys
+import textwrap
+import unittest
from test import support
from test.support import script_helper
@@ -156,7 +157,7 @@ class GeneralTest(unittest.TestCase):
def test_shutdown(self):
# Actually test the shutdown mechanism in a subprocess
- code = """if 1:
+ code = textwrap.dedent("""
import atexit
def f(msg):
@@ -164,7 +165,7 @@ class GeneralTest(unittest.TestCase):
atexit.register(f, "one")
atexit.register(f, "two")
- """
+ """)
res = script_helper.assert_python_ok("-c", code)
self.assertEqual(res.out.decode().splitlines(), ["two", "one"])
self.assertFalse(res.err)
@@ -178,13 +179,13 @@ class SubinterpreterTest(unittest.TestCase):
# take care to free callbacks in its per-subinterpreter module
# state.
n = atexit._ncallbacks()
- code = r"""if 1:
+ code = textwrap.dedent(r"""
import atexit
def f():
pass
atexit.register(f)
del atexit
- """
+ """)
ret = support.run_in_subinterp(code)
self.assertEqual(ret, 0)
self.assertEqual(atexit._ncallbacks(), n)
@@ -193,13 +194,13 @@ class SubinterpreterTest(unittest.TestCase):
# Similar to the above, but with a refcycle through the atexit
# module.
n = atexit._ncallbacks()
- code = r"""if 1:
+ code = textwrap.dedent(r"""
import atexit
def f():
pass
atexit.register(f)
atexit.__atexit = atexit
- """
+ """)
ret = support.run_in_subinterp(code)
self.assertEqual(ret, 0)
self.assertEqual(atexit._ncallbacks(), n)
@@ -210,13 +211,13 @@ class SubinterpreterTest(unittest.TestCase):
expected = b"The test has passed!"
r, w = os.pipe()
- code = r"""if 1:
+ code = textwrap.dedent(r"""
import os
import atexit
def callback():
os.write({:d}, b"The test has passed!")
atexit.register(callback)
- """.format(w)
+ """.format(w))
ret = support.run_in_subinterp(code)
os.close(w)
self.assertEqual(os.read(r, len(expected)), expected)