[Python-checkins] cpython (merge 3.6 -> default): Merge 3.6 (test os.spawn*)

victor.stinner python-checkins at python.org
Wed Sep 14 08:57:54 EDT 2016


https://hg.python.org/cpython/rev/c29787dff0c7
changeset:   103797:c29787dff0c7
parent:      103795:55fa8e38a5f0
parent:      103796:0ca42273c714
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Sep 14 14:57:25 2016 +0200
summary:
  Merge 3.6 (test os.spawn*)

files:
  Lib/test/test_os.py |  86 +++++++++++++++++++++++++++++++++
  1 files changed, 86 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1413,6 +1413,7 @@
         os.execve = orig_execve
         os.defpath = orig_defpath
 
+
 class ExecTests(unittest.TestCase):
     @unittest.skipIf(USING_LINUXTHREADS,
                      "avoid triggering a linuxthreads bug: see issue #4970")
@@ -2163,6 +2164,91 @@
         self.assertEqual(status, (pid, 0))
 
 
+class SpawnTests(unittest.TestCase):
+    def create_args(self, with_env=False):
+        self.exitcode = 17
+
+        filename = support.TESTFN
+        self.addCleanup(support.unlink, filename)
+
+        if not with_env:
+            code = 'import sys; sys.exit(%s)' % self.exitcode
+        else:
+            self.env = dict(os.environ)
+            # create an unique key
+            self.key = str(uuid.uuid4())
+            self.env[self.key] = self.key
+            # read the variable from os.environ to check that it exists
+            code = ('import sys, os; magic = os.environ[%r]; sys.exit(%s)'
+                    % (self.key, self.exitcode))
+
+        with open(filename, "w") as fp:
+            fp.write(code)
+
+        return [sys.executable, filename]
+
+    @unittest.skipUnless(hasattr(os, 'spawnl'), 'need os.spawnl')
+    def test_spawnl(self):
+        args = self.create_args()
+        exitcode = os.spawnl(os.P_WAIT, args[0], *args)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnle'), 'need os.spawnle')
+    def test_spawnle(self):
+        args = self.create_args(True)
+        exitcode = os.spawnle(os.P_WAIT, args[0], *args, self.env)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnlp'), 'need os.spawnlp')
+    def test_spawnlp(self):
+        args = self.create_args()
+        exitcode = os.spawnlp(os.P_WAIT, args[0], *args)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnlpe'), 'need os.spawnlpe')
+    def test_spawnlpe(self):
+        args = self.create_args(True)
+        exitcode = os.spawnlpe(os.P_WAIT, args[0], *args, self.env)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnv'), 'need os.spawnv')
+    def test_spawnv(self):
+        args = self.create_args()
+        exitcode = os.spawnv(os.P_WAIT, args[0], args)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnve'), 'need os.spawnve')
+    def test_spawnve(self):
+        args = self.create_args(True)
+        exitcode = os.spawnve(os.P_WAIT, args[0], args, self.env)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnvp'), 'need os.spawnvp')
+    def test_spawnvp(self):
+        args = self.create_args()
+        exitcode = os.spawnvp(os.P_WAIT, args[0], args)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnvpe'), 'need os.spawnvpe')
+    def test_spawnvpe(self):
+        args = self.create_args(True)
+        exitcode = os.spawnvpe(os.P_WAIT, args[0], args, self.env)
+        self.assertEqual(exitcode, self.exitcode)
+
+    @unittest.skipUnless(hasattr(os, 'spawnv'), 'need os.spawnv')
+    def test_nowait(self):
+        args = self.create_args()
+        pid = os.spawnv(os.P_NOWAIT, args[0], args)
+        result = os.waitpid(pid, 0)
+        self.assertEqual(result[0], pid)
+        status = result[1]
+        if hasattr(os, 'WIFEXITED'):
+            self.assertTrue(os.WIFEXITED(status))
+            self.assertEqual(os.WEXITSTATUS(status), self.exitcode)
+        else:
+            self.assertEqual(status, self.exitcode << 8)
+
+
 # The introduction of this TestCase caused at least two different errors on
 # *nix buildbots. Temporarily skip this to let the buildbots move along.
 @unittest.skip("Skip due to platform/environment differences on *NIX buildbots")

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list