mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-32667: Fix tests when $PATH contains a file (#5322)
Some tests failed when the PATH environment variable contained a path to an existing file. Fix tests to ignore also NotADirectoryError, not only FileNotFoundError and PermissionError.
This commit is contained in:
parent
93a6119f08
commit
b31206a223
2 changed files with 8 additions and 9 deletions
|
@ -79,7 +79,7 @@ class TraceBackend:
|
||||||
try:
|
try:
|
||||||
output = self.trace(abspath("assert_usable" + self.EXTENSION))
|
output = self.trace(abspath("assert_usable" + self.EXTENSION))
|
||||||
output = output.strip()
|
output = output.strip()
|
||||||
except (FileNotFoundError, PermissionError) as fnfe:
|
except (FileNotFoundError, NotADirectoryError, PermissionError) as fnfe:
|
||||||
output = str(fnfe)
|
output = str(fnfe)
|
||||||
if output != "probe: success":
|
if output != "probe: success":
|
||||||
raise unittest.SkipTest(
|
raise unittest.SkipTest(
|
||||||
|
|
|
@ -46,6 +46,8 @@ else:
|
||||||
SETBINARY = ''
|
SETBINARY = ''
|
||||||
|
|
||||||
NONEXISTING_CMD = ('nonexisting_i_hope',)
|
NONEXISTING_CMD = ('nonexisting_i_hope',)
|
||||||
|
# Ignore errors that indicate the command was not found
|
||||||
|
NONEXISTING_ERRORS = (FileNotFoundError, NotADirectoryError, PermissionError)
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(unittest.TestCase):
|
class BaseTestCase(unittest.TestCase):
|
||||||
|
@ -306,9 +308,9 @@ class ProcessTestCase(BaseTestCase):
|
||||||
# Verify first that the call succeeds without the executable arg.
|
# Verify first that the call succeeds without the executable arg.
|
||||||
pre_args = [sys.executable, "-c"]
|
pre_args = [sys.executable, "-c"]
|
||||||
self._assert_python(pre_args)
|
self._assert_python(pre_args)
|
||||||
self.assertRaises((FileNotFoundError, PermissionError),
|
self.assertRaises(NONEXISTING_ERRORS,
|
||||||
self._assert_python, pre_args,
|
self._assert_python, pre_args,
|
||||||
executable="doesnotexist")
|
executable=NONEXISTING_CMD[0])
|
||||||
|
|
||||||
@unittest.skipIf(mswindows, "executable argument replaces shell")
|
@unittest.skipIf(mswindows, "executable argument replaces shell")
|
||||||
def test_executable_replaces_shell(self):
|
def test_executable_replaces_shell(self):
|
||||||
|
@ -1146,13 +1148,10 @@ class ProcessTestCase(BaseTestCase):
|
||||||
# value for that limit, but Windows has 2048, so we loop
|
# value for that limit, but Windows has 2048, so we loop
|
||||||
# 1024 times (each call leaked two fds).
|
# 1024 times (each call leaked two fds).
|
||||||
for i in range(1024):
|
for i in range(1024):
|
||||||
with self.assertRaises(OSError) as c:
|
with self.assertRaises(NONEXISTING_ERRORS):
|
||||||
subprocess.Popen(NONEXISTING_CMD,
|
subprocess.Popen(NONEXISTING_CMD,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
# ignore errors that indicate the command was not found
|
|
||||||
if c.exception.errno not in (errno.ENOENT, errno.EACCES):
|
|
||||||
raise c.exception
|
|
||||||
|
|
||||||
def test_nonexisting_with_pipes(self):
|
def test_nonexisting_with_pipes(self):
|
||||||
# bpo-30121: Popen with pipes must close properly pipes on error.
|
# bpo-30121: Popen with pipes must close properly pipes on error.
|
||||||
|
@ -2533,7 +2532,7 @@ class POSIXProcessTestCase(BaseTestCase):
|
||||||
# let some time for the process to exit, and create a new Popen: this
|
# let some time for the process to exit, and create a new Popen: this
|
||||||
# should trigger the wait() of p
|
# should trigger the wait() of p
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
with self.assertRaises(OSError) as c:
|
with self.assertRaises(OSError):
|
||||||
with subprocess.Popen(NONEXISTING_CMD,
|
with subprocess.Popen(NONEXISTING_CMD,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE) as proc:
|
stderr=subprocess.PIPE) as proc:
|
||||||
|
@ -3044,7 +3043,7 @@ class ContextManagerTests(BaseTestCase):
|
||||||
self.assertEqual(proc.returncode, 1)
|
self.assertEqual(proc.returncode, 1)
|
||||||
|
|
||||||
def test_invalid_args(self):
|
def test_invalid_args(self):
|
||||||
with self.assertRaises((FileNotFoundError, PermissionError)) as c:
|
with self.assertRaises(NONEXISTING_ERRORS):
|
||||||
with subprocess.Popen(NONEXISTING_CMD,
|
with subprocess.Popen(NONEXISTING_CMD,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE) as proc:
|
stderr=subprocess.PIPE) as proc:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue