diff options
author | Guido van Rossum <guido@python.org> | 2007-01-10 16:19:56 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-01-10 16:19:56 (GMT) |
commit | b940e113bf90ff71b0ef57414ea2beea9d2a4bc0 (patch) | |
tree | 0b9ea19eba1e665dac95126c3140ac2bc36326ad /Lib/test/test_exceptions.py | |
parent | 893523e80a2003d4a630aafb84ba016e0070cbbd (diff) | |
download | cpython-b940e113bf90ff71b0ef57414ea2beea9d2a4bc0.zip cpython-b940e113bf90ff71b0ef57414ea2beea9d2a4bc0.tar.gz cpython-b940e113bf90ff71b0ef57414ea2beea9d2a4bc0.tar.bz2 |
SF patch 1631942 by Collin Winter:
(a) "except E, V" -> "except E as V"
(b) V is now limited to a simple name (local variable)
(c) V is now deleted at the end of the except block
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 7619aae..4a6b8c5 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -21,17 +21,17 @@ class ExceptionTests(unittest.TestCase): try: import exceptions reload(exceptions) - except ImportError, e: + except ImportError as e: self.fail("reloading exceptions: %s" % e) def raise_catch(self, exc, excname): try: raise exc, "spam" - except exc, err: + except exc as err: buf1 = str(err) try: raise exc("spam") - except exc, err: + except exc as err: buf2 = str(err) self.assertEquals(buf1, buf2) self.assertEquals(exc.__name__, excname) @@ -115,7 +115,7 @@ class ExceptionTests(unittest.TestCase): self.raise_catch(Exception, "Exception") try: x = 1/0 - except Exception, e: pass + except Exception as e: pass def testSyntaxErrorMessage(self): # make sure the right exception message is raised for each of @@ -124,7 +124,7 @@ class ExceptionTests(unittest.TestCase): def ckmsg(src, msg): try: compile(src, '<fragment>', 'exec') - except SyntaxError, e: + except SyntaxError as e: if e.msg != msg: self.fail("expected %s, got %s" % (msg, e.msg)) else: @@ -163,7 +163,7 @@ class ExceptionTests(unittest.TestCase): import _testcapi try: _testcapi.raise_exception(BadException, 1) - except TypeError, err: + except TypeError as err: exc, err, tb = sys.exc_info() co = tb.tb_frame.f_code self.assertEquals(co.co_name, "test_capi1") @@ -175,7 +175,7 @@ class ExceptionTests(unittest.TestCase): import _testcapi try: _testcapi.raise_exception(BadException, 0) - except RuntimeError, err: + except RuntimeError as err: exc, err, tb = sys.exc_info() co = tb.tb_frame.f_code self.assertEquals(co.co_name, "__init__") @@ -285,7 +285,7 @@ class ExceptionTests(unittest.TestCase): for exc, args, expected in exceptionList: try: raise exc(*args) - except BaseException, e: + except BaseException as e: if type(e) is not exc: raise # Verify module name @@ -344,6 +344,16 @@ class ExceptionTests(unittest.TestCase): self.failUnless(str(Exception('a'))) self.failUnless(unicode(Exception(u'a'))) + def testExceptionCleanup(self): + # Make sure "except V as N" exceptions are cleaned up properly + + try: + raise Exception() + except Exception as e: + self.failUnless(e) + del e + self.failIf('e' in locals()) + def test_main(): run_unittest(ExceptionTests) |