mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
[3.13] gh-118908: Use __main__ for the default PyREPL namespace (GH-121054) (#121059)
This commit is contained in:
parent
64c4139f61
commit
38cfa92880
4 changed files with 75 additions and 67 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue