diff tests/test-wsgirequest.py @ 37715:1859b9a7ddef

cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp The latter is deprecated on Python 3.7 and causes our tests to fail due to the warning. Differential Revision: https://phab.mercurial-scm.org/D3375
author Augie Fackler <augie@google.com>
date Sat, 14 Apr 2018 11:20:38 -0400
parents f0a851542a05
children e0598133ac68
line wrap: on
line diff
--- a/tests/test-wsgirequest.py	Sat Apr 14 11:07:24 2018 -0400
+++ b/tests/test-wsgirequest.py	Sat Apr 14 11:20:38 2018 -0400
@@ -196,21 +196,27 @@
         self.assertEqual(r.dispatchparts, [b'pathinfo'])
         self.assertEqual(r.dispatchpath, b'pathinfo')
 
+    if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
+        # Python 3.7 deprecates the regex*p* version, but 2.7 lacks
+        # the regex version.
+        assertRaisesRegex = (# camelcase-required
+            unittest.TestCase.assertRaisesRegexp)
+
     def testreponame(self):
         """repository path components get stripped from URL."""
 
-        with self.assertRaisesRegexp(error.ProgrammingError,
+        with self.assertRaisesRegex(error.ProgrammingError,
                                      b'reponame requires PATH_INFO'):
             parse(DEFAULT_ENV, reponame=b'repo')
 
-        with self.assertRaisesRegexp(error.ProgrammingError,
+        with self.assertRaisesRegex(error.ProgrammingError,
                                      b'PATH_INFO does not begin with repo '
                                      b'name'):
             parse(DEFAULT_ENV, reponame=b'repo', extra={
                 r'PATH_INFO': r'/pathinfo',
             })
 
-        with self.assertRaisesRegexp(error.ProgrammingError,
+        with self.assertRaisesRegex(error.ProgrammingError,
                                      b'reponame prefix of PATH_INFO'):
             parse(DEFAULT_ENV, reponame=b'repo', extra={
                 r'PATH_INFO': r'/repoextra/path',