From 0e1f9173e28bc1056b1a5a6595a09e9d121dd2c6 Mon Sep 17 00:00:00 2001
From: Jim Garrison <garrison@wikiotics.org>
Date: Sat, 27 Oct 2012 18:46:27 -0700
Subject: [PATCH] [py3k] Use python3 syntax for exceptions in
django.utils.unittest
---
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 f906a4c..fffd3c2 100644
a
|
b
|
class TestCase(unittest.TestCase):
|
324 | 324 | success = False |
325 | 325 | try: |
326 | 326 | self.setUp() |
327 | | except SkipTest, e: |
| 327 | except SkipTest as e: |
328 | 328 | self._addSkip(result, str(e)) |
329 | 329 | except Exception: |
330 | 330 | result.addError(self, sys.exc_info()) |
… |
… |
class TestCase(unittest.TestCase):
|
333 | 333 | testMethod() |
334 | 334 | except self.failureException: |
335 | 335 | result.addFailure(self, sys.exc_info()) |
336 | | except _ExpectedFailure, e: |
| 336 | except _ExpectedFailure as e: |
337 | 337 | addExpectedFailure = getattr(result, 'addExpectedFailure', None) |
338 | 338 | if addExpectedFailure is not None: |
339 | 339 | addExpectedFailure(self, e.exc_info) |
… |
… |
class TestCase(unittest.TestCase):
|
349 | 349 | warnings.warn("Use of a TestResult without an addUnexpectedSuccess method is deprecated", |
350 | 350 | DeprecationWarning) |
351 | 351 | result.addFailure(self, sys.exc_info()) |
352 | | except SkipTest, e: |
| 352 | except SkipTest as e: |
353 | 353 | self._addSkip(result, str(e)) |
354 | 354 | except Exception: |
355 | 355 | result.addError(self, sys.exc_info()) |
… |
… |
class TestCase(unittest.TestCase):
|
770 | 770 | """ |
771 | 771 | try: |
772 | 772 | difference1 = set1.difference(set2) |
773 | | except TypeError, e: |
| 773 | except TypeError as e: |
774 | 774 | self.fail('invalid type when attempting set difference: %s' % e) |
775 | | except AttributeError, e: |
| 775 | except AttributeError as e: |
776 | 776 | self.fail('first argument does not support set difference: %s' % e) |
777 | 777 | |
778 | 778 | try: |
779 | 779 | difference2 = set2.difference(set1) |
780 | | except TypeError, e: |
| 780 | except TypeError as e: |
781 | 781 | self.fail('invalid type when attempting set difference: %s' % e) |
782 | | except AttributeError, e: |
| 782 | except AttributeError as e: |
783 | 783 | self.fail('second argument does not support set difference: %s' % e) |
784 | 784 | |
785 | 785 | if not (difference1 or difference2): |
… |
… |
class TestCase(unittest.TestCase):
|
980 | 980 | return _AssertRaisesContext(expected_exception, self, expected_regexp) |
981 | 981 | try: |
982 | 982 | callable_obj(*args, **kwargs) |
983 | | except expected_exception, exc_value: |
| 983 | except expected_exception as exc_value: |
984 | 984 | if isinstance(expected_regexp, basestring): |
985 | 985 | expected_regexp = re.compile(expected_regexp) |
986 | 986 | if not expected_regexp.search(str(exc_value)): |
diff --git a/django/utils/unittest/loader.py b/django/utils/unittest/loader.py
index 1ca910f..0bdd106 100644
a
|
b
|
class TestLoader(unittest.TestLoader):
|
89 | 89 | if use_load_tests and load_tests is not None: |
90 | 90 | try: |
91 | 91 | return load_tests(self, tests, None) |
92 | | except Exception, e: |
| 92 | except Exception as e: |
93 | 93 | return _make_failed_load_tests(module.__name__, e, |
94 | 94 | self.suiteClass) |
95 | 95 | return tests |
… |
… |
class TestLoader(unittest.TestLoader):
|
295 | 295 | else: |
296 | 296 | try: |
297 | 297 | yield load_tests(self, tests, pattern) |
298 | | except Exception, e: |
| 298 | except Exception as e: |
299 | 299 | yield _make_failed_load_tests(package.__name__, e, |
300 | 300 | self.suiteClass) |
301 | 301 | |
diff --git a/django/utils/unittest/main.py b/django/utils/unittest/main.py
index 0f25a98..659310b 100644
a
|
b
|
class TestProgram(object):
|
150 | 150 | else: |
151 | 151 | self.testNames = (self.defaultTest,) |
152 | 152 | self.createTests() |
153 | | except getopt.error, msg: |
| 153 | except getopt.error as msg: |
154 | 154 | self.usageExit(msg) |
155 | 155 | |
156 | 156 | def createTests(self): |
diff --git a/django/utils/unittest/suite.py b/django/utils/unittest/suite.py
index f39569b..da8ac2e 100644
a
|
b
|
class TestSuite(BaseTestSuite):
|
138 | 138 | if setUpClass is not None: |
139 | 139 | try: |
140 | 140 | setUpClass() |
141 | | except Exception, e: |
| 141 | except Exception as e: |
142 | 142 | if isinstance(result, _DebugResult): |
143 | 143 | raise |
144 | 144 | currentClass._classSetupFailed = True |
… |
… |
class TestSuite(BaseTestSuite):
|
172 | 172 | if setUpModule is not None: |
173 | 173 | try: |
174 | 174 | setUpModule() |
175 | | except Exception, e: |
| 175 | except Exception as e: |
176 | 176 | if isinstance(result, _DebugResult): |
177 | 177 | raise |
178 | 178 | result._moduleSetUpFailed = True |
… |
… |
class TestSuite(BaseTestSuite):
|
203 | 203 | if tearDownModule is not None: |
204 | 204 | try: |
205 | 205 | tearDownModule() |
206 | | except Exception, e: |
| 206 | except Exception as e: |
207 | 207 | if isinstance(result, _DebugResult): |
208 | 208 | raise |
209 | 209 | errorName = 'tearDownModule (%s)' % previousModule |
… |
… |
class TestSuite(BaseTestSuite):
|
225 | 225 | if tearDownClass is not None: |
226 | 226 | try: |
227 | 227 | tearDownClass() |
228 | | except Exception, e: |
| 228 | except Exception as e: |
229 | 229 | if isinstance(result, _DebugResult): |
230 | 230 | raise |
231 | 231 | className = util.strclass(previousClass) |