[1.5.X] Fixed #19204 -- Replaced python2-style exception syntax.

Thanks to garrison for the report and patch.

Backport of 4a71b84266 from master
This commit is contained in:
Florian Apolloner 2012-12-24 14:04:02 +01:00
parent 1114d8203e
commit ef98ae2910
4 changed files with 15 additions and 15 deletions

View File

@ -324,7 +324,7 @@ class TestCase(unittest.TestCase):
success = False success = False
try: try:
self.setUp() self.setUp()
except SkipTest, e: except SkipTest as e:
self._addSkip(result, str(e)) self._addSkip(result, str(e))
except Exception: except Exception:
result.addError(self, sys.exc_info()) result.addError(self, sys.exc_info())
@ -333,7 +333,7 @@ class TestCase(unittest.TestCase):
testMethod() testMethod()
except self.failureException: except self.failureException:
result.addFailure(self, sys.exc_info()) result.addFailure(self, sys.exc_info())
except _ExpectedFailure, e: except _ExpectedFailure as e:
addExpectedFailure = getattr(result, 'addExpectedFailure', None) addExpectedFailure = getattr(result, 'addExpectedFailure', None)
if addExpectedFailure is not None: if addExpectedFailure is not None:
addExpectedFailure(self, e.exc_info) addExpectedFailure(self, e.exc_info)
@ -349,7 +349,7 @@ class TestCase(unittest.TestCase):
warnings.warn("Use of a TestResult without an addUnexpectedSuccess method is deprecated", warnings.warn("Use of a TestResult without an addUnexpectedSuccess method is deprecated",
DeprecationWarning) DeprecationWarning)
result.addFailure(self, sys.exc_info()) result.addFailure(self, sys.exc_info())
except SkipTest, e: except SkipTest as e:
self._addSkip(result, str(e)) self._addSkip(result, str(e))
except Exception: except Exception:
result.addError(self, sys.exc_info()) result.addError(self, sys.exc_info())
@ -770,16 +770,16 @@ class TestCase(unittest.TestCase):
""" """
try: try:
difference1 = set1.difference(set2) difference1 = set1.difference(set2)
except TypeError, e: except TypeError as e:
self.fail('invalid type when attempting set difference: %s' % e) self.fail('invalid type when attempting set difference: %s' % e)
except AttributeError, e: except AttributeError as e:
self.fail('first argument does not support set difference: %s' % e) self.fail('first argument does not support set difference: %s' % e)
try: try:
difference2 = set2.difference(set1) difference2 = set2.difference(set1)
except TypeError, e: except TypeError as e:
self.fail('invalid type when attempting set difference: %s' % e) self.fail('invalid type when attempting set difference: %s' % e)
except AttributeError, e: except AttributeError as e:
self.fail('second argument does not support set difference: %s' % e) self.fail('second argument does not support set difference: %s' % e)
if not (difference1 or difference2): if not (difference1 or difference2):
@ -980,7 +980,7 @@ class TestCase(unittest.TestCase):
return _AssertRaisesContext(expected_exception, self, expected_regexp) return _AssertRaisesContext(expected_exception, self, expected_regexp)
try: try:
callable_obj(*args, **kwargs) callable_obj(*args, **kwargs)
except expected_exception, exc_value: except expected_exception as exc_value:
if isinstance(expected_regexp, basestring): if isinstance(expected_regexp, basestring):
expected_regexp = re.compile(expected_regexp) expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(str(exc_value)): if not expected_regexp.search(str(exc_value)):

View File

@ -89,7 +89,7 @@ class TestLoader(unittest.TestLoader):
if use_load_tests and load_tests is not None: if use_load_tests and load_tests is not None:
try: try:
return load_tests(self, tests, None) return load_tests(self, tests, None)
except Exception, e: except Exception as e:
return _make_failed_load_tests(module.__name__, e, return _make_failed_load_tests(module.__name__, e,
self.suiteClass) self.suiteClass)
return tests return tests
@ -295,7 +295,7 @@ class TestLoader(unittest.TestLoader):
else: else:
try: try:
yield load_tests(self, tests, pattern) yield load_tests(self, tests, pattern)
except Exception, e: except Exception as e:
yield _make_failed_load_tests(package.__name__, e, yield _make_failed_load_tests(package.__name__, e,
self.suiteClass) self.suiteClass)

View File

@ -150,7 +150,7 @@ class TestProgram(object):
else: else:
self.testNames = (self.defaultTest,) self.testNames = (self.defaultTest,)
self.createTests() self.createTests()
except getopt.error, msg: except getopt.error as msg:
self.usageExit(msg) self.usageExit(msg)
def createTests(self): def createTests(self):

View File

@ -138,7 +138,7 @@ class TestSuite(BaseTestSuite):
if setUpClass is not None: if setUpClass is not None:
try: try:
setUpClass() setUpClass()
except Exception, e: except Exception as e:
if isinstance(result, _DebugResult): if isinstance(result, _DebugResult):
raise raise
currentClass._classSetupFailed = True currentClass._classSetupFailed = True
@ -172,7 +172,7 @@ class TestSuite(BaseTestSuite):
if setUpModule is not None: if setUpModule is not None:
try: try:
setUpModule() setUpModule()
except Exception, e: except Exception as e:
if isinstance(result, _DebugResult): if isinstance(result, _DebugResult):
raise raise
result._moduleSetUpFailed = True result._moduleSetUpFailed = True
@ -203,7 +203,7 @@ class TestSuite(BaseTestSuite):
if tearDownModule is not None: if tearDownModule is not None:
try: try:
tearDownModule() tearDownModule()
except Exception, e: except Exception as e:
if isinstance(result, _DebugResult): if isinstance(result, _DebugResult):
raise raise
errorName = 'tearDownModule (%s)' % previousModule errorName = 'tearDownModule (%s)' % previousModule
@ -225,7 +225,7 @@ class TestSuite(BaseTestSuite):
if tearDownClass is not None: if tearDownClass is not None:
try: try:
tearDownClass() tearDownClass()
except Exception, e: except Exception as e:
if isinstance(result, _DebugResult): if isinstance(result, _DebugResult):
raise raise
className = util.strclass(previousClass) className = util.strclass(previousClass)