mirror of
https://github.com/python/cpython.git
synced 2025-11-09 10:01:42 +00:00
[3.13] gh-133054: Skip test_pyrepl tests when cannot use pyrepl is reported (GH-133055) (#133095)
(cherry picked from commit b739ec5ab7)
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
This commit is contained in:
parent
507b4fa7a4
commit
ab89f6ec84
1 changed files with 14 additions and 20 deletions
|
|
@ -43,6 +43,7 @@ def run_repl(
|
||||||
*,
|
*,
|
||||||
cmdline_args: list[str] | None = None,
|
cmdline_args: list[str] | None = None,
|
||||||
cwd: str | None = None,
|
cwd: str | None = None,
|
||||||
|
skip: bool = False,
|
||||||
) -> tuple[str, int]:
|
) -> tuple[str, int]:
|
||||||
temp_dir = None
|
temp_dir = None
|
||||||
if cwd is None:
|
if cwd is None:
|
||||||
|
|
@ -50,7 +51,7 @@ def run_repl(
|
||||||
cwd = temp_dir.name
|
cwd = temp_dir.name
|
||||||
try:
|
try:
|
||||||
return self._run_repl(
|
return self._run_repl(
|
||||||
repl_input, env=env, cmdline_args=cmdline_args, cwd=cwd
|
repl_input, env=env, cmdline_args=cmdline_args, cwd=cwd, skip=skip,
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
if temp_dir is not None:
|
if temp_dir is not None:
|
||||||
|
|
@ -63,6 +64,7 @@ def _run_repl(
|
||||||
env: dict | None,
|
env: dict | None,
|
||||||
cmdline_args: list[str] | None,
|
cmdline_args: list[str] | None,
|
||||||
cwd: str,
|
cwd: str,
|
||||||
|
skip: bool,
|
||||||
) -> tuple[str, int]:
|
) -> tuple[str, int]:
|
||||||
assert pty
|
assert pty
|
||||||
master_fd, slave_fd = pty.openpty()
|
master_fd, slave_fd = pty.openpty()
|
||||||
|
|
@ -119,7 +121,10 @@ def _run_repl(
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
process.kill()
|
process.kill()
|
||||||
exit_code = process.wait()
|
exit_code = process.wait()
|
||||||
return "".join(output), exit_code
|
output = "".join(output)
|
||||||
|
if skip and "can't use pyrepl" in output:
|
||||||
|
self.skipTest("pyrepl not available")
|
||||||
|
return output, exit_code
|
||||||
|
|
||||||
|
|
||||||
class TestCursorPosition(TestCase):
|
class TestCursorPosition(TestCase):
|
||||||
|
|
@ -1082,9 +1087,7 @@ def setUp(self):
|
||||||
def test_exposed_globals_in_repl(self):
|
def test_exposed_globals_in_repl(self):
|
||||||
pre = "['__annotations__', '__builtins__'"
|
pre = "['__annotations__', '__builtins__'"
|
||||||
post = "'__loader__', '__name__', '__package__', '__spec__']"
|
post = "'__loader__', '__name__', '__package__', '__spec__']"
|
||||||
output, exit_code = self.run_repl(["sorted(dir())", "exit()"])
|
output, exit_code = self.run_repl(["sorted(dir())", "exit()"], skip=True)
|
||||||
if "can't use pyrepl" in output:
|
|
||||||
self.skipTest("pyrepl not available")
|
|
||||||
self.assertEqual(exit_code, 0)
|
self.assertEqual(exit_code, 0)
|
||||||
|
|
||||||
# if `__main__` is not a file (impossible with pyrepl)
|
# if `__main__` is not a file (impossible with pyrepl)
|
||||||
|
|
@ -1136,6 +1139,7 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
|
||||||
commands,
|
commands,
|
||||||
cmdline_args=[str(mod)],
|
cmdline_args=[str(mod)],
|
||||||
env=clean_env,
|
env=clean_env,
|
||||||
|
skip=True,
|
||||||
)
|
)
|
||||||
elif as_module:
|
elif as_module:
|
||||||
output, exit_code = self.run_repl(
|
output, exit_code = self.run_repl(
|
||||||
|
|
@ -1143,13 +1147,11 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
|
||||||
cmdline_args=["-m", "blue.calx"],
|
cmdline_args=["-m", "blue.calx"],
|
||||||
env=clean_env,
|
env=clean_env,
|
||||||
cwd=td,
|
cwd=td,
|
||||||
|
skip=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.fail("Choose one of as_file or as_module")
|
self.fail("Choose one of as_file or as_module")
|
||||||
|
|
||||||
if "can't use pyrepl" in output:
|
|
||||||
self.skipTest("pyrepl not available")
|
|
||||||
|
|
||||||
self.assertEqual(exit_code, 0)
|
self.assertEqual(exit_code, 0)
|
||||||
for var, expected in expectations.items():
|
for var, expected in expectations.items():
|
||||||
with self.subTest(var=var, expected=expected):
|
with self.subTest(var=var, expected=expected):
|
||||||
|
|
@ -1187,9 +1189,7 @@ def test_python_basic_repl(self):
|
||||||
"exit()\n")
|
"exit()\n")
|
||||||
|
|
||||||
env.pop("PYTHON_BASIC_REPL", None)
|
env.pop("PYTHON_BASIC_REPL", None)
|
||||||
output, exit_code = self.run_repl(commands, env=env)
|
output, exit_code = self.run_repl(commands, env=env, skip=True)
|
||||||
if "can\'t use pyrepl" in output:
|
|
||||||
self.skipTest("pyrepl not available")
|
|
||||||
self.assertEqual(exit_code, 0)
|
self.assertEqual(exit_code, 0)
|
||||||
self.assertIn("True", output)
|
self.assertIn("True", output)
|
||||||
self.assertNotIn("False", output)
|
self.assertNotIn("False", output)
|
||||||
|
|
@ -1256,9 +1256,7 @@ def check(output, exitcode):
|
||||||
self.assertIn("division by zero", output)
|
self.assertIn("division by zero", output)
|
||||||
self.assertEqual(exitcode, 0)
|
self.assertEqual(exitcode, 0)
|
||||||
env.pop("PYTHON_BASIC_REPL", None)
|
env.pop("PYTHON_BASIC_REPL", None)
|
||||||
output, exit_code = self.run_repl(commands, env=env)
|
output, exit_code = self.run_repl(commands, env=env, skip=True)
|
||||||
if "can\'t use pyrepl" in output:
|
|
||||||
self.skipTest("pyrepl not available")
|
|
||||||
check(output, exit_code)
|
check(output, exit_code)
|
||||||
|
|
||||||
env["PYTHON_BASIC_REPL"] = "1"
|
env["PYTHON_BASIC_REPL"] = "1"
|
||||||
|
|
@ -1296,9 +1294,7 @@ def test_not_wiping_history_file(self):
|
||||||
def test_correct_filename_in_syntaxerrors(self):
|
def test_correct_filename_in_syntaxerrors(self):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
commands = "a b c\nexit()\n"
|
commands = "a b c\nexit()\n"
|
||||||
output, exit_code = self.run_repl(commands, env=env)
|
output, exit_code = self.run_repl(commands, env=env, skip=True)
|
||||||
if "can't use pyrepl" in output:
|
|
||||||
self.skipTest("pyrepl not available")
|
|
||||||
self.assertIn("SyntaxError: invalid syntax", output)
|
self.assertIn("SyntaxError: invalid syntax", output)
|
||||||
self.assertIn("<python-input-0>", output)
|
self.assertIn("<python-input-0>", output)
|
||||||
commands = " b\nexit()\n"
|
commands = " b\nexit()\n"
|
||||||
|
|
@ -1325,9 +1321,7 @@ def test_proper_tracebacklimit(self):
|
||||||
env.pop("PYTHON_BASIC_REPL", None)
|
env.pop("PYTHON_BASIC_REPL", None)
|
||||||
with self.subTest(set_tracebacklimit=set_tracebacklimit,
|
with self.subTest(set_tracebacklimit=set_tracebacklimit,
|
||||||
basic_repl=basic_repl):
|
basic_repl=basic_repl):
|
||||||
output, exit_code = self.run_repl(commands, env=env)
|
output, exit_code = self.run_repl(commands, env=env, skip=True)
|
||||||
if "can't use pyrepl" in output:
|
|
||||||
self.skipTest("pyrepl not available")
|
|
||||||
self.assertIn("in x1", output)
|
self.assertIn("in x1", output)
|
||||||
if set_tracebacklimit:
|
if set_tracebacklimit:
|
||||||
self.assertNotIn("in x2", output)
|
self.assertNotIn("in x2", output)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue