diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2023-10-18 11:36:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-18 11:36:43 -0700 |
commit | e6eb8cafca441046b5f9ded27c68d9a84c42022a (patch) | |
tree | f0bc7f0c17f8e0a2e52b8fd3ba83c78a7d11a606 /Lib/test/test_code_module.py | |
parent | cb1bf89c4066f30c80f7d1193b586a2ff8c40579 (diff) | |
download | cpython-e6eb8cafca441046b5f9ded27c68d9a84c42022a.tar.gz cpython-e6eb8cafca441046b5f9ded27c68d9a84c42022a.zip |
GH-102895 Add an option local_exit in code.interact to block exit() from terminating the whole process (GH-102896)
Diffstat (limited to 'Lib/test/test_code_module.py')
-rw-r--r-- | Lib/test/test_code_module.py | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/Lib/test/test_code_module.py b/Lib/test/test_code_module.py index 226bc3a853b..747c0f9683c 100644 --- a/Lib/test/test_code_module.py +++ b/Lib/test/test_code_module.py @@ -10,11 +10,7 @@ from test.support import import_helper code = import_helper.import_module('code') -class TestInteractiveConsole(unittest.TestCase): - - def setUp(self): - self.console = code.InteractiveConsole() - self.mock_sys() +class MockSys: def mock_sys(self): "Mock system environment for InteractiveConsole" @@ -32,6 +28,13 @@ class TestInteractiveConsole(unittest.TestCase): del self.sysmod.ps1 del self.sysmod.ps2 + +class TestInteractiveConsole(unittest.TestCase, MockSys): + + def setUp(self): + self.console = code.InteractiveConsole() + self.mock_sys() + def test_ps1(self): self.infunc.side_effect = EOFError('Finished') self.console.interact() @@ -151,5 +154,21 @@ class TestInteractiveConsole(unittest.TestCase): self.assertIn(expected, output) +class TestInteractiveConsoleLocalExit(unittest.TestCase, MockSys): + + def setUp(self): + self.console = code.InteractiveConsole(local_exit=True) + self.mock_sys() + + def test_exit(self): + # default exit message + self.infunc.side_effect = ["exit()"] + self.console.interact(banner='') + self.assertEqual(len(self.stderr.method_calls), 2) + err_msg = self.stderr.method_calls[1] + expected = 'now exiting InteractiveConsole...\n' + self.assertEqual(err_msg, ['write', (expected,), {}]) + + if __name__ == "__main__": unittest.main() |