diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-31 22:56:02 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-07-31 22:56:02 (GMT) |
commit | e19cadb427b6910930b50584bd9066ab5b198300 (patch) | |
tree | 318d34b82b72e35bfcf4df07991ca22efa58c730 /Lib | |
parent | a986dfa927017d23c73c703ba848bd86b4424437 (diff) | |
download | cpython-e19cadb427b6910930b50584bd9066ab5b198300.zip cpython-e19cadb427b6910930b50584bd9066ab5b198300.tar.gz cpython-e19cadb427b6910930b50584bd9066ab5b198300.tar.bz2 |
Correct one of the "MemoryError oddities":
the traceback would grow each time a MemoryError is raised.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_exceptions.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 2b248e1..b742fce 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -596,6 +596,24 @@ class ExceptionTests(unittest.TestCase): "Exception ValueError: ValueError() " "in <class 'KeyError'> ignored\n") + + def test_MemoryError(self): + # PyErr_NoMemory always raises the same exception instance. + # Check that the traceback is not doubled. + import traceback + def raiseMemError(): + try: + "a" * (sys.maxsize // 2) + except MemoryError as e: + tb = e.__traceback__ + else: + self.fail("Should have raises a MemoryError") + return traceback.format_tb(tb) + + tb1 = raiseMemError() + tb2 = raiseMemError() + self.assertEqual(tb1, tb2) + def test_main(): run_unittest(ExceptionTests) |