]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#14179: add tests for re.compile. Patch by Florian Mladitsch.
authorEzio Melotti <ezio.melotti@gmail.com>
Mon, 12 Mar 2012 23:29:48 +0000 (01:29 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Mon, 12 Mar 2012 23:29:48 +0000 (01:29 +0200)
Lib/test/test_re.py
Misc/ACKS

index 4e18531803d25f8bf18fe8f7a64524673441be86..940ba390583905b5a608694be39ce30aebc5f9b8 100644 (file)
@@ -818,6 +818,16 @@ class ReTests(unittest.TestCase):
         self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
         self.assertRaises(TypeError, _sre.compile, {}, 0, [])
 
+    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 e7bc2b6c8bfa6a7f3c72fc5b1659f4c15031ace5..a7d89d39c42e1e8094ef0f70d52cba086a4b1405 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -629,6 +629,7 @@ Roman Milner
 Andrii V. Mishkovskyi
 Dustin J. Mitchell
 Dom Mitchell
+Florian Mladitsch
 Doug Moen
 The Dragon De Monsyne
 Skip Montanaro