Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit aa9559b

Browse files
committed
Fix timing of a test and use dedent for inline scripts
The test test_other_thread_Py_Exit had a timing problem under maxOS and SLP 2.7.13. Also used dedent to get rid of the restrictions of inline scripts. (grafted from 6b9da7302720834198effb5ecf7a147ba43db2e6)
1 parent 3766741 commit aa9559b

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

Stackless/unittests/test_shutdown.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
withThreads = False
5151
from support import test_main # @UnusedImport
5252
from support import StacklessTestCase
53+
from textwrap import dedent
5354

5455

5556
@unittest.skipUnless(withThreads, "requires thread support")
@@ -135,7 +136,9 @@ def test_deep_thread(self):
135136
if not stackless.enable_softswitch(None):
136137
args.append("--hard")
137138

138-
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1:
139+
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent("""
140+
from __future__ import print_function, absolute_import
141+
139142
import threading
140143
import stackless
141144
import time
@@ -163,7 +166,7 @@ def recurse():
163166
# print("end")
164167
sys.stdout.flush()
165168
sys.exit(42)
166-
"""] + args)
169+
""")] + args)
167170
self.assertEqual(rc, 42)
168171

169172
def test_deep_tasklets(self):
@@ -173,7 +176,9 @@ def test_deep_tasklets(self):
173176
if not stackless.enable_softswitch(None):
174177
args.append("--hard")
175178

176-
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1:
179+
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent("""
180+
from __future__ import print_function, absolute_import
181+
177182
import stackless
178183
import sys
179184
from stackless import _test_nostacklesscall as apply
@@ -199,7 +204,7 @@ def recurse():
199204
# print("end")
200205
sys.stdout.flush()
201206
sys.exit(42)
202-
"""] + args)
207+
""")] + args)
203208
self.assertEqual(rc, 42)
204209

205210
def test_exit_in_deep_tasklet1(self):
@@ -209,7 +214,9 @@ def test_exit_in_deep_tasklet1(self):
209214
if not stackless.enable_softswitch(None):
210215
args.append("--hard")
211216

212-
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1:
217+
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent("""
218+
from __future__ import print_function, absolute_import
219+
213220
import stackless
214221
import sys
215222
from stackless import _test_nostacklesscall as apply
@@ -241,7 +248,7 @@ def recurse():
241248
print("OOPS, must not be reached")
242249
sys.stdout.flush()
243250
sys.exit(44)
244-
"""] + args)
251+
""")] + args)
245252
self.assertEqual(rc, 42)
246253

247254
def test_exit_in_deep_tasklet2(self):
@@ -251,7 +258,9 @@ def test_exit_in_deep_tasklet2(self):
251258
if not stackless.enable_softswitch(None):
252259
args.append("--hard")
253260

254-
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1:
261+
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent("""
262+
from __future__ import print_function, absolute_import
263+
255264
import stackless
256265
import sys
257266
from stackless import _test_nostacklesscall as apply
@@ -288,7 +297,7 @@ def recurse():
288297
print("OOPS, must not be reached")
289298
sys.stdout.flush()
290299
sys.exit(44)
291-
"""] + args)
300+
""")] + args)
292301
self.assertEqual(rc, 42)
293302

294303
def test_deep_Py_Exit(self):
@@ -302,7 +311,9 @@ def test_deep_Py_Exit(self):
302311
if not stackless.enable_softswitch(None):
303312
args.append("--hard")
304313

305-
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1:
314+
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent("""
315+
from __future__ import print_function, absolute_import
316+
306317
import stackless
307318
import sys
308319
import ctypes
@@ -329,7 +340,7 @@ def recurse():
329340
print("OOPS, must not be reached")
330341
sys.stdout.flush()
331342
sys.exit(43)
332-
"""] + args)
343+
""")] + args)
333344
self.assertEqual(rc, 42)
334345

335346
@unittest.skipUnless(withThreads, "requires thread support")
@@ -344,7 +355,9 @@ def test_other_thread_Py_Exit(self):
344355
if not stackless.enable_softswitch(None):
345356
args.append("--hard")
346357

347-
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1:
358+
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent("""
359+
from __future__ import print_function, absolute_import
360+
348361
import stackless
349362
import sys
350363
import ctypes
@@ -372,7 +385,7 @@ def exit():
372385
print("OOPS, must not be reached")
373386
sys.stdout.flush()
374387
sys.exit(43)
375-
"""] + args)
388+
""")] + args)
376389
self.assertEqual(rc, 42)
377390

378391
@unittest.skipUnless(withThreads, "requires thread support")
@@ -383,7 +396,9 @@ def test_kill_modifies_slp_cstack_chain(self):
383396
if not stackless.enable_softswitch(None):
384397
args.append("--hard")
385398

386-
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import, division\nif 1:
399+
rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent("""
400+
from __future__ import print_function, absolute_import, division
401+
387402
import threading
388403
import stackless
389404
import time
@@ -447,7 +462,7 @@ def other_thread():
447462
event.wait(5.0)
448463
print("end")
449464
sys.exit(42)
450-
"""] + args)
465+
""")] + args)
451466
self.assertEqual(rc, 42)
452467

453468

0 commit comments

Comments
 (0)