From 4a71b842662162e0892a9269179421ff2191adba Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Mon, 24 Dec 2012 14:04:02 +0100 Subject: [PATCH] Fixed #19204 -- Replaced python2-style exception syntax. Thanks to garrison for the report and patch. --- django/utils/unittest/case.py | 16 ++++++++-------- django/utils/unittest/loader.py | 4 ++-- django/utils/unittest/main.py | 2 +- django/utils/unittest/suite.py | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/django/utils/unittest/case.py b/django/utils/unittest/case.py index f906a4cb686..fffd3c25245 100644 --- a/django/utils/unittest/case.py +++ b/django/utils/unittest/case.py @@ -324,7 +324,7 @@ class TestCase(unittest.TestCase): success = False try: self.setUp() - except SkipTest, e: + except SkipTest as e: self._addSkip(result, str(e)) except Exception: result.addError(self, sys.exc_info()) @@ -333,7 +333,7 @@ class TestCase(unittest.TestCase): testMethod() except self.failureException: result.addFailure(self, sys.exc_info()) - except _ExpectedFailure, e: + except _ExpectedFailure as e: addExpectedFailure = getattr(result, 'addExpectedFailure', None) if addExpectedFailure is not None: 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", DeprecationWarning) result.addFailure(self, sys.exc_info()) - except SkipTest, e: + except SkipTest as e: self._addSkip(result, str(e)) except Exception: result.addError(self, sys.exc_info()) @@ -770,16 +770,16 @@ class TestCase(unittest.TestCase): """ try: difference1 = set1.difference(set2) - except TypeError, e: + except TypeError as 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) try: difference2 = set2.difference(set1) - except TypeError, e: + except TypeError as 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) if not (difference1 or difference2): @@ -980,7 +980,7 @@ class TestCase(unittest.TestCase): return _AssertRaisesContext(expected_exception, self, expected_regexp) try: callable_obj(*args, **kwargs) - except expected_exception, exc_value: + except expected_exception as exc_value: if isinstance(expected_regexp, basestring): expected_regexp = re.compile(expected_regexp) if not expected_regexp.search(str(exc_value)): diff --git a/django/utils/unittest/loader.py b/django/utils/unittest/loader.py index 1ca910f0195..0bdd106d390 100644 --- a/django/utils/unittest/loader.py +++ b/django/utils/unittest/loader.py @@ -89,7 +89,7 @@ class TestLoader(unittest.TestLoader): if use_load_tests and load_tests is not None: try: return load_tests(self, tests, None) - except Exception, e: + except Exception as e: return _make_failed_load_tests(module.__name__, e, self.suiteClass) return tests @@ -295,7 +295,7 @@ class TestLoader(unittest.TestLoader): else: try: yield load_tests(self, tests, pattern) - except Exception, e: + except Exception as e: yield _make_failed_load_tests(package.__name__, e, self.suiteClass) diff --git a/django/utils/unittest/main.py b/django/utils/unittest/main.py index 0f25a98a22f..659310babf2 100644 --- a/django/utils/unittest/main.py +++ b/django/utils/unittest/main.py @@ -150,7 +150,7 @@ class TestProgram(object): else: self.testNames = (self.defaultTest,) self.createTests() - except getopt.error, msg: + except getopt.error as msg: self.usageExit(msg) def createTests(self): diff --git a/django/utils/unittest/suite.py b/django/utils/unittest/suite.py index f39569bbc29..da8ac2e2a8e 100644 --- a/django/utils/unittest/suite.py +++ b/django/utils/unittest/suite.py @@ -138,7 +138,7 @@ class TestSuite(BaseTestSuite): if setUpClass is not None: try: setUpClass() - except Exception, e: + except Exception as e: if isinstance(result, _DebugResult): raise currentClass._classSetupFailed = True @@ -172,7 +172,7 @@ class TestSuite(BaseTestSuite): if setUpModule is not None: try: setUpModule() - except Exception, e: + except Exception as e: if isinstance(result, _DebugResult): raise result._moduleSetUpFailed = True @@ -203,7 +203,7 @@ class TestSuite(BaseTestSuite): if tearDownModule is not None: try: tearDownModule() - except Exception, e: + except Exception as e: if isinstance(result, _DebugResult): raise errorName = 'tearDownModule (%s)' % previousModule @@ -225,7 +225,7 @@ class TestSuite(BaseTestSuite): if tearDownClass is not None: try: tearDownClass() - except Exception, e: + except Exception as e: if isinstance(result, _DebugResult): raise className = util.strclass(previousClass)