Mercurial > public > mercurial-scm > hg
diff tests/test-wireproto-clientreactor.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 | cb71e0f9ac6f |
children | deff7cf7eefd |
line wrap: on
line diff
--- a/tests/test-wireproto-clientreactor.py Sat Apr 14 11:07:24 2018 -0400 +++ b/tests/test-wireproto-clientreactor.py Sat Apr 14 11:20:38 2018 -0400 @@ -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 regex version. + assertRaisesRegex = (# camelcase-required + unittest.TestCase.assertRaisesRegexp) + def testoddstream(self): reactor = framing.clientreactor() @@ -101,7 +114,7 @@ for frame in meta[b'framegen']: pass - with self.assertRaisesRegexp(error.ProgrammingError, + with self.assertRaisesRegex(error.ProgrammingError, 'unhandled frame type'): sendframe(reactor, ffs(b'1 0 stream-begin text-output 0 foo'))