From 171b9a354e816eebc6d4c3a8553303942e9c5025 Mon Sep 17 00:00:00 2001 From: Roy Williams Date: Fri, 9 Jun 2017 22:01:16 -0700 Subject: bpo-30605: Fix compiling binary regexs with BytesWarnings enabled. (#2016) Running our unit tests with `-bb` enabled triggered this failure. --- Lib/test/test_re.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Lib/test/test_re.py') diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 027df4092d..0ea5a20469 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1368,7 +1368,7 @@ class ReTests(unittest.TestCase): self.assertTrue(re.match(p, lower_char)) self.assertEqual( str(warns.warnings[0].message), - 'Flags not at the start of the expression %s' % p + 'Flags not at the start of the expression %r' % p ) self.assertEqual(warns.warnings[0].filename, __file__) @@ -1377,10 +1377,22 @@ class ReTests(unittest.TestCase): self.assertTrue(re.match(p, lower_char)) self.assertEqual( str(warns.warnings[0].message), - 'Flags not at the start of the expression %s (truncated)' % p[:20] + 'Flags not at the start of the expression %r (truncated)' % p[:20] ) self.assertEqual(warns.warnings[0].filename, __file__) + # bpo-30605: Compiling a bytes instance regex was throwing a BytesWarning + with warnings.catch_warnings(): + warnings.simplefilter('error', BytesWarning) + p = b'A(?i)' + with self.assertWarns(DeprecationWarning) as warns: + self.assertTrue(re.match(p, b'a')) + self.assertEqual( + str(warns.warnings[0].message), + 'Flags not at the start of the expression %r' % p + ) + self.assertEqual(warns.warnings[0].filename, __file__) + with self.assertWarns(DeprecationWarning): self.assertTrue(re.match('(?s).(?i)' + upper_char, '\n' + lower_char)) with self.assertWarns(DeprecationWarning): -- cgit v1.2.1