aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_pyrepl/test_pyrepl.py
diff options
context:
space:
mode:
authorƁukasz Langa <lukasz@langa.pl>2024-06-26 15:01:10 -0400
committerGitHub <noreply@github.com>2024-06-26 15:01:10 -0400
commitd611c4c8e9893c0816969e19ab6ca4992a3a15e3 (patch)
tree8fb08a5af46f8bb2ca83c91d4b4a20f8ca896c07 /Lib/test/test_pyrepl/test_pyrepl.py
parente51e880e75d79687b54a71351266e29ee349b4b8 (diff)
downloadcpython-d611c4c8e9893c0816969e19ab6ca4992a3a15e3.tar.gz
cpython-d611c4c8e9893c0816969e19ab6ca4992a3a15e3.zip
gh-118908: Use __main__ for the default PyREPL namespace (#121054)
Diffstat (limited to 'Lib/test/test_pyrepl/test_pyrepl.py')
-rw-r--r--Lib/test/test_pyrepl/test_pyrepl.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index 21a570d271d..b189d3291e8 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -843,15 +843,26 @@ class TestPasteEvent(TestCase):
class TestMain(TestCase):
@force_not_colorized
def test_exposed_globals_in_repl(self):
- expected_output = (
- "[\'__annotations__\', \'__builtins__\', \'__doc__\', \'__loader__\', "
- "\'__name__\', \'__package__\', \'__spec__\']"
- )
+ pre = "['__annotations__', '__builtins__'"
+ post = "'__loader__', '__name__', '__package__', '__spec__']"
output, exit_code = self.run_repl(["sorted(dir())", "exit"])
- if "can\'t use pyrepl" in output:
+ if "can't use pyrepl" in output:
self.skipTest("pyrepl not available")
self.assertEqual(exit_code, 0)
- self.assertIn(expected_output, output)
+
+ # if `__main__` is not a file (impossible with pyrepl)
+ case1 = f"{pre}, '__doc__', {post}" in output
+
+ # if `__main__` is an uncached .py file (no .pyc)
+ case2 = f"{pre}, '__doc__', '__file__', {post}" in output
+
+ # if `__main__` is a cached .pyc file and the .py source exists
+ case3 = f"{pre}, '__cached__', '__doc__', '__file__', {post}" in output
+
+ # if `__main__` is a cached .pyc file but there's no .py source file
+ case4 = f"{pre}, '__cached__', '__doc__', {post}" in output
+
+ self.assertTrue(case1 or case2 or case3 or case4, output)
def test_dumb_terminal_exits_cleanly(self):
env = os.environ.copy()