diff tests/test-wireproto-framing.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 1ec5ce21cb46
children fcc6bd11444b
line wrap: on
line diff
--- a/tests/test-wireproto-framing.py	Sat Apr 14 11:07:24 2018 -0400
+++ b/tests/test-wireproto-framing.py	Sat Apr 14 11:20:38 2018 -0400
@@ -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')])]))