summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2008-05-08 04:26:35 (GMT)
committerBarry Warsaw <barry@python.org>2008-05-08 04:26:35 (GMT)
commit8d109cb0436e76448b2a413833bc867d490f6cca (patch)
tree7ff951c058bec95c594c0aba1e672de710324dd6 /Lib/test
parent96de30ae1eba0fb126c8bef8b2fcfba1d5b34290 (diff)
downloadcpython-8d109cb0436e76448b2a413833bc867d490f6cca.zip
cpython-8d109cb0436e76448b2a413833bc867d490f6cca.tar.gz
cpython-8d109cb0436e76448b2a413833bc867d490f6cca.tar.bz2
Antoine Pitrou's patch for bug 2507; exception state lives too long in
3.0.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_exceptions.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index ae4687f..0574356 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -4,6 +4,7 @@ import os
import sys
import unittest
import pickle
+import weakref
from test.test_support import TESTFN, unlink, run_unittest
@@ -400,8 +401,9 @@ class ExceptionTests(unittest.TestCase):
self.failUnless(str(Exception('a')))
self.failUnless(str(Exception('a')))
- def testExceptionCleanup(self):
- # Make sure "except V as N" exceptions are cleaned up properly
+ def testExceptionCleanupNames(self):
+ # Make sure the local variable bound to the exception instance by
+ # an "except" statement is only visible inside the except block.
try:
raise Exception()
@@ -410,6 +412,31 @@ class ExceptionTests(unittest.TestCase):
del e
self.failIf('e' in locals())
+ def testExceptionCleanupState(self):
+ # Make sure exception state is cleaned up as soon as the except
+ # block is left. See #2507
+
+ class MyException(Exception):
+ def __init__(self, obj):
+ self.obj = obj
+ class MyObj:
+ pass
+
+ def inner_raising_func():
+ # Create some references in exception value and traceback
+ local_ref = obj
+ raise MyException(obj)
+
+ obj = MyObj()
+ wr = weakref.ref(obj)
+ try:
+ inner_raising_func()
+ except MyException as e:
+ pass
+ obj = None
+ obj = wr()
+ self.failUnless(obj is None, "%s" % obj)
+
def test_main():
run_unittest(ExceptionTests)