From aa9559b43094dc3e7d8d94ccb5e22b48ad22a56b Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Tue, 28 Mar 2017 12:17:11 +0200 Subject: [PATCH] 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) --- Stackless/unittests/test_shutdown.py | 43 +++++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/Stackless/unittests/test_shutdown.py b/Stackless/unittests/test_shutdown.py index 69555ba883c112..9a9fde96f383a9 100644 --- a/Stackless/unittests/test_shutdown.py +++ b/Stackless/unittests/test_shutdown.py @@ -50,6 +50,7 @@ withThreads = False from support import test_main # @UnusedImport from support import StacklessTestCase +from textwrap import dedent @unittest.skipUnless(withThreads, "requires thread support") @@ -135,7 +136,9 @@ def test_deep_thread(self): if not stackless.enable_softswitch(None): args.append("--hard") - rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1: + rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent(""" + from __future__ import print_function, absolute_import + import threading import stackless import time @@ -163,7 +166,7 @@ def recurse(): # print("end") sys.stdout.flush() sys.exit(42) - """] + args) + """)] + args) self.assertEqual(rc, 42) def test_deep_tasklets(self): @@ -173,7 +176,9 @@ def test_deep_tasklets(self): if not stackless.enable_softswitch(None): args.append("--hard") - rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1: + rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent(""" + from __future__ import print_function, absolute_import + import stackless import sys from stackless import _test_nostacklesscall as apply @@ -199,7 +204,7 @@ def recurse(): # print("end") sys.stdout.flush() sys.exit(42) - """] + args) + """)] + args) self.assertEqual(rc, 42) def test_exit_in_deep_tasklet1(self): @@ -209,7 +214,9 @@ def test_exit_in_deep_tasklet1(self): if not stackless.enable_softswitch(None): args.append("--hard") - rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1: + rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent(""" + from __future__ import print_function, absolute_import + import stackless import sys from stackless import _test_nostacklesscall as apply @@ -241,7 +248,7 @@ def recurse(): print("OOPS, must not be reached") sys.stdout.flush() sys.exit(44) - """] + args) + """)] + args) self.assertEqual(rc, 42) def test_exit_in_deep_tasklet2(self): @@ -251,7 +258,9 @@ def test_exit_in_deep_tasklet2(self): if not stackless.enable_softswitch(None): args.append("--hard") - rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1: + rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent(""" + from __future__ import print_function, absolute_import + import stackless import sys from stackless import _test_nostacklesscall as apply @@ -288,7 +297,7 @@ def recurse(): print("OOPS, must not be reached") sys.stdout.flush() sys.exit(44) - """] + args) + """)] + args) self.assertEqual(rc, 42) def test_deep_Py_Exit(self): @@ -302,7 +311,9 @@ def test_deep_Py_Exit(self): if not stackless.enable_softswitch(None): args.append("--hard") - rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1: + rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent(""" + from __future__ import print_function, absolute_import + import stackless import sys import ctypes @@ -329,7 +340,7 @@ def recurse(): print("OOPS, must not be reached") sys.stdout.flush() sys.exit(43) - """] + args) + """)] + args) self.assertEqual(rc, 42) @unittest.skipUnless(withThreads, "requires thread support") @@ -344,7 +355,9 @@ def test_other_thread_Py_Exit(self): if not stackless.enable_softswitch(None): args.append("--hard") - rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import\nif 1: + rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent(""" + from __future__ import print_function, absolute_import + import stackless import sys import ctypes @@ -372,7 +385,7 @@ def exit(): print("OOPS, must not be reached") sys.stdout.flush() sys.exit(43) - """] + args) + """)] + args) self.assertEqual(rc, 42) @unittest.skipUnless(withThreads, "requires thread support") @@ -383,7 +396,9 @@ def test_kill_modifies_slp_cstack_chain(self): if not stackless.enable_softswitch(None): args.append("--hard") - rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", """from __future__ import print_function, absolute_import, division\nif 1: + rc = subprocess.call([sys.executable, "-s", "-S", "-E", "-c", dedent(""" + from __future__ import print_function, absolute_import, division + import threading import stackless import time @@ -447,7 +462,7 @@ def other_thread(): event.wait(5.0) print("end") sys.exit(42) - """] + args) + """)] + args) self.assertEqual(rc, 42)