]> granicus.if.org Git - python/commitdiff
#14179: add tests for re.compile. Patch by Florian Mladitsch.
authorEzio Melotti <ezio.melotti@gmail.com>
Mon, 12 Mar 2012 23:25:40 +0000 (01:25 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Mon, 12 Mar 2012 23:25:40 +0000 (01:25 +0200)
Lib/test/test_re.py
Misc/ACKS

index b19834cae63e81740a8e6c9c40b5f5564658cd63..6f6d014cb1c64d3693474464c5dcbea9b59aa994 100644 (file)
@@ -783,6 +783,16 @@ class ReTests(unittest.TestCase):
         self.assertRaises(TypeError, re.finditer, "a", {})
         self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
 
+    def test_compile(self):
+        # Test return value when given string and pattern as parameter
+        pattern = re.compile('random pattern')
+        self.assertIsInstance(pattern, re._pattern_type)
+        same_pattern = re.compile(pattern)
+        self.assertIsInstance(same_pattern, re._pattern_type)
+        self.assertIs(same_pattern, pattern)
+        # Test behaviour when not given a string or pattern as parameter
+        self.assertRaises(TypeError, re.compile, 0)
+
 def run_re_tests():
     from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
     if verbose:
index b51de26d225eaa0b6c459d0481cd8526748bc3b0..dc6d749190ca1a4dcf6314dcc05355b463e98a24 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -577,6 +577,7 @@ Roman Milner
 Andrii V. Mishkovskyi
 Dustin J. Mitchell
 Dom Mitchell
+Florian Mladitsch
 Doug Moen
 The Dragon De Monsyne
 Skip Montanaro