diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-06-26 19:25:38 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-26 19:25:38 (GMT) |
| commit | 38cfa92880a19d03a4ada4cd843870a8602c13a0 (patch) | |
| tree | df306f3b7cfa72710e6b8ffe0fa523322ca99516 /Lib/test/test_pyrepl/test_pyrepl.py | |
| parent | 64c4139f61517cb8845b42fce0a1dad0e6ebbd9a (diff) | |
| download | cpython-38cfa92880a19d03a4ada4cd843870a8602c13a0.zip cpython-38cfa92880a19d03a4ada4cd843870a8602c13a0.tar.gz cpython-38cfa92880a19d03a4ada4cd843870a8602c13a0.tar.bz2 | |
[3.13] gh-118908: Use __main__ for the default PyREPL namespace (GH-121054) (#121059)
Diffstat (limited to 'Lib/test/test_pyrepl/test_pyrepl.py')
| -rw-r--r-- | Lib/test/test_pyrepl/test_pyrepl.py | 23 |
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 adc55f2..bf8753f 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() |
