1- import sys
2- import unittest
3- import io
41import atexit
2+ import io
53import os
4+ import sys
5+ import textwrap
6+ import unittest
67from test import support
78from test .support import script_helper
89
@@ -156,15 +157,15 @@ def test_bound_methods(self):
156157
157158 def test_shutdown (self ):
158159 # Actually test the shutdown mechanism in a subprocess
159- code = """if 1:
160+ code = textwrap . dedent ( """
160161 import atexit
161162
162163 def f(msg):
163164 print(msg)
164165
165166 atexit.register(f, "one")
166167 atexit.register(f, "two")
167- """
168+ """ )
168169 res = script_helper .assert_python_ok ("-c" , code )
169170 self .assertEqual (res .out .decode ().splitlines (), ["two" , "one" ])
170171 self .assertFalse (res .err )
@@ -178,13 +179,13 @@ def test_callbacks_leak(self):
178179 # take care to free callbacks in its per-subinterpreter module
179180 # state.
180181 n = atexit ._ncallbacks ()
181- code = r"""if 1:
182+ code = textwrap . dedent ( r"""
182183 import atexit
183184 def f():
184185 pass
185186 atexit.register(f)
186187 del atexit
187- """
188+ """ )
188189 ret = support .run_in_subinterp (code )
189190 self .assertEqual (ret , 0 )
190191 self .assertEqual (atexit ._ncallbacks (), n )
@@ -193,13 +194,13 @@ def test_callbacks_leak_refcycle(self):
193194 # Similar to the above, but with a refcycle through the atexit
194195 # module.
195196 n = atexit ._ncallbacks ()
196- code = r"""if 1:
197+ code = textwrap . dedent ( r"""
197198 import atexit
198199 def f():
199200 pass
200201 atexit.register(f)
201202 atexit.__atexit = atexit
202- """
203+ """ )
203204 ret = support .run_in_subinterp (code )
204205 self .assertEqual (ret , 0 )
205206 self .assertEqual (atexit ._ncallbacks (), n )
@@ -210,13 +211,13 @@ def test_callback_on_subinterpreter_teardown(self):
210211 expected = b"The test has passed!"
211212 r , w = os .pipe ()
212213
213- code = r"""if 1:
214+ code = textwrap . dedent ( r"""
214215 import os
215216 import atexit
216217 def callback():
217218 os.write({:d}, b"The test has passed!")
218219 atexit.register(callback)
219- """ .format (w )
220+ """ .format (w ))
220221 ret = support .run_in_subinterp (code )
221222 os .close (w )
222223 self .assertEqual (os .read (r , len (expected )), expected )
0 commit comments