summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_re.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r--Lib/test/test_re.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 52ee616..3752d73 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -2386,6 +2386,30 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.fullmatch(r'(?s:(?>.*?\.).*)\Z', "a.txt")) # reproducer
self.assertTrue(re.fullmatch(r'(?s:(?=(?P<g0>.*?\.))(?P=g0).*)\Z', "a.txt"))
+ def test_template_function_and_flag_is_deprecated(self):
+ with self.assertWarns(DeprecationWarning) as cm:
+ template_re1 = re.template(r'a')
+ self.assertIn('re.template()', str(cm.warning))
+ self.assertIn('is deprecated', str(cm.warning))
+ self.assertIn('function', str(cm.warning))
+ self.assertNotIn('flag', str(cm.warning))
+
+ with self.assertWarns(DeprecationWarning) as cm:
+ # we deliberately use more flags here to test that that still
+ # triggers the warning
+ # if paranoid, we could test multiple different combinations,
+ # but it's probably not worth it
+ template_re2 = re.compile(r'a', flags=re.TEMPLATE|re.UNICODE)
+ self.assertIn('re.TEMPLATE', str(cm.warning))
+ self.assertIn('is deprecated', str(cm.warning))
+ self.assertIn('flag', str(cm.warning))
+ self.assertNotIn('function', str(cm.warning))
+
+ # while deprecated, is should still function
+ self.assertEqual(template_re1, template_re2)
+ self.assertTrue(template_re1.match('ahoy'))
+ self.assertFalse(template_re1.match('nope'))
+
def get_debug_out(pat):
with captured_stdout() as out:
@@ -2580,11 +2604,11 @@ class PatternReprTests(unittest.TestCase):
"re.IGNORECASE|re.DOTALL|re.VERBOSE|0x100000")
self.assertEqual(
repr(~re.I),
- "re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DOTALL|re.VERBOSE|re.DEBUG|0x1")
+ "re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DOTALL|re.VERBOSE|re.TEMPLATE|re.DEBUG")
self.assertEqual(repr(~(re.I|re.S|re.X)),
- "re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DEBUG|0x1")
+ "re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.TEMPLATE|re.DEBUG")
self.assertEqual(repr(~(re.I|re.S|re.X|(1<<20))),
- "re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.DEBUG|0xffe01")
+ "re.ASCII|re.LOCALE|re.UNICODE|re.MULTILINE|re.TEMPLATE|re.DEBUG|0xffe00")
class ImplementationTest(unittest.TestCase):