diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-06-15 13:55:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-15 13:55:22 (GMT) |
commit | 523a243840feb4d5f444a1b128e540876afac3d2 (patch) | |
tree | 25f46a1865e7e2f584a7d73c03ca9d650edd3dd1 /Lib/test | |
parent | 86b95370c45dedb8a56c9894372a43681de47a73 (diff) | |
download | cpython-523a243840feb4d5f444a1b128e540876afac3d2.zip cpython-523a243840feb4d5f444a1b128e540876afac3d2.tar.gz cpython-523a243840feb4d5f444a1b128e540876afac3d2.tar.bz2 |
[3.6] bpo-30605: Fix compiling binary regexs with BytesWarnings enabled. (GH-2016) (#2214)
Running our unit tests with `-bb` enabled triggered this failure..
(cherry picked from commit 171b9a354e816eebc6d4c3a8553303942e9c5025)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_re.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index e88d0b3..a6cbbd0 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1346,7 +1346,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__) @@ -1355,10 +1355,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): |