summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordevdanzin <74280297+devdanzin@users.noreply.github.com>2024-06-26 21:17:14 (GMT)
committerGitHub <noreply@github.com>2024-06-26 21:17:14 (GMT)
commitbc515b332bef0eaa3064d3b912ad660932ad8c90 (patch)
treec16c31d4ddc39a88c56be0f3bdcfe2a86c663cf1
parentd7cd71c72a9ad0abcc89deed50762ac7ceaef6d4 (diff)
downloadcpython-bc515b332bef0eaa3064d3b912ad660932ad8c90.zip
cpython-bc515b332bef0eaa3064d3b912ad660932ad8c90.tar.gz
cpython-bc515b332bef0eaa3064d3b912ad660932ad8c90.tar.bz2
[3.13] gh-121016: Add test for PYTHON_BASIC_REPL envioronment variable (GH-121017) (#121064)
* gh-121016: Add test for `PYTHON_BASIC_REPL` envioronment variable (#121017) (cherry picked from commit 9e45fd9858a059950f7387b4fda2b00df0e8e537) * [3.13] gh-121016: Add test for `PYTHON_BASIC_REPL` envioronment variable (GH-121017) (cherry picked from commit 9e45fd9858a059950f7387b4fda2b00df0e8e537) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
-rw-r--r--Lib/test/support/__init__.py6
-rw-r--r--Lib/test/test_pyrepl/test_pyrepl.py25
2 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index e90ef3d..81cd7f1 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -2607,3 +2607,9 @@ def force_not_colorized(func):
if value is not None:
os.environ[key] = value
return wrapper
+
+
+def initialized_with_pyrepl():
+ """Detect whether PyREPL was used during Python initialization."""
+ # If the main module has a __file__ attribute it's a Python module, which means PyREPL.
+ return hasattr(sys.modules["__main__"], "__file__")
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index bf8753f..b189d32 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -873,6 +873,31 @@ class TestMain(TestCase):
self.assertNotIn("Exception", output)
self.assertNotIn("Traceback", output)
+ @force_not_colorized
+ def test_python_basic_repl(self):
+ env = os.environ.copy()
+ commands = ("from test.support import initialized_with_pyrepl\n"
+ "initialized_with_pyrepl()\n"
+ "exit()\n")
+
+ env.pop("PYTHON_BASIC_REPL", None)
+ output, exit_code = self.run_repl(commands, env=env)
+ if "can\'t use pyrepl" in output:
+ self.skipTest("pyrepl not available")
+ self.assertEqual(exit_code, 0)
+ self.assertIn("True", output)
+ self.assertNotIn("False", output)
+ self.assertNotIn("Exception", output)
+ self.assertNotIn("Traceback", output)
+
+ env["PYTHON_BASIC_REPL"] = "1"
+ output, exit_code = self.run_repl(commands, env=env)
+ self.assertEqual(exit_code, 0)
+ self.assertIn("False", output)
+ self.assertNotIn("True", output)
+ self.assertNotIn("Exception", output)
+ self.assertNotIn("Traceback", output)
+
def run_repl(self, repl_input: str | list[str], env: dict | None = None) -> tuple[str, int]:
master_fd, slave_fd = pty.openpty()
process = subprocess.Popen(