summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sys.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-15 15:38:52 (GMT)
committerGitHub <noreply@github.com>2017-11-15 15:38:52 (GMT)
commitedad8eebeee3c99e324a7f1ac5073167c2b0b54d (patch)
tree51d1b1a41e635461c0f82cf8e754b2b8dd982b21 /Lib/test/test_sys.py
parent6545256df93ba54f811206107274cfa5a6d76b86 (diff)
downloadcpython-edad8eebeee3c99e324a7f1ac5073167c2b0b54d.zip
cpython-edad8eebeee3c99e324a7f1ac5073167c2b0b54d.tar.gz
cpython-edad8eebeee3c99e324a7f1ac5073167c2b0b54d.tar.bz2
bpo-31949: Fixed several issues in printing tracebacks (PyTraceBack_Print()). (#4289)
* Setting sys.tracebacklimit to 0 or less now suppresses printing tracebacks. * Setting sys.tracebacklimit to None now causes using the default limit. * Setting sys.tracebacklimit to an integer larger than LONG_MAX now means using the limit LONG_MAX rather than the default limit. * Fixed integer overflows in the case of more than 2**31 traceback items on Windows. * Fixed output errors handling.
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r--Lib/test/test_sys.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 50eb1b7..20965b9 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -808,6 +808,39 @@ class SysModuleTest(unittest.TestCase):
self.assertIsInstance(level, int)
self.assertGreater(level, 0)
+ def test_sys_tracebacklimit(self):
+ code = """if 1:
+ import sys
+ def f1():
+ 1 / 0
+ def f2():
+ f1()
+ sys.tracebacklimit = %r
+ f2()
+ """
+ def check(tracebacklimit, expected):
+ p = subprocess.Popen([sys.executable, '-c', code % tracebacklimit],
+ stderr=subprocess.PIPE)
+ out = p.communicate()[1]
+ self.assertEqual(out.splitlines(), expected)
+
+ traceback = [
+ b'Traceback (most recent call last):',
+ b' File "<string>", line 8, in <module>',
+ b' File "<string>", line 6, in f2',
+ b' File "<string>", line 4, in f1',
+ b'ZeroDivisionError: division by zero'
+ ]
+ check(10, traceback)
+ check(3, traceback)
+ check(2, traceback[:1] + traceback[2:])
+ check(1, traceback[:1] + traceback[3:])
+ check(0, [traceback[-1]])
+ check(-1, [traceback[-1]])
+ check(1<<1000, traceback)
+ check(-1<<1000, [traceback[-1]])
+ check(None, traceback)
+
@test.support.cpython_only
class SizeofTest(unittest.TestCase):