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 | |
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')
60 files changed, 174 insertions, 166 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 30c1e7c..0f1386e 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -585,7 +585,7 @@ class AbstractPickleTests(unittest.TestCase): badpickle = pickle.PROTO + chr(oob) + build_none try: self.loads(badpickle) - except ValueError, detail: + except ValueError as detail: self.failUnless(str(detail).startswith( "unsupported pickle protocol")) else: diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 8c0f2e4..ce39649 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -211,7 +211,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, generate=False, 'coverdir=', 'nocoverdir', 'runleaks', 'huntrleaks=', 'verbose2', 'memlimit=', ]) - except getopt.error, msg: + except getopt.error as msg: usage(2, msg) # Defaults @@ -556,19 +556,19 @@ def runtest_inner(test, generate, verbose, quiet, dash_R(the_module, test, indirect_test, huntrleaks) finally: sys.stdout = save_stdout - except test_support.ResourceDenied, msg: + except test_support.ResourceDenied as msg: if not quiet: print test, "skipped --", msg sys.stdout.flush() return -2 - except (ImportError, test_support.TestSkipped), msg: + except (ImportError, test_support.TestSkipped) as msg: if not quiet: print test, "skipped --", msg sys.stdout.flush() return -1 except KeyboardInterrupt: raise - except test_support.TestFailed, msg: + except test_support.TestFailed as msg: print "test", test, "failed --", msg sys.stdout.flush() return 0 @@ -640,7 +640,7 @@ def cleanup_test_droppings(testname, verbose): print "%r left behind %s %r" % (testname, kind, name) try: nuker(name) - except Exception, msg: + except Exception as msg: print >> sys.stderr, ("%r left behind %s %r and it couldn't be " "removed: %s" % (testname, kind, name, msg)) diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py index cc83ee4..3c95b89 100644 --- a/Lib/test/sortperf.py +++ b/Lib/test/sortperf.py @@ -37,7 +37,7 @@ def randfloats(n): os.unlink(fn) except os.error: pass - except IOError, msg: + except IOError as msg: print "can't write", fn, ":", msg else: result = marshal.load(fp) diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 1aa68de..2116ea4 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -970,7 +970,7 @@ class MixinStrUnicodeUserStringTest: def f(): yield 4 + "" self.fixtype(' ').join(f()) - except TypeError, e: + except TypeError as e: if '+' not in str(e): self.fail('join() ate exception message') else: diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py index 8121e03..954423f 100644 --- a/Lib/test/test_bool.py +++ b/Lib/test/test_bool.py @@ -373,13 +373,11 @@ class BoolTest(unittest.TestCase): return badval try: bool(A()) - except (Exception), e_bool: - pass - try: - len(A()) - except (Exception), e_len: - pass - self.assertEqual(str(e_bool), str(e_len)) + except (Exception) as e_bool: + try: + len(A()) + except (Exception) as e_len: + self.assertEqual(str(e_bool), str(e_len)) def test_main(): test_support.run_unittest(BoolTest) diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py index 3979f15..1b288b4 100644 --- a/Lib/test/test_cfgparser.py +++ b/Lib/test/test_cfgparser.py @@ -181,7 +181,7 @@ class TestCaseBase(unittest.TestCase): def get_error(self, exc, section, option): try: self.cf.get(section, option) - except exc, e: + except exc as e: return e else: self.fail("expected exception type %s.%s" diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index 52e5e91..9cf6a12 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -50,7 +50,7 @@ def do_test(buf, method): raise ValueError, "unknown method: %s" % method try: return cgi.parse(fp, env, strict_parsing=1) - except StandardError, err: + except StandardError as err: return ComparableException(err) # A list of test cases. Each test case is a a two-tuple that contains diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 3201dd8..1758fd4 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -372,7 +372,7 @@ class A: a = property(booh) try: A().a # Raised AttributeError: A instance has no attribute 'a' -except AttributeError, x: +except AttributeError as x: if str(x) != "booh": print "attribute error for A().a got masked:", str(x) @@ -384,7 +384,7 @@ class I: __init__ = property(booh) try: I() # In debug mode, printed XXX undetected error and raises AttributeError -except AttributeError, x: +except AttributeError as x: pass else: print "attribute error for I.__init__ got masked" diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 3c800f8..0711923 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -595,7 +595,7 @@ class UnicodeInternalTest(unittest.TestCase): if sys.maxunicode > 0xffff: try: "\x00\x00\x00\x00\x00\x11\x11\x00".decode("unicode_internal") - except UnicodeDecodeError, ex: + except UnicodeDecodeError as ex: self.assertEquals("unicode_internal", ex.encoding) self.assertEquals("\x00\x00\x00\x00\x00\x11\x11\x00", ex.object) self.assertEquals(4, ex.start) @@ -782,7 +782,7 @@ class NameprepTest(unittest.TestCase): prepped = unicode(prepped, "utf-8") try: self.assertEquals(nameprep(orig), prepped) - except Exception,e: + except Exception as e: raise test_support.TestFailed("Test 3.%d: %s" % (pos+1, str(e))) class IDNACodecTest(unittest.TestCase): diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py index 2ecd093..ebccb36 100644 --- a/Lib/test/test_compiler.py +++ b/Lib/test/test_compiler.py @@ -44,7 +44,7 @@ class CompilerTest(unittest.TestCase): else: try: compiler.compile(buf, basename, "exec") - except Exception, e: + except Exception as e: args = list(e.args) args[0] += "[in file %s]" % basename e.args = tuple(args) diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index 747785d..9142428 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -76,7 +76,7 @@ class ContextManagerTestCase(unittest.TestCase): state.append(1) try: yield 42 - except ZeroDivisionError, e: + except ZeroDivisionError as e: state.append(e.args[0]) self.assertEqual(state, [1, 42, 999]) with woohoo() as x: diff --git a/Lib/test/test_cookielib.py b/Lib/test/test_cookielib.py index 544f29f..9b06869 100644 --- a/Lib/test/test_cookielib.py +++ b/Lib/test/test_cookielib.py @@ -257,7 +257,7 @@ class FileCookieJarTests(TestCase): try: c.load(filename="for this test to work, a file with this " "filename should not exist") - except IOError, exc: + except IOError as exc: # exactly IOError, not LoadError self.assertEqual(exc.__class__, IOError) else: diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py index ed92bfe..0a9db4e 100755 --- a/Lib/test/test_dbm.py +++ b/Lib/test/test_dbm.py @@ -16,7 +16,8 @@ def cleanup(): for suffix in ['', '.pag', '.dir', '.db']: try: os.unlink(filename + suffix) - except OSError, (errno, strerror): + except OSError as e: + (errno, strerror) = e # if we can't delete the file because of permissions, # nothing will work, so skip the test if errno == 1: diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py index 50df93d..f9a9e82 100644 --- a/Lib/test/test_decimal.py +++ b/Lib/test/test_decimal.py @@ -146,7 +146,7 @@ class DecimalTest(unittest.TestCase): print 'Error in test cases:' print line continue - except DecimalException, exception: + except DecimalException as exception: #Exception raised where there shoudn't have been one. self.fail('Exception "'+exception.__class__.__name__ + '" raised on line '+line) @@ -238,7 +238,7 @@ class DecimalTest(unittest.TestCase): funct(self.context.create_decimal(v)) except error: pass - except Signals, e: + except Signals as e: self.fail("Raised %s in %s when %s disabled" % \ (e, s, error)) else: @@ -258,7 +258,7 @@ class DecimalTest(unittest.TestCase): funct(*vals) except error: pass - except Signals, e: + except Signals as e: self.fail("Raised %s in %s when %s disabled" % \ (e, s, error)) else: @@ -268,7 +268,7 @@ class DecimalTest(unittest.TestCase): result = str(funct(*vals)) if fname == 'same_quantum': result = str(int(eval(result))) # 'True', 'False' -> '1', '0' - except Signals, error: + except Signals as error: self.fail("Raised %s in %s" % (error, s)) except: #Catch any error long enough to state the test case. print "ERROR:", s diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py index 134b5a8..602e0d9 100644 --- a/Lib/test/test_defaultdict.py +++ b/Lib/test/test_defaultdict.py @@ -43,7 +43,7 @@ class TestDefaultDict(unittest.TestCase): self.assertEqual(d2.default_factory, None) try: d2[15] - except KeyError, err: + except KeyError as err: self.assertEqual(err.args, (15,)) else: self.fail("d2[15] didn't raise KeyError") diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 2968e3d..96ff9f3 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -945,7 +945,7 @@ def mro_disagreement(): def raises(exc, expected, callable, *args): try: callable(*args) - except exc, msg: + except exc as msg: if not str(msg).startswith(expected): raise TestFailed, "Message %r, expected %r" % (str(msg), expected) @@ -1813,7 +1813,7 @@ def weakrefs(): no = NoWeak() try: weakref.ref(no) - except TypeError, msg: + except TypeError as msg: verify(str(msg).find("weak reference") >= 0) else: verify(0, "weakref.ref(no) should be illegal") @@ -1866,7 +1866,7 @@ def properties(): for attr in "__doc__", "fget", "fset", "fdel": try: setattr(raw, attr, 42) - except TypeError, msg: + except TypeError as msg: if str(msg).find('readonly') < 0: raise TestFailed("when setting readonly attr %r on a " "property, got unexpected TypeError " @@ -2416,7 +2416,7 @@ f = t(%r, 'w') # rexec can't catch this by itself for code in code1, code2, code3: try: sandbox.r_exec(code) - except IOError, msg: + except IOError as msg: if str(msg).find("restricted") >= 0: outcome = "OK" else: @@ -3523,7 +3523,7 @@ def test_mutable_bases(): try: D.__bases__ = () - except TypeError, msg: + except TypeError as msg: if str(msg) == "a new-style class can't have only classic bases": raise TestFailed, "wrong error message for .__bases__ = ()" else: diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index ff6ccde..c7fa15d 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -414,7 +414,7 @@ class DictTest(unittest.TestCase): e = E() try: e[42] - except RuntimeError, err: + except RuntimeError as err: self.assertEqual(err.args, (42,)) else: self.fail_("e[42] didn't raise RuntimeError") @@ -425,7 +425,7 @@ class DictTest(unittest.TestCase): f = F() try: f[42] - except KeyError, err: + except KeyError as err: self.assertEqual(err.args, (42,)) else: self.fail_("f[42] didn't raise KeyError") @@ -434,7 +434,7 @@ class DictTest(unittest.TestCase): g = G() try: g[42] - except KeyError, err: + except KeyError as err: self.assertEqual(err.args, (42,)) else: self.fail_("g[42] didn't raise KeyError") @@ -444,7 +444,7 @@ class DictTest(unittest.TestCase): d = {} try: d[(1,)] - except KeyError, e: + except KeyError as e: self.assertEqual(e.args, ((1,),)) else: self.fail("missing KeyError") diff --git a/Lib/test/test_dl.py b/Lib/test/test_dl.py index b70a4cf..9c70427 100755 --- a/Lib/test/test_dl.py +++ b/Lib/test/test_dl.py @@ -18,7 +18,7 @@ for s, func in sharedlibs: if verbose: print 'trying to open:', s, l = dl.open(s) - except dl.error, err: + except dl.error as err: if verbose: print 'failed', repr(str(err)) pass diff --git a/Lib/test/test_eof.py b/Lib/test/test_eof.py index aae3518..1187d07 100644 --- a/Lib/test/test_eof.py +++ b/Lib/test/test_eof.py @@ -11,7 +11,7 @@ class EOFTestCase(unittest.TestCase): try: eval("""'this is a test\ """) - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(str(msg), expect) else: raise test_support.TestFailed @@ -20,7 +20,7 @@ class EOFTestCase(unittest.TestCase): expect = "EOF while scanning triple-quoted string (<string>, line 1)" try: eval("""'''this is a test""") - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(str(msg), expect) else: raise test_support.TestFailed 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) diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index 284dbb2..11cf43a 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -35,21 +35,21 @@ else: try: g() -except TypeError, err: +except TypeError as err: print "TypeError:", err else: print "should raise TypeError: not enough arguments; expected 1, got 0" try: g(*()) -except TypeError, err: +except TypeError as err: print "TypeError:", err else: print "should raise TypeError: not enough arguments; expected 1, got 0" try: g(*(), **{}) -except TypeError, err: +except TypeError as err: print "TypeError:", err else: print "should raise TypeError: not enough arguments; expected 1, got 0" @@ -61,7 +61,7 @@ g(1, 2, 3, *(4, 5)) class Nothing: pass try: g(*Nothing()) -except TypeError, attr: +except TypeError as attr: pass else: print "should raise TypeError" @@ -71,7 +71,7 @@ class Nothing: return 5 try: g(*Nothing()) -except TypeError, attr: +except TypeError as attr: pass else: print "should raise TypeError" @@ -93,7 +93,7 @@ class Nothing: return self try: g(*Nothing()) -except TypeError, attr: +except TypeError as attr: pass else: print "should raise TypeError" @@ -132,77 +132,77 @@ del kw['x'] try: g(1, 2, 3, **{'x':4, 'y':5}) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: keyword parameter redefined" try: g(1, 2, 3, a=4, b=5, *(6, 7), **{'a':8, 'b':9}) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: keyword parameter redefined" try: f(**{1:2}) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: keywords must be strings" try: h(**{'e': 2}) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: unexpected keyword argument: e" try: h(*h) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: * argument must be a tuple" try: dir(*h) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: * argument must be a tuple" try: None(*h) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: * argument must be a tuple" try: h(**h) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: ** argument must be a dictionary" try: dir(**h) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: ** argument must be a dictionary" try: None(**h) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: ** argument must be a dictionary" try: dir(b=1,**{'b':1}) -except TypeError, err: +except TypeError as err: print err else: print "should raise TypeError: dir() got multiple values for keyword argument 'b'" @@ -226,13 +226,13 @@ print Foo.method(*(x, 1, 2)) print Foo.method(x, *(1, 2)) try: print Foo.method(*(1, 2, 3)) -except TypeError, err: +except TypeError as err: pass else: print 'expected a TypeError for unbound method call' try: print Foo.method(1, *(2, 3)) -except TypeError, err: +except TypeError as err: pass else: print 'expected a TypeError for unbound method call' @@ -276,4 +276,4 @@ for name in ['za', 'zade', 'zabk', 'zabdv', 'zabdevk']: for k in kwargs: kwdict[k] = k + k print func.func_name, args, sortdict(kwdict), '->', try: func(*args, **kwdict) - except TypeError, err: print err + except TypeError as err: print err diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index 234920d..52c4a02 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -159,7 +159,7 @@ class OtherFileTests(unittest.TestCase): bad_mode = "qwerty" try: f = open(TESTFN, bad_mode) - except ValueError, msg: + except ValueError as msg: if msg[0] != 0: s = str(msg) if s.find(TESTFN) != -1 or s.find(bad_mode) == -1: @@ -183,7 +183,7 @@ class OtherFileTests(unittest.TestCase): d = int(f.read()) f.close() f.close() - except IOError, msg: + except IOError as msg: self.fail('error setting buffer size %d: %s' % (s, str(msg))) self.assertEquals(d, s) diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index 8bf5d6e..ace3bc9 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -199,7 +199,7 @@ if verbose: def test_exc(formatstr, args, exception, excmsg): try: testformat(formatstr, args) - except exception, exc: + except exception as exc: if str(exc) == excmsg: if verbose: print "yes" diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py index 673799d..678b9a8 100644 --- a/Lib/test/test_frozen.py +++ b/Lib/test/test_frozen.py @@ -12,17 +12,17 @@ import sys, os try: import __hello__ -except ImportError, x: +except ImportError as x: raise TestFailed, "import __hello__ failed:" + str(x) try: import __phello__ -except ImportError, x: +except ImportError as x: raise TestFailed, "import __phello__ failed:" + str(x) try: import __phello__.spam -except ImportError, x: +except ImportError as x: raise TestFailed, "import __phello__.spam failed:" + str(x) if sys.platform != "mac": # On the Mac this import does succeed. diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py index 9a5f829..1437489 100644 --- a/Lib/test/test_future.py +++ b/Lib/test/test_future.py @@ -29,7 +29,7 @@ class FutureTest(unittest.TestCase): def test_badfuture3(self): try: from test import badsyntax_future3 - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(get_error_location(msg), ("badsyntax_future3", '3')) else: self.fail("expected exception didn't occur") @@ -37,7 +37,7 @@ class FutureTest(unittest.TestCase): def test_badfuture4(self): try: from test import badsyntax_future4 - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(get_error_location(msg), ("badsyntax_future4", '3')) else: self.fail("expected exception didn't occur") @@ -45,7 +45,7 @@ class FutureTest(unittest.TestCase): def test_badfuture5(self): try: from test import badsyntax_future5 - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(get_error_location(msg), ("badsyntax_future5", '4')) else: self.fail("expected exception didn't occur") @@ -53,7 +53,7 @@ class FutureTest(unittest.TestCase): def test_badfuture6(self): try: from test import badsyntax_future6 - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(get_error_location(msg), ("badsyntax_future6", '3')) else: self.fail("expected exception didn't occur") @@ -61,7 +61,7 @@ class FutureTest(unittest.TestCase): def test_badfuture7(self): try: from test import badsyntax_future7 - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(get_error_location(msg), ("badsyntax_future7", '3')) else: self.fail("expected exception didn't occur") @@ -69,7 +69,7 @@ class FutureTest(unittest.TestCase): def test_badfuture8(self): try: from test import badsyntax_future8 - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(get_error_location(msg), ("badsyntax_future8", '3')) else: self.fail("expected exception didn't occur") @@ -77,7 +77,7 @@ class FutureTest(unittest.TestCase): def test_badfuture9(self): try: from test import badsyntax_future9 - except SyntaxError, msg: + except SyntaxError as msg: self.assertEqual(get_error_location(msg), ("badsyntax_future9", '3')) else: self.fail("expected exception didn't occur") diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 2ffd2f8..30df034 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -1554,7 +1554,7 @@ Now check some throw() conditions: ... while True: ... try: ... print (yield) -... except ValueError,v: +... except ValueError as v: ... print "caught ValueError (%s)" % (v), >>> import sys >>> g = f() diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 34c550e..0d36a62 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -554,7 +554,7 @@ hello world assert 1, lambda x:x+1 try: assert 0, "msg" - except AssertionError, e: + except AssertionError as e: self.assertEquals(e.args[0], "msg") else: if __debug__: @@ -612,7 +612,7 @@ hello world def testTry(self): ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite] ### | 'try' ':' suite 'finally' ':' suite - ### except_clause: 'except' [expr [',' expr]] + ### except_clause: 'except' [expr ['as' expr]] try: 1/0 except ZeroDivisionError: @@ -621,14 +621,14 @@ hello world pass try: 1/0 except EOFError: pass - except TypeError, msg: pass - except RuntimeError, msg: pass + except TypeError as msg: pass + except RuntimeError as msg: pass except: pass else: pass try: 1/0 except (EOFError, TypeError, ZeroDivisionError): pass try: 1/0 - except (EOFError, TypeError, ZeroDivisionError), msg: pass + except (EOFError, TypeError, ZeroDivisionError) as msg: pass try: pass finally: pass diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 58de944..f3d1d49 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -55,7 +55,7 @@ class ImportTest(unittest.TestCase): try: try: mod = __import__(TESTFN) - except ImportError, err: + except ImportError as err: self.fail("import from %s failed: %s" % (ext, err)) self.assertEquals(mod.a, a, @@ -68,7 +68,7 @@ class ImportTest(unittest.TestCase): try: try: reload(mod) - except ImportError, err: + except ImportError as err: self.fail("import from .pyc/.pyo failed: %s" % err) finally: try: diff --git a/Lib/test/test_linuxaudiodev.py b/Lib/test/test_linuxaudiodev.py index fe902b5..05e4041 100644 --- a/Lib/test/test_linuxaudiodev.py +++ b/Lib/test/test_linuxaudiodev.py @@ -27,7 +27,7 @@ def play_sound_file(path): try: a = linuxaudiodev.open('w') - except linuxaudiodev.error, msg: + except linuxaudiodev.error as msg: if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): raise TestSkipped, msg raise TestFailed, msg @@ -62,27 +62,27 @@ def test_errors(): nchannels = 1 try: a.setparameters(-1, size, nchannels, fmt) - except ValueError, msg: + except ValueError as msg: print msg try: a.setparameters(rate, -2, nchannels, fmt) - except ValueError, msg: + except ValueError as msg: print msg try: a.setparameters(rate, size, 3, fmt) - except ValueError, msg: + except ValueError as msg: print msg try: a.setparameters(rate, size, nchannels, 177) - except ValueError, msg: + except ValueError as msg: print msg try: a.setparameters(rate, size, nchannels, linuxaudiodev.AFMT_U16_LE) - except ValueError, msg: + except ValueError as msg: print msg try: a.setparameters(rate, 16, nchannels, fmt) - except ValueError, msg: + except ValueError as msg: print msg def test(): diff --git a/Lib/test/test_nis.py b/Lib/test/test_nis.py index 590868f..55dd32c 100644 --- a/Lib/test/test_nis.py +++ b/Lib/test/test_nis.py @@ -6,7 +6,7 @@ class NisTests(unittest.TestCase): def test_maps(self): try: maps = nis.maps() - except nis.error, msg: + except nis.error as msg: # NIS is probably not active, so this test isn't useful if verbose: self.fail("(failing because of verbose mode) %s" % msg) diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py index 1a2f5d6..0ee51a8 100644 --- a/Lib/test/test_opcodes.py +++ b/Lib/test/test_opcodes.py @@ -47,12 +47,12 @@ class OpcodeTest(unittest.TestCase): b = BClass() try: raise AClass, b - except BClass, v: + except BClass as v: if v != b: self.fail("v!=b") else: self.fail("no exception") try: raise b - except AClass, v: + except AClass as v: if v != b: self.fail("v!=b AClass") else: self.fail("no exception") @@ -63,7 +63,7 @@ class OpcodeTest(unittest.TestCase): ##else: self.fail("no exception") try: raise DClass, a - except DClass, v: + except DClass as v: self.assert_(isinstance(v, DClass)) else: self.fail("no exception") diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py index 4582fa7..1c4970f 100644 --- a/Lib/test/test_optparse.py +++ b/Lib/test/test_optparse.py @@ -114,7 +114,7 @@ Args were %(args)s.""" % locals ()) try: func(*args, **kwargs) - except expected_exception, err: + except expected_exception as err: actual_message = str(err) if isinstance(expected_message, retype): self.assert_(expected_message.search(actual_message), @@ -152,7 +152,7 @@ and kwargs %(kwargs)r """ try: self.parser.parse_args(cmdline_args) - except InterceptedError, err: + except InterceptedError as err: self.assertEqual(err.error_message, expected_output) else: self.assertFalse("expected parse failure") @@ -175,7 +175,7 @@ and kwargs %(kwargs)r output = sys.stdout.getvalue() sys.stdout = save_stdout - except InterceptedError, err: + except InterceptedError as err: self.assert_( type(output) is types.StringType, "expected output to be an ordinary string, not %r" @@ -460,7 +460,7 @@ def _check_duration(option, opt, value): return int(value) else: return int(value[:-1]) * _time_units[value[-1]] - except ValueError, IndexError: + except ValueError as IndexError: raise OptionValueError( 'option %s: invalid duration: %r' % (opt, value)) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 1c87d06..93e530c 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -179,7 +179,7 @@ class StatAttributeTests(unittest.TestCase): import statvfs try: result = os.statvfs(self.fname) - except OSError, e: + except OSError as e: # On AtheOS, glibc always returns ENOSYS import errno if e.errno == errno.ENOSYS: diff --git a/Lib/test/test_ossaudiodev.py b/Lib/test/test_ossaudiodev.py index 5868ea7..0377e9c 100644 --- a/Lib/test/test_ossaudiodev.py +++ b/Lib/test/test_ossaudiodev.py @@ -48,7 +48,7 @@ def _assert(expr, message=None): def play_sound_file(data, rate, ssize, nchannels): try: dsp = ossaudiodev.open('w') - except IOError, msg: + except IOError as msg: if msg[0] in (errno.EACCES, errno.ENOENT, errno.ENODEV, errno.EBUSY): raise TestSkipped, msg raise TestFailed, msg @@ -142,7 +142,7 @@ def test_bad_setparameters(dsp): try: result = dsp.setparameters(fmt, channels, rate, True) raise AssertionError("setparameters: expected OSSAudioError") - except ossaudiodev.OSSAudioError, err: + except ossaudiodev.OSSAudioError as err: print "setparameters: got OSSAudioError as expected" def test(): diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 0bf1218..36bc4e3 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -15,7 +15,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): t = st1.totuple() try: st2 = parser.sequence2st(t) - except parser.ParserError, why: + except parser.ParserError as why: self.fail("could not roundtrip %r: %s" % (s, why)) self.assertEquals(t, st2.totuple(), diff --git a/Lib/test/test_pep277.py b/Lib/test/test_pep277.py index f307089..ff71bf2 100644 --- a/Lib/test/test_pep277.py +++ b/Lib/test/test_pep277.py @@ -50,7 +50,7 @@ class UnicodeFileTests(unittest.TestCase): fn(filename) raise test_support.TestFailed("Expected to fail calling '%s(%r)'" % (fn.__name__, filename)) - except expected_exception, details: + except expected_exception as details: if check_fn_in_exception and details.filename != filename: raise test_support.TestFailed("Function '%s(%r) failed with " "bad filename in the exception: %r" diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py index 0698818..73092c1 100644 --- a/Lib/test/test_pyexpat.py +++ b/Lib/test/test_pyexpat.py @@ -177,7 +177,7 @@ expat.ParserCreate(namespace_separator=' ') print "Legal values tested o.k." try: expat.ParserCreate(namespace_separator=42) -except TypeError, e: +except TypeError as e: print "Caught expected TypeError:" print e else: @@ -185,7 +185,7 @@ else: try: expat.ParserCreate(namespace_separator='too long') -except ValueError, e: +except ValueError as e: print "Caught expected ValueError:" print e else: @@ -321,7 +321,7 @@ parser.StartElementHandler = StartElementHandler try: parser.Parse("<a><b><c/></b></a>", 1) -except RuntimeError, e: +except RuntimeError as e: if e.args[0] != "a": print "Expected RuntimeError for element 'a'; found %r" % e.args[0] else: diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 02f4dca..dafd82e 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -633,7 +633,7 @@ def run_re_tests(): else: try: result = obj.search(s) - except re.error, msg: + except re.error as msg: print '=== Unexpected exception', t, repr(msg) if outcome == SYNTAX_ERROR: # This should have been a syntax error; forget it. diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py index 88e9900..a37ee7b 100644 --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -117,7 +117,7 @@ class RunModuleTest(unittest.TestCase): entry = parts[0] try: del sys.modules[entry] - except KeyError, ex: + except KeyError as ex: if verbose: print ex # Persist with cleaning up if verbose: print " Removed sys.modules entries" del sys.path[0] @@ -126,18 +126,18 @@ class RunModuleTest(unittest.TestCase): for name in files: try: os.remove(os.path.join(root, name)) - except OSError, ex: + except OSError as ex: if verbose: print ex # Persist with cleaning up for name in dirs: fullname = os.path.join(root, name) try: os.rmdir(fullname) - except OSError, ex: + except OSError as ex: if verbose: print ex # Persist with cleaning up try: os.rmdir(top) if verbose: print " Removed package tree" - except OSError, ex: + except OSError as ex: if verbose: print ex # Persist with cleaning up def _check_module(self, depth): diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 83ffcf1..d3939c0 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -479,7 +479,7 @@ def test_expat_inpsource_location(): source.setSystemId(name) try: parser.parse(source) - except SAXException, e: + except SAXException as e: return e.getSystemId() == name def test_expat_incomplete(): diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 9bd0d43..0d08b79 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -332,7 +332,7 @@ class TestSet(TestJointOps): for v1 in ['Q', (1,)]: try: self.s.remove(v1) - except KeyError, e: + except KeyError as e: v2 = e.args[0] self.assertEqual(v1, v2) else: diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index df37f73..e141257 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -129,7 +129,7 @@ class ThreadableTest: raise TypeError, "test_func must be a callable function" try: test_func() - except Exception, strerror: + except Exception as strerror: self.queue.put(strerror) self.clientTearDown() diff --git a/Lib/test/test_socket_ssl.py b/Lib/test/test_socket_ssl.py index 3c9c9f0..5d308c5 100644 --- a/Lib/test/test_socket_ssl.py +++ b/Lib/test/test_socket_ssl.py @@ -58,7 +58,7 @@ def test_timeout(): except socket.timeout: error_msg('timed out') return - except socket.error, exc: # In case connection is refused. + except socket.error as exc: # In case connection is refused. if exc.args[0] == errno.ECONNREFUSED: error_msg('was refused') return diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index e4cbb2b..202f2da 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -155,7 +155,8 @@ class ForgivingTCPServer(TCPServer): self.server_address = host, port TCPServer.server_bind(self) break - except socket.error, (err, msg): + except socket.error as e: + (err, msg) = e if err != errno.EADDRINUSE: raise print >>sys.__stderr__, \ diff --git a/Lib/test/test_strftime.py b/Lib/test/test_strftime.py index e9d3826..00fa227 100755 --- a/Lib/test/test_strftime.py +++ b/Lib/test/test_strftime.py @@ -119,7 +119,7 @@ def strftest(now): for e in expectations: try: result = time.strftime(e[0], now) - except ValueError, error: + except ValueError as error: print "Standard '%s' format gave error:" % e[0], error continue if re.match(escapestr(e[1], ampm), result): continue @@ -132,7 +132,7 @@ def strftest(now): for e in nonstandard_expectations: try: result = time.strftime(e[0], now) - except ValueError, result: + except ValueError as result: if verbose: print "Error for nonstandard '%s' format (%s): %s" % \ (e[0], e[2], str(result)) diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index fdd431d..6d5e8e4 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -55,7 +55,7 @@ class StringTest( def f(): yield 4 + "" self.fixtype(' ').join(f()) - except TypeError, e: + except TypeError as e: if '+' not in str(e): self.fail('join() ate exception message') else: diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py index ba65649..df94f7b 100644 --- a/Lib/test/test_strptime.py +++ b/Lib/test/test_strptime.py @@ -206,7 +206,7 @@ class StrptimeTests(unittest.TestCase): _strptime.strptime("2005", bad_format) except ValueError: continue - except Exception, err: + except Exception as err: self.fail("'%s' raised %s, not ValueError" % (bad_format, err.__class__.__name__)) else: diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 64f8d40..fcc0f45 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -67,7 +67,7 @@ class ProcessTestCase(unittest.TestCase): try: subprocess.check_call([sys.executable, "-c", "import sys; sys.exit(47)"]) - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError as e: self.assertEqual(e.returncode, 47) else: self.fail("Expected CalledProcessError") @@ -475,7 +475,7 @@ class ProcessTestCase(unittest.TestCase): try: p = subprocess.Popen([sys.executable, "-c", ""], cwd="/this/path/does/not/exist") - except OSError, e: + except OSError as e: # The attribute child_traceback should contain "os.chdir" # somewhere. self.assertNotEqual(e.child_traceback.find("os.chdir"), -1) diff --git a/Lib/test/test_sunaudiodev.py b/Lib/test/test_sunaudiodev.py index f203d9a..0427db5 100644 --- a/Lib/test/test_sunaudiodev.py +++ b/Lib/test/test_sunaudiodev.py @@ -16,7 +16,7 @@ def play_sound_file(path): fp.close() try: a = sunaudiodev.open('w') - except sunaudiodev.error, msg: + except sunaudiodev.error as msg: raise TestFailed, msg else: a.write(data) diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 2c19698..6115800 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -102,7 +102,8 @@ def bind_port(sock, host='', preferred_port=54321): try: sock.bind((host, port)) return port - except socket.error, (err, msg): + except socket.error as e: + (err, msg) = e if err != errno.EADDRINUSE: raise print >>sys.__stderr__, \ diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index a0eaac6..2c7315d 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -387,7 +387,7 @@ class SyntaxTestCase(unittest.TestCase): """ try: compile(code, filename, mode) - except SyntaxError, err: + except SyntaxError as err: if subclass and not isinstance(err, subclass): self.fail("SyntaxError is not a %s" % subclass.__name__) mo = re.search(errtext, str(err)) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index fdeb500..897c6b0 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -54,7 +54,7 @@ class SysModuleTest(unittest.TestCase): self.assertRaises(TypeError, eh) try: raise ValueError(42) - except ValueError, exc: + except ValueError as exc: eh(*sys.exc_info()) sys.stderr = savestderr @@ -84,7 +84,7 @@ class SysModuleTest(unittest.TestCase): def clear(): try: raise ValueError, 42 - except ValueError, exc: + except ValueError as exc: clear_check(exc) # Raise an exception and check that it can be cleared @@ -94,7 +94,7 @@ class SysModuleTest(unittest.TestCase): # unaffected by calling exc_clear in a nested frame. try: raise ValueError, 13 - except ValueError, exc: + except ValueError as exc: typ1, value1, traceback1 = sys.exc_info() clear() typ2, value2, traceback2 = sys.exc_info() @@ -104,16 +104,13 @@ class SysModuleTest(unittest.TestCase): self.assert_(value1 is value2) self.assert_(traceback1 is traceback2) - # Check that an exception can be cleared outside of an except block - clear_check(exc) - def test_exit(self): self.assertRaises(TypeError, sys.exit, 42, 42) # call without argument try: sys.exit(0) - except SystemExit, exc: + except SystemExit as exc: self.assertEquals(exc.code, 0) except: self.fail("wrong exception") @@ -124,7 +121,7 @@ class SysModuleTest(unittest.TestCase): # entry will be unpacked try: sys.exit(42) - except SystemExit, exc: + except SystemExit as exc: self.assertEquals(exc.code, 42) except: self.fail("wrong exception") @@ -134,7 +131,7 @@ class SysModuleTest(unittest.TestCase): # call with integer argument try: sys.exit((42,)) - except SystemExit, exc: + except SystemExit as exc: self.assertEquals(exc.code, 42) except: self.fail("wrong exception") @@ -144,7 +141,7 @@ class SysModuleTest(unittest.TestCase): # call with string argument try: sys.exit("exit") - except SystemExit, exc: + except SystemExit as exc: self.assertEquals(exc.code, "exit") except: self.fail("wrong exception") @@ -154,7 +151,7 @@ class SysModuleTest(unittest.TestCase): # call with tuple argument with two entries try: sys.exit((17, 23)) - except SystemExit, exc: + except SystemExit as exc: self.assertEquals(exc.code, (17, 23)) except: self.fail("wrong exception") diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 2b39715..9ae913d 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -545,7 +545,7 @@ class ExtractHardlinkTest(BaseTest): try: # Extract 1-LNKTYPE which is a hardlink to 0-REGTYPE self.tar.extract("1-LNKTYPE", dirname()) - except EnvironmentError, e: + except EnvironmentError as e: import errno if e.errno == errno.ENOENT: self.fail("hardlink not extracted properly") diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index fa170ef..4255d8a 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -107,7 +107,7 @@ class TclTest(unittest.TestCase): filename = "doesnotexists" try: os.remove(filename) - except Exception,e: + except Exception as e: pass self.assertRaises(TclError,tcl.evalfile,filename) diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py index 08aec8e..42d1a4a 100644 --- a/Lib/test/test_trace.py +++ b/Lib/test/test_trace.py @@ -97,7 +97,7 @@ def raises(): def test_raise(): try: raises() - except Exception, exc: + except Exception as exc: x = 1 test_raise.events = [(0, 'call'), @@ -127,7 +127,7 @@ def _settrace_and_raise(tracefunc): def settrace_and_raise(tracefunc): try: _settrace_and_raise(tracefunc) - except RuntimeError, exc: + except RuntimeError as exc: pass settrace_and_raise.events = [(2, 'exception'), @@ -432,7 +432,7 @@ def no_jump_too_far_forwards(output): try: output.append(2) output.append(3) - except ValueError, e: + except ValueError as e: output.append('after' in str(e)) no_jump_too_far_forwards.jump = (3, 6) @@ -442,7 +442,7 @@ def no_jump_too_far_backwards(output): try: output.append(2) output.append(3) - except ValueError, e: + except ValueError as e: output.append('before' in str(e)) no_jump_too_far_backwards.jump = (3, -1) @@ -472,7 +472,7 @@ no_jump_to_except_2.output = [True] def no_jump_to_except_3(output): try: output.append(2) - except ValueError, e: + except ValueError as e: output.append('except' in str(e)) no_jump_to_except_3.jump = (2, 3) @@ -481,7 +481,7 @@ no_jump_to_except_3.output = [True] def no_jump_to_except_4(output): try: output.append(2) - except (ValueError, RuntimeError), e: + except (ValueError, RuntimeError) as e: output.append('except' in str(e)) no_jump_to_except_4.jump = (2, 3) @@ -492,7 +492,7 @@ def no_jump_forwards_into_block(output): output.append(2) for i in 1, 2: output.append(4) - except ValueError, e: + except ValueError as e: output.append('into' in str(e)) no_jump_forwards_into_block.jump = (2, 4) @@ -503,7 +503,7 @@ def no_jump_backwards_into_block(output): for i in 1, 2: output.append(3) output.append(4) - except ValueError, e: + except ValueError as e: output.append('into' in str(e)) no_jump_backwards_into_block.jump = (4, 3) @@ -516,7 +516,7 @@ def no_jump_into_finally_block(output): x = 1 finally: output.append(6) - except ValueError, e: + except ValueError as e: output.append('finally' in str(e)) no_jump_into_finally_block.jump = (4, 6) @@ -529,7 +529,7 @@ def no_jump_out_of_finally_block(output): finally: output.append(5) output.append(6) - except ValueError, e: + except ValueError as e: output.append('finally' in str(e)) no_jump_out_of_finally_block.jump = (5, 1) @@ -539,7 +539,7 @@ no_jump_out_of_finally_block.output = [3, True] def no_jump_to_non_integers(output): try: output.append(2) - except ValueError, e: + except ValueError as e: output.append('integer' in str(e)) no_jump_to_non_integers.jump = (2, "Spam") @@ -551,7 +551,7 @@ def no_jump_without_trace_function(): try: previous_frame = sys._getframe().f_back previous_frame.f_lineno = previous_frame.f_lineno - except ValueError, e: + except ValueError as e: # This is the exception we wanted; make sure the error message # talks about trace functions. if 'trace' not in str(e): diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 48c5d19..5c8a4e4 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -12,7 +12,7 @@ class TracebackCases(unittest.TestCase): def get_exception_format(self, func, exc): try: func() - except exc, value: + except exc as value: return traceback.format_exception_only(exc, value) else: raise ValueError, "call did not raise exception" diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py index 00cf202..50acff8 100644 --- a/Lib/test/test_urllib2net.py +++ b/Lib/test/test_urllib2net.py @@ -236,7 +236,7 @@ class OtherNetworkTests(unittest.TestCase): debug(url) try: f = urllib2.urlopen(url, req) - except (IOError, socket.error, OSError), err: + except (IOError, socket.error, OSError) as err: debug(err) if expected_err: msg = ("Didn't get expected error(s) %s for %s %s, got %s" % diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py index 447f434..25aa307 100644 --- a/Lib/test/test_userdict.py +++ b/Lib/test/test_userdict.py @@ -168,7 +168,7 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): e = E() try: e[42] - except RuntimeError, err: + except RuntimeError as err: self.assertEqual(err.args, (42,)) else: self.fail_("e[42] didn't raise RuntimeError") @@ -180,7 +180,7 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): f = F() try: f[42] - except KeyError, err: + except KeyError as err: self.assertEqual(err.args, (42,)) else: self.fail_("f[42] didn't raise KeyError") @@ -189,7 +189,7 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol): g = G() try: g[42] - except KeyError, err: + except KeyError as err: self.assertEqual(err.args, (42,)) else: self.fail_("g[42] didn't raise KeyError") diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py index 16a55e4..7128148 100644 --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -50,7 +50,7 @@ class UUTest(unittest.TestCase): try: uu.decode(inp, out) self.fail("No exception thrown") - except uu.Error, e: + except uu.Error as e: self.assertEqual(str(e), "Truncated input file") def test_missingbegin(self): @@ -59,7 +59,7 @@ class UUTest(unittest.TestCase): try: uu.decode(inp, out) self.fail("No exception thrown") - except uu.Error, e: + except uu.Error as e: self.assertEqual(str(e), "No valid begin line found in input file") class UUStdIOTest(unittest.TestCase): diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py index 5830fd6..81bd760 100644 --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -142,7 +142,7 @@ except (IndexError, ValueError): if remote_name is not None: try: remote_key = ConnectRegistry(remote_name, HKEY_CURRENT_USER) - except EnvironmentError, exc: + except EnvironmentError as exc: print "Could not connect to the remote machine -", exc.strerror remote_key = None if remote_key is not None: |