summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test
diff options
context:
space:
mode:
authorTal Einat <taleinat+github@gmail.com>2019-07-06 12:35:24 (GMT)
committerGitHub <noreply@github.com>2019-07-06 12:35:24 (GMT)
commitfcf1d003bf4f0100c9d0921ff3d70e1127ca1b71 (patch)
tree77d6f9323162ee6455a14da9c4f9bb78640284ae /Lib/idlelib/idle_test
parent45bc61b97178b27ae05bd3eb95481bf0325795bb (diff)
downloadcpython-fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71.zip
cpython-fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71.tar.gz
cpython-fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71.tar.bz2
bpo-26806: add 30 to the recursion limit in IDLE's shell (GH-13944)
This is done to compensate for the extra stack frames added by IDLE itself, which cause problems when setting the recursion limit to low values. This wraps sys.setrecursionlimit() and sys.getrecursionlimit() as invisibly as possible.
Diffstat (limited to 'Lib/idlelib/idle_test')
-rw-r--r--Lib/idlelib/idle_test/test_run.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/idlelib/idle_test/test_run.py b/Lib/idlelib/idle_test/test_run.py
index 46f0235..d0f1e92 100644
--- a/Lib/idlelib/idle_test/test_run.py
+++ b/Lib/idlelib/idle_test/test_run.py
@@ -6,6 +6,8 @@ from unittest import mock
from test.support import captured_stderr
import io
+import sys
+
class RunTest(unittest.TestCase):
@@ -260,5 +262,36 @@ class PseudeOutputFilesTest(unittest.TestCase):
self.assertRaises(TypeError, f.close, 1)
+class TestSysRecursionLimitWrappers(unittest.TestCase):
+
+ def test_bad_setrecursionlimit_calls(self):
+ run.install_recursionlimit_wrappers()
+ self.addCleanup(run.uninstall_recursionlimit_wrappers)
+ f = sys.setrecursionlimit
+ self.assertRaises(TypeError, f, limit=100)
+ self.assertRaises(TypeError, f, 100, 1000)
+ self.assertRaises(ValueError, f, 0)
+
+ def test_roundtrip(self):
+ run.install_recursionlimit_wrappers()
+ self.addCleanup(run.uninstall_recursionlimit_wrappers)
+
+ # check that setting the recursion limit works
+ orig_reclimit = sys.getrecursionlimit()
+ self.addCleanup(sys.setrecursionlimit, orig_reclimit)
+ sys.setrecursionlimit(orig_reclimit + 3)
+
+ # check that the new limit is returned by sys.getrecursionlimit()
+ new_reclimit = sys.getrecursionlimit()
+ self.assertEqual(new_reclimit, orig_reclimit + 3)
+
+ def test_default_recursion_limit_preserved(self):
+ orig_reclimit = sys.getrecursionlimit()
+ run.install_recursionlimit_wrappers()
+ self.addCleanup(run.uninstall_recursionlimit_wrappers)
+ new_reclimit = sys.getrecursionlimit()
+ self.assertEqual(new_reclimit, orig_reclimit)
+
+
if __name__ == '__main__':
unittest.main(verbosity=2)