D3375: cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
This revision was automatically updated to reflect the committed changes. Closed by commit rHG1859b9a7ddef: cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp (authored by durin42, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D3375?vs=8281=8309 REVISION DETAIL https://phab.mercurial-scm.org/D3375 AFFECTED FILES tests/test-simplekeyvaluefile.py tests/test-wireproto-clientreactor.py tests/test-wireproto-framing.py tests/test-wsgirequest.py CHANGE DETAILS diff --git a/tests/test-wsgirequest.py b/tests/test-wsgirequest.py --- a/tests/test-wsgirequest.py +++ b/tests/test-wsgirequest.py @@ -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', diff --git a/tests/test-wireproto-framing.py b/tests/test-wireproto-framing.py --- a/tests/test-wireproto-framing.py +++ b/tests/test-wireproto-framing.py @@ -103,19 +103,25 @@ ffs(b'1 1 0 command-data eos %s' % data.getvalue()), ]) +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 testtextoutputformattingstringtype(self): """Formatting string must be bytes.""" -with self.assertRaisesRegexp(ValueError, 'must use bytes formatting '): +with self.assertRaisesRegex(ValueError, 'must use bytes formatting '): list(framing.createtextoutputframe(None, 1, [ (b'foo'.decode('ascii'), [], [])])) def testtextoutputargumentbytes(self): -with self.assertRaisesRegexp(ValueError, 'must use bytes for argument'): +with self.assertRaisesRegex(ValueError, 'must use bytes for argument'): list(framing.createtextoutputframe(None, 1, [ (b'foo', [b'foo'.decode('ascii')], [])])) def testtextoutputlabelbytes(self): -with self.assertRaisesRegexp(ValueError, 'must use bytes for labels'): +with self.assertRaisesRegex(ValueError, 'must use bytes for labels'): list(framing.createtextoutputframe(None, 1, [ (b'foo', [], [b'foo'.decode('ascii')])])) diff --git a/tests/test-wireproto-clientreactor.py b/tests/test-wireproto-clientreactor.py --- a/tests/test-wireproto-clientreactor.py +++ b/tests/test-wireproto-clientreactor.py @@ -24,6 +24,13 @@ class SingleSendTests(unittest.TestCase): """A reactor that can only send once rejects subsequent sends.""" + +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 testbasic(self): reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True) @@ -39,11 +46,11 @@ self.assertEqual(request.state, b'sent') -with self.assertRaisesRegexp(error.ProgrammingError, +with self.assertRaisesRegex(error.ProgrammingError, 'cannot issue new commands'): reactor.callcommand(b'foo', {}) -with self.assertRaisesRegexp(error.ProgrammingError, +with self.assertRaisesRegex(error.ProgrammingError, 'cannot issue new commands'): reactor.callcommand(b'foo', {}) @@ -77,6 +84,12 @@ self.assertEqual(request.state, b'sent') class
D3375: cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
durin42 updated this revision to Diff 8281. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D3375?vs=8280=8281 REVISION DETAIL https://phab.mercurial-scm.org/D3375 AFFECTED FILES tests/test-simplekeyvaluefile.py tests/test-wireproto-clientreactor.py tests/test-wireproto-framing.py tests/test-wsgirequest.py CHANGE DETAILS diff --git a/tests/test-wsgirequest.py b/tests/test-wsgirequest.py --- a/tests/test-wsgirequest.py +++ b/tests/test-wsgirequest.py @@ -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', diff --git a/tests/test-wireproto-framing.py b/tests/test-wireproto-framing.py --- a/tests/test-wireproto-framing.py +++ b/tests/test-wireproto-framing.py @@ -103,19 +103,25 @@ ffs(b'1 1 0 command-data eos %s' % data.getvalue()), ]) +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 testtextoutputformattingstringtype(self): """Formatting string must be bytes.""" -with self.assertRaisesRegexp(ValueError, 'must use bytes formatting '): +with self.assertRaisesRegex(ValueError, 'must use bytes formatting '): list(framing.createtextoutputframe(None, 1, [ (b'foo'.decode('ascii'), [], [])])) def testtextoutputargumentbytes(self): -with self.assertRaisesRegexp(ValueError, 'must use bytes for argument'): +with self.assertRaisesRegex(ValueError, 'must use bytes for argument'): list(framing.createtextoutputframe(None, 1, [ (b'foo', [b'foo'.decode('ascii')], [])])) def testtextoutputlabelbytes(self): -with self.assertRaisesRegexp(ValueError, 'must use bytes for labels'): +with self.assertRaisesRegex(ValueError, 'must use bytes for labels'): list(framing.createtextoutputframe(None, 1, [ (b'foo', [], [b'foo'.decode('ascii')])])) diff --git a/tests/test-wireproto-clientreactor.py b/tests/test-wireproto-clientreactor.py --- a/tests/test-wireproto-clientreactor.py +++ b/tests/test-wireproto-clientreactor.py @@ -24,6 +24,13 @@ class SingleSendTests(unittest.TestCase): """A reactor that can only send once rejects subsequent sends.""" + +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 testbasic(self): reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True) @@ -39,11 +46,11 @@ self.assertEqual(request.state, b'sent') -with self.assertRaisesRegexp(error.ProgrammingError, +with self.assertRaisesRegex(error.ProgrammingError, 'cannot issue new commands'): reactor.callcommand(b'foo', {}) -with self.assertRaisesRegexp(error.ProgrammingError, +with self.assertRaisesRegex(error.ProgrammingError, 'cannot issue new commands'): reactor.callcommand(b'foo', {}) @@ -77,6 +84,12 @@ self.assertEqual(request.state, b'sent') class BadFrameRecvTests(unittest.TestCase): +if not getattr(unittest.TestCase, 'assertRaisesRegex', False): +# Python 3.7 deprecates the regex*p* version, but 2.7 lacks +# the
D3375: cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
durin42 created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY The latter is deprecated on Python 3.7 and causes our tests to fail due to the warning. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D3375 AFFECTED FILES tests/test-simplekeyvaluefile.py tests/test-wireproto-clientreactor.py tests/test-wireproto-framing.py tests/test-wsgirequest.py CHANGE DETAILS diff --git a/tests/test-wsgirequest.py b/tests/test-wsgirequest.py --- a/tests/test-wsgirequest.py +++ b/tests/test-wsgirequest.py @@ -196,21 +196,26 @@ 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 = 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', diff --git a/tests/test-wireproto-framing.py b/tests/test-wireproto-framing.py --- a/tests/test-wireproto-framing.py +++ b/tests/test-wireproto-framing.py @@ -103,19 +103,24 @@ ffs(b'1 1 0 command-data eos %s' % data.getvalue()), ]) +if not getattr(unittest.TestCase, 'assertRaisesRegex', False): +# Python 3.7 deprecates the regex*p* version, but 2.7 lacks +# the regex version. +assertRaisesRegex = unittest.TestCase.assertRaisesRegexp + def testtextoutputformattingstringtype(self): """Formatting string must be bytes.""" -with self.assertRaisesRegexp(ValueError, 'must use bytes formatting '): +with self.assertRaisesRegex(ValueError, 'must use bytes formatting '): list(framing.createtextoutputframe(None, 1, [ (b'foo'.decode('ascii'), [], [])])) def testtextoutputargumentbytes(self): -with self.assertRaisesRegexp(ValueError, 'must use bytes for argument'): +with self.assertRaisesRegex(ValueError, 'must use bytes for argument'): list(framing.createtextoutputframe(None, 1, [ (b'foo', [b'foo'.decode('ascii')], [])])) def testtextoutputlabelbytes(self): -with self.assertRaisesRegexp(ValueError, 'must use bytes for labels'): +with self.assertRaisesRegex(ValueError, 'must use bytes for labels'): list(framing.createtextoutputframe(None, 1, [ (b'foo', [], [b'foo'.decode('ascii')])])) diff --git a/tests/test-wireproto-clientreactor.py b/tests/test-wireproto-clientreactor.py --- a/tests/test-wireproto-clientreactor.py +++ b/tests/test-wireproto-clientreactor.py @@ -24,6 +24,12 @@ class SingleSendTests(unittest.TestCase): """A reactor that can only send once rejects subsequent sends.""" + +if not getattr(unittest.TestCase, 'assertRaisesRegex', False): +# Python 3.7 deprecates the regex*p* version, but 2.7 lacks +# the regex version. +assertRaisesRegex = unittest.TestCase.assertRaisesRegexp + def testbasic(self): reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True) @@ -39,11 +45,11 @@ self.assertEqual(request.state, b'sent') -with self.assertRaisesRegexp(error.ProgrammingError, +with self.assertRaisesRegex(error.ProgrammingError, 'cannot issue new commands'): reactor.callcommand(b'foo', {}) -with self.assertRaisesRegexp(error.ProgrammingError, +with self.assertRaisesRegex(error.ProgrammingError, 'cannot issue new commands'): reactor.callcommand(b'foo', {}) @@ -77,6 +83,11 @@ self.assertEqual(request.state, b'sent') class BadFrameRecvTests(unittest.TestCase): +if not getattr(unittest.TestCase, 'assertRaisesRegex', False): +# Python 3.7 deprecates the regex*p* version, but 2.7 lacks +# the regex