Skip to content

Commit

Permalink
Merge 3.6 (test os.spawn*)
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Sep 14, 2016
2 parents 03270f3 + 2aa2efa commit 3c06edf
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ def mock_execve(name, *args):
os.execve = orig_execve
os.defpath = orig_defpath


class ExecTests(unittest.TestCase):
@unittest.skipIf(USING_LINUXTHREADS,
"avoid triggering a linuxthreads bug: see issue #4970")
Expand Down Expand Up @@ -2163,6 +2164,91 @@ def test_waitpid(self):
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")
Expand Down

0 comments on commit 3c06edf

Please sign in to comment.