Ticket #19204: 0001-py3k-Use-python3-syntax-for-exceptions-in-django.uti.patch

File 0001-py3k-Use-python3-syntax-for-exceptions-in-django.uti.patch, 6.2 KB (added by Jim Garrison, 12 years ago)
  • django/utils/unittest/case.py

    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):  
    324324            success = False
    325325            try:
    326326                self.setUp()
    327             except SkipTest, e:
     327            except SkipTest as e:
    328328                self._addSkip(result, str(e))
    329329            except Exception:
    330330                result.addError(self, sys.exc_info())
    class TestCase(unittest.TestCase):  
    333333                    testMethod()
    334334                except self.failureException:
    335335                    result.addFailure(self, sys.exc_info())
    336                 except _ExpectedFailure, e:
     336                except _ExpectedFailure as e:
    337337                    addExpectedFailure = getattr(result, 'addExpectedFailure', None)
    338338                    if addExpectedFailure is not None:
    339339                        addExpectedFailure(self, e.exc_info)
    class TestCase(unittest.TestCase):  
    349349                        warnings.warn("Use of a TestResult without an addUnexpectedSuccess method is deprecated",
    350350                                      DeprecationWarning)
    351351                        result.addFailure(self, sys.exc_info())
    352                 except SkipTest, e:
     352                except SkipTest as e:
    353353                    self._addSkip(result, str(e))
    354354                except Exception:
    355355                    result.addError(self, sys.exc_info())
    class TestCase(unittest.TestCase):  
    770770        """
    771771        try:
    772772            difference1 = set1.difference(set2)
    773         except TypeError, e:
     773        except TypeError as e:
    774774            self.fail('invalid type when attempting set difference: %s' % e)
    775         except AttributeError, e:
     775        except AttributeError as e:
    776776            self.fail('first argument does not support set difference: %s' % e)
    777777
    778778        try:
    779779            difference2 = set2.difference(set1)
    780         except TypeError, e:
     780        except TypeError as e:
    781781            self.fail('invalid type when attempting set difference: %s' % e)
    782         except AttributeError, e:
     782        except AttributeError as e:
    783783            self.fail('second argument does not support set difference: %s' % e)
    784784
    785785        if not (difference1 or difference2):
    class TestCase(unittest.TestCase):  
    980980            return _AssertRaisesContext(expected_exception, self, expected_regexp)
    981981        try:
    982982            callable_obj(*args, **kwargs)
    983         except expected_exception, exc_value:
     983        except expected_exception as exc_value:
    984984            if isinstance(expected_regexp, basestring):
    985985                expected_regexp = re.compile(expected_regexp)
    986986            if not expected_regexp.search(str(exc_value)):
  • django/utils/unittest/loader.py

    diff --git a/django/utils/unittest/loader.py b/django/utils/unittest/loader.py
    index 1ca910f..0bdd106 100644
    a b class TestLoader(unittest.TestLoader):  
    8989        if use_load_tests and load_tests is not None:
    9090            try:
    9191                return load_tests(self, tests, None)
    92             except Exception, e:
     92            except Exception as e:
    9393                return _make_failed_load_tests(module.__name__, e,
    9494                                               self.suiteClass)
    9595        return tests
    class TestLoader(unittest.TestLoader):  
    295295                else:
    296296                    try:
    297297                        yield load_tests(self, tests, pattern)
    298                     except Exception, e:
     298                    except Exception as e:
    299299                        yield _make_failed_load_tests(package.__name__, e,
    300300                                                      self.suiteClass)
    301301
  • django/utils/unittest/main.py

    diff --git a/django/utils/unittest/main.py b/django/utils/unittest/main.py
    index 0f25a98..659310b 100644
    a b class TestProgram(object):  
    150150            else:
    151151                self.testNames = (self.defaultTest,)
    152152            self.createTests()
    153         except getopt.error, msg:
     153        except getopt.error as msg:
    154154            self.usageExit(msg)
    155155
    156156    def createTests(self):
  • django/utils/unittest/suite.py

    diff --git a/django/utils/unittest/suite.py b/django/utils/unittest/suite.py
    index f39569b..da8ac2e 100644
    a b class TestSuite(BaseTestSuite):  
    138138        if setUpClass is not None:
    139139            try:
    140140                setUpClass()
    141             except Exception, e:
     141            except Exception as e:
    142142                if isinstance(result, _DebugResult):
    143143                    raise
    144144                currentClass._classSetupFailed = True
    class TestSuite(BaseTestSuite):  
    172172        if setUpModule is not None:
    173173            try:
    174174                setUpModule()
    175             except Exception, e:
     175            except Exception as e:
    176176                if isinstance(result, _DebugResult):
    177177                    raise
    178178                result._moduleSetUpFailed = True
    class TestSuite(BaseTestSuite):  
    203203        if tearDownModule is not None:
    204204            try:
    205205                tearDownModule()
    206             except Exception, e:
     206            except Exception as e:
    207207                if isinstance(result, _DebugResult):
    208208                    raise
    209209                errorName = 'tearDownModule (%s)' % previousModule
    class TestSuite(BaseTestSuite):  
    225225        if tearDownClass is not None:
    226226            try:
    227227                tearDownClass()
    228             except Exception, e:
     228            except Exception as e:
    229229                if isinstance(result, _DebugResult):
    230230                    raise
    231231                className = util.strclass(previousClass)
Back to Top