Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df723e1

Browse files
committed
#14179: add tests for re.compile. Patch by Florian Mladitsch.
1 parent 1d4798c commit df723e1

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/test/test_re.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,16 @@ def test_dealloc(self):
818818
self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
819819
self.assertRaises(TypeError, _sre.compile, {}, 0, [])
820820

821+
def test_compile(self):
822+
# Test return value when given string and pattern as parameter
823+
pattern = re.compile('random pattern')
824+
self.assertIsInstance(pattern, re._pattern_type)
825+
same_pattern = re.compile(pattern)
826+
self.assertIsInstance(same_pattern, re._pattern_type)
827+
self.assertIs(same_pattern, pattern)
828+
# Test behaviour when not given a string or pattern as parameter
829+
self.assertRaises(TypeError, re.compile, 0)
830+
821831
def run_re_tests():
822832
from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
823833
if verbose:

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ Roman Milner
629629
Andrii V. Mishkovskyi
630630
Dustin J. Mitchell
631631
Dom Mitchell
632+
Florian Mladitsch
632633
Doug Moen
633634
The Dragon De Monsyne
634635
Skip Montanaro

0 commit comments

Comments
 (0)