Merged revisions 70912,70944,70968,71033,71041,71208,71263,71286,71395-71396,71405-71406,71485,71492,71494 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70912 | georg.brandl | 2009-03-31 17:35:46 -0500 (Tue, 31 Mar 2009) | 1 line
#5617: add a handy function to print a unicode string to gdbinit.
........
r70944 | georg.brandl | 2009-03-31 23:32:39 -0500 (Tue, 31 Mar 2009) | 1 line
#5631: add upload to list of possible commands, which is presented in --help-commands.
........
r70968 | michael.foord | 2009-04-01 13:25:38 -0500 (Wed, 01 Apr 2009) | 1 line
Adding Wing project file
........
r71033 | brett.cannon | 2009-04-01 22:34:53 -0500 (Wed, 01 Apr 2009) | 3 lines
Fix two issues introduced by issue #71031 by changing the signature of
PyImport_AppendInittab() to take a const char *.
........
r71041 | jesse.noller | 2009-04-02 00:17:26 -0500 (Thu, 02 Apr 2009) | 1 line
Add custom initializer argument to multiprocess.Manager*, courtesy of lekma
........
r71208 | michael.foord | 2009-04-04 20:15:01 -0500 (Sat, 04 Apr 2009) | 4 lines
Change the way unittest.TestSuite use their tests to always access them through iteration. Non behavior changing, this allows you to create custom subclasses that override __iter__.
Issue #5693
........
r71263 | michael.foord | 2009-04-05 14:19:28 -0500 (Sun, 05 Apr 2009) | 4 lines
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
........
r71286 | tarek.ziade | 2009-04-05 17:04:38 -0500 (Sun, 05 Apr 2009) | 1 line
added a simplest test to distutils.spawn._nt_quote_args
........
r71395 | benjamin.peterson | 2009-04-08 08:27:29 -0500 (Wed, 08 Apr 2009) | 1 line
these must be installed to correctly run tests
........
r71396 | benjamin.peterson | 2009-04-08 08:29:41 -0500 (Wed, 08 Apr 2009) | 1 line
fix syntax
........
r71405 | andrew.kuchling | 2009-04-09 06:22:47 -0500 (Thu, 09 Apr 2009) | 1 line
Add items
........
r71406 | andrew.kuchling | 2009-04-09 06:23:36 -0500 (Thu, 09 Apr 2009) | 1 line
Typo fixes
........
r71485 | andrew.kuchling | 2009-04-11 11:12:23 -0500 (Sat, 11 Apr 2009) | 1 line
Add various items
........
r71492 | georg.brandl | 2009-04-11 13:19:27 -0500 (Sat, 11 Apr 2009) | 1 line
Take credit for a patch of mine.
........
r71494 | benjamin.peterson | 2009-04-11 14:31:00 -0500 (Sat, 11 Apr 2009) | 1 line
ignore py3_test_grammar when compiling the library
........
2009-04-11 17:45:40 -03:00
|
|
|
"""Tests for distutils.spawn."""
|
2009-06-02 13:18:55 -03:00
|
|
|
import os
|
2018-09-04 06:01:09 -03:00
|
|
|
import stat
|
|
|
|
import sys
|
2020-04-29 21:21:30 -03:00
|
|
|
import unittest.mock
|
2016-07-22 07:15:29 -03:00
|
|
|
from test.support import run_unittest, unix_shell
|
2020-07-06 09:29:49 -03:00
|
|
|
from test.support import os_helper
|
2009-06-02 13:18:55 -03:00
|
|
|
|
2018-09-04 06:01:09 -03:00
|
|
|
from distutils.spawn import find_executable
|
2016-04-24 15:41:02 -03:00
|
|
|
from distutils.spawn import spawn
|
2009-06-02 13:18:55 -03:00
|
|
|
from distutils.errors import DistutilsExecError
|
|
|
|
from distutils.tests import support
|
Merged revisions 70912,70944,70968,71033,71041,71208,71263,71286,71395-71396,71405-71406,71485,71492,71494 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70912 | georg.brandl | 2009-03-31 17:35:46 -0500 (Tue, 31 Mar 2009) | 1 line
#5617: add a handy function to print a unicode string to gdbinit.
........
r70944 | georg.brandl | 2009-03-31 23:32:39 -0500 (Tue, 31 Mar 2009) | 1 line
#5631: add upload to list of possible commands, which is presented in --help-commands.
........
r70968 | michael.foord | 2009-04-01 13:25:38 -0500 (Wed, 01 Apr 2009) | 1 line
Adding Wing project file
........
r71033 | brett.cannon | 2009-04-01 22:34:53 -0500 (Wed, 01 Apr 2009) | 3 lines
Fix two issues introduced by issue #71031 by changing the signature of
PyImport_AppendInittab() to take a const char *.
........
r71041 | jesse.noller | 2009-04-02 00:17:26 -0500 (Thu, 02 Apr 2009) | 1 line
Add custom initializer argument to multiprocess.Manager*, courtesy of lekma
........
r71208 | michael.foord | 2009-04-04 20:15:01 -0500 (Sat, 04 Apr 2009) | 4 lines
Change the way unittest.TestSuite use their tests to always access them through iteration. Non behavior changing, this allows you to create custom subclasses that override __iter__.
Issue #5693
........
r71263 | michael.foord | 2009-04-05 14:19:28 -0500 (Sun, 05 Apr 2009) | 4 lines
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
........
r71286 | tarek.ziade | 2009-04-05 17:04:38 -0500 (Sun, 05 Apr 2009) | 1 line
added a simplest test to distutils.spawn._nt_quote_args
........
r71395 | benjamin.peterson | 2009-04-08 08:27:29 -0500 (Wed, 08 Apr 2009) | 1 line
these must be installed to correctly run tests
........
r71396 | benjamin.peterson | 2009-04-08 08:29:41 -0500 (Wed, 08 Apr 2009) | 1 line
fix syntax
........
r71405 | andrew.kuchling | 2009-04-09 06:22:47 -0500 (Thu, 09 Apr 2009) | 1 line
Add items
........
r71406 | andrew.kuchling | 2009-04-09 06:23:36 -0500 (Thu, 09 Apr 2009) | 1 line
Typo fixes
........
r71485 | andrew.kuchling | 2009-04-11 11:12:23 -0500 (Sat, 11 Apr 2009) | 1 line
Add various items
........
r71492 | georg.brandl | 2009-04-11 13:19:27 -0500 (Sat, 11 Apr 2009) | 1 line
Take credit for a patch of mine.
........
r71494 | benjamin.peterson | 2009-04-11 14:31:00 -0500 (Sat, 11 Apr 2009) | 1 line
ignore py3_test_grammar when compiling the library
........
2009-04-11 17:45:40 -03:00
|
|
|
|
2009-06-02 13:18:55 -03:00
|
|
|
class SpawnTestCase(support.TempdirManager,
|
|
|
|
support.LoggingSilencer,
|
|
|
|
unittest.TestCase):
|
Merged revisions 70912,70944,70968,71033,71041,71208,71263,71286,71395-71396,71405-71406,71485,71492,71494 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70912 | georg.brandl | 2009-03-31 17:35:46 -0500 (Tue, 31 Mar 2009) | 1 line
#5617: add a handy function to print a unicode string to gdbinit.
........
r70944 | georg.brandl | 2009-03-31 23:32:39 -0500 (Tue, 31 Mar 2009) | 1 line
#5631: add upload to list of possible commands, which is presented in --help-commands.
........
r70968 | michael.foord | 2009-04-01 13:25:38 -0500 (Wed, 01 Apr 2009) | 1 line
Adding Wing project file
........
r71033 | brett.cannon | 2009-04-01 22:34:53 -0500 (Wed, 01 Apr 2009) | 3 lines
Fix two issues introduced by issue #71031 by changing the signature of
PyImport_AppendInittab() to take a const char *.
........
r71041 | jesse.noller | 2009-04-02 00:17:26 -0500 (Thu, 02 Apr 2009) | 1 line
Add custom initializer argument to multiprocess.Manager*, courtesy of lekma
........
r71208 | michael.foord | 2009-04-04 20:15:01 -0500 (Sat, 04 Apr 2009) | 4 lines
Change the way unittest.TestSuite use their tests to always access them through iteration. Non behavior changing, this allows you to create custom subclasses that override __iter__.
Issue #5693
........
r71263 | michael.foord | 2009-04-05 14:19:28 -0500 (Sun, 05 Apr 2009) | 4 lines
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
........
r71286 | tarek.ziade | 2009-04-05 17:04:38 -0500 (Sun, 05 Apr 2009) | 1 line
added a simplest test to distutils.spawn._nt_quote_args
........
r71395 | benjamin.peterson | 2009-04-08 08:27:29 -0500 (Wed, 08 Apr 2009) | 1 line
these must be installed to correctly run tests
........
r71396 | benjamin.peterson | 2009-04-08 08:29:41 -0500 (Wed, 08 Apr 2009) | 1 line
fix syntax
........
r71405 | andrew.kuchling | 2009-04-09 06:22:47 -0500 (Thu, 09 Apr 2009) | 1 line
Add items
........
r71406 | andrew.kuchling | 2009-04-09 06:23:36 -0500 (Thu, 09 Apr 2009) | 1 line
Typo fixes
........
r71485 | andrew.kuchling | 2009-04-11 11:12:23 -0500 (Sat, 11 Apr 2009) | 1 line
Add various items
........
r71492 | georg.brandl | 2009-04-11 13:19:27 -0500 (Sat, 11 Apr 2009) | 1 line
Take credit for a patch of mine.
........
r71494 | benjamin.peterson | 2009-04-11 14:31:00 -0500 (Sat, 11 Apr 2009) | 1 line
ignore py3_test_grammar when compiling the library
........
2009-04-11 17:45:40 -03:00
|
|
|
|
2009-06-02 13:18:55 -03:00
|
|
|
@unittest.skipUnless(os.name in ('nt', 'posix'),
|
|
|
|
'Runs only under posix or nt')
|
|
|
|
def test_spawn(self):
|
|
|
|
tmpdir = self.mkdtemp()
|
|
|
|
|
|
|
|
# creating something executable
|
|
|
|
# through the shell that returns 1
|
2016-07-22 07:15:29 -03:00
|
|
|
if sys.platform != 'win32':
|
2009-06-02 13:18:55 -03:00
|
|
|
exe = os.path.join(tmpdir, 'foo.sh')
|
2016-07-22 07:15:29 -03:00
|
|
|
self.write_file(exe, '#!%s\nexit 1' % unix_shell)
|
2009-06-02 13:18:55 -03:00
|
|
|
else:
|
|
|
|
exe = os.path.join(tmpdir, 'foo.bat')
|
|
|
|
self.write_file(exe, 'exit 1')
|
|
|
|
|
|
|
|
os.chmod(exe, 0o777)
|
|
|
|
self.assertRaises(DistutilsExecError, spawn, [exe])
|
|
|
|
|
|
|
|
# now something that works
|
2016-07-22 07:15:29 -03:00
|
|
|
if sys.platform != 'win32':
|
2009-06-02 13:18:55 -03:00
|
|
|
exe = os.path.join(tmpdir, 'foo.sh')
|
2016-07-22 07:15:29 -03:00
|
|
|
self.write_file(exe, '#!%s\nexit 0' % unix_shell)
|
2009-06-02 13:18:55 -03:00
|
|
|
else:
|
|
|
|
exe = os.path.join(tmpdir, 'foo.bat')
|
|
|
|
self.write_file(exe, 'exit 0')
|
|
|
|
|
|
|
|
os.chmod(exe, 0o777)
|
|
|
|
spawn([exe]) # should work without any error
|
|
|
|
|
2018-09-04 06:01:09 -03:00
|
|
|
def test_find_executable(self):
|
2020-07-06 09:29:49 -03:00
|
|
|
with os_helper.temp_dir() as tmp_dir:
|
2018-09-04 06:01:09 -03:00
|
|
|
# use TESTFN to get a pseudo-unique filename
|
2020-07-06 09:29:49 -03:00
|
|
|
program_noeext = os_helper.TESTFN
|
2018-09-04 06:01:09 -03:00
|
|
|
# Give the temporary program an ".exe" suffix for all.
|
|
|
|
# It's needed on Windows and not harmful on other platforms.
|
|
|
|
program = program_noeext + ".exe"
|
|
|
|
|
|
|
|
filename = os.path.join(tmp_dir, program)
|
|
|
|
with open(filename, "wb"):
|
|
|
|
pass
|
|
|
|
os.chmod(filename, stat.S_IXUSR)
|
|
|
|
|
|
|
|
# test path parameter
|
|
|
|
rv = find_executable(program, path=tmp_dir)
|
|
|
|
self.assertEqual(rv, filename)
|
|
|
|
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
# test without ".exe" extension
|
|
|
|
rv = find_executable(program_noeext, path=tmp_dir)
|
|
|
|
self.assertEqual(rv, filename)
|
|
|
|
|
|
|
|
# test find in the current directory
|
2020-07-06 09:29:49 -03:00
|
|
|
with os_helper.change_cwd(tmp_dir):
|
2018-09-04 06:01:09 -03:00
|
|
|
rv = find_executable(program)
|
|
|
|
self.assertEqual(rv, program)
|
|
|
|
|
|
|
|
# test non-existent program
|
|
|
|
dont_exist_program = "dontexist_" + program
|
|
|
|
rv = find_executable(dont_exist_program , path=tmp_dir)
|
|
|
|
self.assertIsNone(rv)
|
|
|
|
|
2019-04-17 11:26:36 -03:00
|
|
|
# PATH='': no match, except in the current directory
|
2020-07-06 09:29:49 -03:00
|
|
|
with os_helper.EnvironmentVarGuard() as env:
|
2019-04-17 11:26:36 -03:00
|
|
|
env['PATH'] = ''
|
|
|
|
with unittest.mock.patch('distutils.spawn.os.confstr',
|
|
|
|
return_value=tmp_dir, create=True), \
|
|
|
|
unittest.mock.patch('distutils.spawn.os.defpath',
|
|
|
|
tmp_dir):
|
|
|
|
rv = find_executable(program)
|
|
|
|
self.assertIsNone(rv)
|
|
|
|
|
|
|
|
# look in current directory
|
2020-07-06 09:29:49 -03:00
|
|
|
with os_helper.change_cwd(tmp_dir):
|
2019-04-17 11:26:36 -03:00
|
|
|
rv = find_executable(program)
|
|
|
|
self.assertEqual(rv, program)
|
|
|
|
|
|
|
|
# PATH=':': explicitly looks in the current directory
|
2020-07-06 09:29:49 -03:00
|
|
|
with os_helper.EnvironmentVarGuard() as env:
|
2019-04-17 11:26:36 -03:00
|
|
|
env['PATH'] = os.pathsep
|
|
|
|
with unittest.mock.patch('distutils.spawn.os.confstr',
|
|
|
|
return_value='', create=True), \
|
|
|
|
unittest.mock.patch('distutils.spawn.os.defpath', ''):
|
|
|
|
rv = find_executable(program)
|
|
|
|
self.assertIsNone(rv)
|
|
|
|
|
|
|
|
# look in current directory
|
2020-07-06 09:29:49 -03:00
|
|
|
with os_helper.change_cwd(tmp_dir):
|
2019-04-17 11:26:36 -03:00
|
|
|
rv = find_executable(program)
|
|
|
|
self.assertEqual(rv, program)
|
|
|
|
|
|
|
|
# missing PATH: test os.confstr("CS_PATH") and os.defpath
|
2020-07-06 09:29:49 -03:00
|
|
|
with os_helper.EnvironmentVarGuard() as env:
|
2019-04-17 11:26:36 -03:00
|
|
|
env.pop('PATH', None)
|
|
|
|
|
|
|
|
# without confstr
|
|
|
|
with unittest.mock.patch('distutils.spawn.os.confstr',
|
|
|
|
side_effect=ValueError,
|
|
|
|
create=True), \
|
|
|
|
unittest.mock.patch('distutils.spawn.os.defpath',
|
|
|
|
tmp_dir):
|
|
|
|
rv = find_executable(program)
|
|
|
|
self.assertEqual(rv, filename)
|
2018-09-04 06:01:09 -03:00
|
|
|
|
2019-04-17 11:26:36 -03:00
|
|
|
# with confstr
|
|
|
|
with unittest.mock.patch('distutils.spawn.os.confstr',
|
|
|
|
return_value=tmp_dir, create=True), \
|
|
|
|
unittest.mock.patch('distutils.spawn.os.defpath', ''):
|
2018-09-04 06:01:09 -03:00
|
|
|
rv = find_executable(program)
|
|
|
|
self.assertEqual(rv, filename)
|
|
|
|
|
2020-07-07 08:11:28 -03:00
|
|
|
def test_spawn_missing_exe(self):
|
|
|
|
with self.assertRaises(DistutilsExecError) as ctx:
|
|
|
|
spawn(['does-not-exist'])
|
|
|
|
self.assertIn("command 'does-not-exist' failed", str(ctx.exception))
|
|
|
|
|
2018-09-04 06:01:09 -03:00
|
|
|
|
Merged revisions 70912,70944,70968,71033,71041,71208,71263,71286,71395-71396,71405-71406,71485,71492,71494 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70912 | georg.brandl | 2009-03-31 17:35:46 -0500 (Tue, 31 Mar 2009) | 1 line
#5617: add a handy function to print a unicode string to gdbinit.
........
r70944 | georg.brandl | 2009-03-31 23:32:39 -0500 (Tue, 31 Mar 2009) | 1 line
#5631: add upload to list of possible commands, which is presented in --help-commands.
........
r70968 | michael.foord | 2009-04-01 13:25:38 -0500 (Wed, 01 Apr 2009) | 1 line
Adding Wing project file
........
r71033 | brett.cannon | 2009-04-01 22:34:53 -0500 (Wed, 01 Apr 2009) | 3 lines
Fix two issues introduced by issue #71031 by changing the signature of
PyImport_AppendInittab() to take a const char *.
........
r71041 | jesse.noller | 2009-04-02 00:17:26 -0500 (Thu, 02 Apr 2009) | 1 line
Add custom initializer argument to multiprocess.Manager*, courtesy of lekma
........
r71208 | michael.foord | 2009-04-04 20:15:01 -0500 (Sat, 04 Apr 2009) | 4 lines
Change the way unittest.TestSuite use their tests to always access them through iteration. Non behavior changing, this allows you to create custom subclasses that override __iter__.
Issue #5693
........
r71263 | michael.foord | 2009-04-05 14:19:28 -0500 (Sun, 05 Apr 2009) | 4 lines
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
........
r71286 | tarek.ziade | 2009-04-05 17:04:38 -0500 (Sun, 05 Apr 2009) | 1 line
added a simplest test to distutils.spawn._nt_quote_args
........
r71395 | benjamin.peterson | 2009-04-08 08:27:29 -0500 (Wed, 08 Apr 2009) | 1 line
these must be installed to correctly run tests
........
r71396 | benjamin.peterson | 2009-04-08 08:29:41 -0500 (Wed, 08 Apr 2009) | 1 line
fix syntax
........
r71405 | andrew.kuchling | 2009-04-09 06:22:47 -0500 (Thu, 09 Apr 2009) | 1 line
Add items
........
r71406 | andrew.kuchling | 2009-04-09 06:23:36 -0500 (Thu, 09 Apr 2009) | 1 line
Typo fixes
........
r71485 | andrew.kuchling | 2009-04-11 11:12:23 -0500 (Sat, 11 Apr 2009) | 1 line
Add various items
........
r71492 | georg.brandl | 2009-04-11 13:19:27 -0500 (Sat, 11 Apr 2009) | 1 line
Take credit for a patch of mine.
........
r71494 | benjamin.peterson | 2009-04-11 14:31:00 -0500 (Sat, 11 Apr 2009) | 1 line
ignore py3_test_grammar when compiling the library
........
2009-04-11 17:45:40 -03:00
|
|
|
def test_suite():
|
|
|
|
return unittest.makeSuite(SpawnTestCase)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2010-11-05 23:44:43 -03:00
|
|
|
run_unittest(test_suite())
|