Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(120551)

Delta Between Two Patch Sets: Lib/test/test_re.py

Issue 12759: "(?P=)" input for Tools/scripts/redemo.py raises unnhandled exception
Left Patch Set: Created 7 years, 12 months ago
Right Patch Set: Created 7 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/sre_parse.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 from test.support import verbose, run_unittest 1 from test.support import verbose, run_unittest, gc_collect
2 import io
2 import re 3 import re
3 from re import Scanner 4 from re import Scanner
4 import sys 5 import sys
5 import string 6 import string
6 import traceback 7 import traceback
7 from weakref import proxy 8 from weakref import proxy
8 9
9 # Misc tests from Tim Peters' re.doc 10 # Misc tests from Tim Peters' re.doc
10 11
11 # WARNING: Don't change details in these tests if you don't know 12 # WARNING: Don't change details in these tests if you don't know
12 # what you're doing. Some of these tests were carefully modeled to 13 # what you're doing. Some of these tests were carefully modeled to
13 # cover most of the code. 14 # cover most of the code.
14 15
15 import unittest 16 import unittest
16 17
17 class ReTests(unittest.TestCase): 18 class ReTests(unittest.TestCase):
19
20 def test_keep_buffer(self):
21 # See bug 14212
22 b = bytearray(b'x')
23 it = re.finditer(b'a', b)
24 with self.assertRaises(BufferError):
25 b.extend(b'x'*400)
26 list(it)
27 del it
28 gc_collect()
29 b.extend(b'x'*400)
18 30
19 def test_weakref(self): 31 def test_weakref(self):
20 s = 'QabbbcR' 32 s = 'QabbbcR'
21 x = re.compile('ab+c') 33 x = re.compile('ab+c')
22 y = proxy(x) 34 y = proxy(x)
23 self.assertEqual(x.findall('QabbbcR'), y.findall('QabbbcR')) 35 self.assertEqual(x.findall('QabbbcR'), y.findall('QabbbcR'))
24 36
25 def test_search_star_plus(self): 37 def test_search_star_plus(self):
26 self.assertEqual(re.search('x*', 'axx').span(0), (0, 0)) 38 self.assertEqual(re.search('x*', 'axx').span(0), (0, 0))
27 self.assertEqual(re.search('x*', 'axx').span(), (0, 0)) 39 self.assertEqual(re.search('x*', 'axx').span(), (0, 0))
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 154
143 def test_bug_114660(self): 155 def test_bug_114660(self):
144 self.assertEqual(re.sub(r'(\S)\s+(\S)', r'\1 \2', 'hello there'), 156 self.assertEqual(re.sub(r'(\S)\s+(\S)', r'\1 \2', 'hello there'),
145 'hello there') 157 'hello there')
146 158
147 def test_bug_462270(self): 159 def test_bug_462270(self):
148 # Test for empty sub() behaviour, see SF bug #462270 160 # Test for empty sub() behaviour, see SF bug #462270
149 self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-') 161 self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-')
150 self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d') 162 self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')
151 163
164 def test_symbolic_groups(self):
165 re.compile('(?P<a>x)(?P=a)(?(a)y)')
166 re.compile('(?P<a1>x)(?P=a1)(?(a1)y)')
167 self.assertRaises(re.error, re.compile, '(?P<a>)(?P<a>)')
168 self.assertRaises(re.error, re.compile, '(?Px)')
169 self.assertRaises(re.error, re.compile, '(?P=)')
170 self.assertRaises(re.error, re.compile, '(?P=1)')
171 self.assertRaises(re.error, re.compile, '(?P=a.)')
172 self.assertRaises(re.error, re.compile, '(?P<)')
173 self.assertRaises(re.error, re.compile, '(?P<>)')
174 self.assertRaises(re.error, re.compile, '(?P<1>)')
175 self.assertRaises(re.error, re.compile, '(?P<a.>)')
176 self.assertRaises(re.error, re.compile, '(?())')
177 self.assertRaises(re.error, re.compile, '(?(a))')
178 self.assertRaises(re.error, re.compile, '(?(1a))')
179 self.assertRaises(re.error, re.compile, '(?(a.))')
180
152 def test_symbolic_refs(self): 181 def test_symbolic_refs(self):
153 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx') 182 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
154 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx') 183 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx')
155 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx') 184 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx')
156 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx') 185 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx')
157 self.assertRaises(re.error, re.sub, '(?P=)' , '\g', 'xx') 186 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<>', 'xx')
158 self.assertRaises(re.error, re.sub, '(?P<>)' , '\g', 'xx')
159 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx') 187 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx')
160 self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx') 188 self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx')
161 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx') 189 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
162 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx') 190 self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx')
163 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx') 191 self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx')
164 192
165 def test_re_subn(self): 193 def test_re_subn(self):
166 self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2)) 194 self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))
167 self.assertEqual(re.subn("b+", "x", "bbbb BBBB"), ('x BBBB', 1)) 195 self.assertEqual(re.subn("b+", "x", "bbbb BBBB"), ('x BBBB', 1))
168 self.assertEqual(re.subn("b+", "x", "xyz"), ('xyz', 0)) 196 self.assertEqual(re.subn("b+", "x", "xyz"), ('xyz', 0))
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc") 378 self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc")
351 self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc") 379 self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc")
352 self.assertEqual(re.search(r"^\Aabc\Z$", "\nabc\n", re.M), None) 380 self.assertEqual(re.search(r"^\Aabc\Z$", "\nabc\n", re.M), None)
353 self.assertEqual(re.search(r"\d\D\w\W\s\S", 381 self.assertEqual(re.search(r"\d\D\w\W\s\S",
354 "1aa! a").group(0), "1aa! a") 382 "1aa! a").group(0), "1aa! a")
355 self.assertEqual(re.search(r"\d\D\w\W\s\S", 383 self.assertEqual(re.search(r"\d\D\w\W\s\S",
356 "1aa! a", re.LOCALE).group(0), "1aa! a") 384 "1aa! a", re.LOCALE).group(0), "1aa! a")
357 self.assertEqual(re.search(r"\d\D\w\W\s\S", 385 self.assertEqual(re.search(r"\d\D\w\W\s\S",
358 "1aa! a", re.UNICODE).group(0), "1aa! a") 386 "1aa! a", re.UNICODE).group(0), "1aa! a")
359 387
388 def test_string_boundaries(self):
389 # See http://bugs.python.org/issue10713
390 self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1),
391 "abc")
392 # There's a word boundary at the start of a string.
393 self.assertTrue(re.match(r"\b", "abc"))
394 # A non-empty string includes a non-boundary zero-length match.
395 self.assertTrue(re.search(r"\B", "abc"))
396 # There is no non-boundary match at the start of a string.
397 self.assertFalse(re.match(r"\B", "abc"))
398 # However, an empty string contains no word boundaries, and also no
399 # non-boundaries.
400 self.assertEqual(re.search(r"\B", ""), None)
401 # This one is questionable and different from the perlre behaviour,
402 # but describes current behavior.
403 self.assertEqual(re.search(r"\b", ""), None)
404 # A single word-character string has two boundaries, but no
405 # non-boundary gaps.
406 self.assertEqual(len(re.findall(r"\b", "a")), 2)
407 self.assertEqual(len(re.findall(r"\B", "a")), 0)
408 # If there are no words, there are no boundaries
409 self.assertEqual(len(re.findall(r"\b", " ")), 0)
410 self.assertEqual(len(re.findall(r"\b", " ")), 0)
411 # Can match around the whitespace.
412 self.assertEqual(len(re.findall(r"\B", " ")), 2)
413
360 def test_bigcharset(self): 414 def test_bigcharset(self):
361 self.assertEqual(re.match("([\u2222\u2223])", 415 self.assertEqual(re.match("([\u2222\u2223])",
362 "\u2222").group(1), "\u2222") 416 "\u2222").group(1), "\u2222")
363 self.assertEqual(re.match("([\u2222\u2223])", 417 self.assertEqual(re.match("([\u2222\u2223])",
364 "\u2222", re.UNICODE).group(1), "\u2222") 418 "\u2222", re.UNICODE).group(1), "\u2222")
365 419
366 def test_anyall(self): 420 def test_anyall(self):
367 self.assertEqual(re.match("a.b", "a\nb", re.DOTALL).group(0), 421 self.assertEqual(re.match("a.b", "a\nb", re.DOTALL).group(0),
368 "a\nb") 422 "a\nb")
369 self.assertEqual(re.match("a.*b", "a\n\nb", re.DOTALL).group(0), 423 self.assertEqual(re.match("a.*b", "a\n\nb", re.DOTALL).group(0),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 self.assertEqual(re.L, re.LOCALE) 537 self.assertEqual(re.L, re.LOCALE)
484 self.assertEqual(re.M, re.MULTILINE) 538 self.assertEqual(re.M, re.MULTILINE)
485 self.assertEqual(re.S, re.DOTALL) 539 self.assertEqual(re.S, re.DOTALL)
486 self.assertEqual(re.X, re.VERBOSE) 540 self.assertEqual(re.X, re.VERBOSE)
487 541
488 def test_flags(self): 542 def test_flags(self):
489 for flag in [re.I, re.M, re.X, re.S, re.L]: 543 for flag in [re.I, re.M, re.X, re.S, re.L]:
490 self.assertNotEqual(re.compile('^pattern$', flag), None) 544 self.assertNotEqual(re.compile('^pattern$', flag), None)
491 545
492 def test_sre_character_literals(self): 546 def test_sre_character_literals(self):
547 for i in [0, 8, 16, 32, 64, 127, 128, 255, 256, 0xFFFF, 0x10000, 0x10FFF F]:
548 if i < 256:
549 self.assertIsNotNone(re.match(r"\%03o" % i, chr(i)))
550 self.assertIsNotNone(re.match(r"\%03o0" % i, chr(i)+"0"))
551 self.assertIsNotNone(re.match(r"\%03o8" % i, chr(i)+"8"))
552 self.assertIsNotNone(re.match(r"\x%02x" % i, chr(i)))
553 self.assertIsNotNone(re.match(r"\x%02x0" % i, chr(i)+"0"))
554 self.assertIsNotNone(re.match(r"\x%02xz" % i, chr(i)+"z"))
555 if i < 0x10000:
556 self.assertIsNotNone(re.match(r"\u%04x" % i, chr(i)))
557 self.assertIsNotNone(re.match(r"\u%04x0" % i, chr(i)+"0"))
558 self.assertIsNotNone(re.match(r"\u%04xz" % i, chr(i)+"z"))
559 self.assertIsNotNone(re.match(r"\U%08x" % i, chr(i)))
560 self.assertIsNotNone(re.match(r"\U%08x0" % i, chr(i)+"0"))
561 self.assertIsNotNone(re.match(r"\U%08xz" % i, chr(i)+"z"))
562 self.assertIsNotNone(re.match(r"\0", "\000"))
563 self.assertIsNotNone(re.match(r"\08", "\0008"))
564 self.assertIsNotNone(re.match(r"\01", "\001"))
565 self.assertIsNotNone(re.match(r"\018", "\0018"))
566 self.assertIsNotNone(re.match(r"\567", chr(0o167)))
567 self.assertRaises(re.error, re.match, r"\911", "")
568 self.assertRaises(re.error, re.match, r"\x1", "")
569 self.assertRaises(re.error, re.match, r"\x1z", "")
570 self.assertRaises(re.error, re.match, r"\u123", "")
571 self.assertRaises(re.error, re.match, r"\u123z", "")
572 self.assertRaises(re.error, re.match, r"\U0001234", "")
573 self.assertRaises(re.error, re.match, r"\U0001234z", "")
574 self.assertRaises(re.error, re.match, r"\U00110000", "")
575
576 def test_sre_character_class_literals(self):
577 for i in [0, 8, 16, 32, 64, 127, 128, 255, 256, 0xFFFF, 0x10000, 0x10FFF F]:
578 if i < 256:
579 self.assertIsNotNone(re.match(r"[\%o]" % i, chr(i)))
580 self.assertIsNotNone(re.match(r"[\%o8]" % i, chr(i)))
581 self.assertIsNotNone(re.match(r"[\%03o]" % i, chr(i)))
582 self.assertIsNotNone(re.match(r"[\%03o0]" % i, chr(i)))
583 self.assertIsNotNone(re.match(r"[\%03o8]" % i, chr(i)))
584 self.assertIsNotNone(re.match(r"[\x%02x]" % i, chr(i)))
585 self.assertIsNotNone(re.match(r"[\x%02x0]" % i, chr(i)))
586 self.assertIsNotNone(re.match(r"[\x%02xz]" % i, chr(i)))
587 if i < 0x10000:
588 self.assertIsNotNone(re.match(r"[\u%04x]" % i, chr(i)))
589 self.assertIsNotNone(re.match(r"[\u%04x0]" % i, chr(i)))
590 self.assertIsNotNone(re.match(r"[\u%04xz]" % i, chr(i)))
591 self.assertIsNotNone(re.match(r"[\U%08x]" % i, chr(i)))
592 self.assertIsNotNone(re.match(r"[\U%08x0]" % i, chr(i)+"0"))
593 self.assertIsNotNone(re.match(r"[\U%08xz]" % i, chr(i)+"z"))
594 self.assertRaises(re.error, re.match, r"[\911]", "")
595 self.assertRaises(re.error, re.match, r"[\x1z]", "")
596 self.assertRaises(re.error, re.match, r"[\u123z]", "")
597 self.assertRaises(re.error, re.match, r"[\U0001234z]", "")
598 self.assertRaises(re.error, re.match, r"[\U00110000]", "")
599
600 def test_sre_byte_literals(self):
493 for i in [0, 8, 16, 32, 64, 127, 128, 255]: 601 for i in [0, 8, 16, 32, 64, 127, 128, 255]:
494 self.assertNotEqual(re.match(r"\%03o" % i, chr(i)), None) 602 self.assertIsNotNone(re.match((r"\%03o" % i).encode(), bytes([i])))
495 self.assertNotEqual(re.match(r"\%03o0" % i, chr(i)+"0"), None) 603 self.assertIsNotNone(re.match((r"\%03o0" % i).encode(), bytes([i])+b "0"))
496 self.assertNotEqual(re.match(r"\%03o8" % i, chr(i)+"8"), None) 604 self.assertIsNotNone(re.match((r"\%03o8" % i).encode(), bytes([i])+b "8"))
497 self.assertNotEqual(re.match(r"\x%02x" % i, chr(i)), None) 605 self.assertIsNotNone(re.match((r"\x%02x" % i).encode(), bytes([i])))
498 self.assertNotEqual(re.match(r"\x%02x0" % i, chr(i)+"0"), None) 606 self.assertIsNotNone(re.match((r"\x%02x0" % i).encode(), bytes([i])+ b"0"))
499 self.assertNotEqual(re.match(r"\x%02xz" % i, chr(i)+"z"), None) 607 self.assertIsNotNone(re.match((r"\x%02xz" % i).encode(), bytes([i])+ b"z"))
500 self.assertRaises(re.error, re.match, "\911", "") 608 self.assertIsNotNone(re.match(br"\u", b'u'))
501 609 self.assertIsNotNone(re.match(br"\U", b'U'))
502 def test_sre_character_class_literals(self): 610 self.assertIsNotNone(re.match(br"\0", b"\000"))
611 self.assertIsNotNone(re.match(br"\08", b"\0008"))
612 self.assertIsNotNone(re.match(br"\01", b"\001"))
613 self.assertIsNotNone(re.match(br"\018", b"\0018"))
614 self.assertIsNotNone(re.match(br"\567", bytes([0o167])))
615 self.assertRaises(re.error, re.match, br"\911", b"")
616 self.assertRaises(re.error, re.match, br"\x1", b"")
617 self.assertRaises(re.error, re.match, br"\x1z", b"")
618
619 def test_sre_byte_class_literals(self):
503 for i in [0, 8, 16, 32, 64, 127, 128, 255]: 620 for i in [0, 8, 16, 32, 64, 127, 128, 255]:
504 self.assertNotEqual(re.match(r"[\%03o]" % i, chr(i)), None) 621 self.assertIsNotNone(re.match((r"[\%o]" % i).encode(), bytes([i])))
505 self.assertNotEqual(re.match(r"[\%03o0]" % i, chr(i)), None) 622 self.assertIsNotNone(re.match((r"[\%o8]" % i).encode(), bytes([i])))
506 self.assertNotEqual(re.match(r"[\%03o8]" % i, chr(i)), None) 623 self.assertIsNotNone(re.match((r"[\%03o]" % i).encode(), bytes([i])) )
507 self.assertNotEqual(re.match(r"[\x%02x]" % i, chr(i)), None) 624 self.assertIsNotNone(re.match((r"[\%03o0]" % i).encode(), bytes([i]) ))
508 self.assertNotEqual(re.match(r"[\x%02x0]" % i, chr(i)), None) 625 self.assertIsNotNone(re.match((r"[\%03o8]" % i).encode(), bytes([i]) ))
509 self.assertNotEqual(re.match(r"[\x%02xz]" % i, chr(i)), None) 626 self.assertIsNotNone(re.match((r"[\x%02x]" % i).encode(), bytes([i]) ))
510 self.assertRaises(re.error, re.match, "[\911]", "") 627 self.assertIsNotNone(re.match((r"[\x%02x0]" % i).encode(), bytes([i] )))
628 self.assertIsNotNone(re.match((r"[\x%02xz]" % i).encode(), bytes([i] )))
629 self.assertIsNotNone(re.match(br"[\u]", b'u'))
630 self.assertIsNotNone(re.match(br"[\U]", b'U'))
631 self.assertRaises(re.error, re.match, br"[\911]", "")
632 self.assertRaises(re.error, re.match, br"[\x1z]", "")
511 633
512 def test_bug_113254(self): 634 def test_bug_113254(self):
513 self.assertEqual(re.match(r'(a)|(b)', 'b').start(1), -1) 635 self.assertEqual(re.match(r'(a)|(b)', 'b').start(1), -1)
514 self.assertEqual(re.match(r'(a)|(b)', 'b').end(1), -1) 636 self.assertEqual(re.match(r'(a)|(b)', 'b').end(1), -1)
515 self.assertEqual(re.match(r'(a)|(b)', 'b').span(1), (-1, -1)) 637 self.assertEqual(re.match(r'(a)|(b)', 'b').span(1), (-1, -1))
516 638
517 def test_bug_527371(self): 639 def test_bug_527371(self):
518 # bug described in patches 527371/672491 640 # bug described in patches 527371/672491
519 self.assertEqual(re.match(r'(a)?a','a').lastindex, None) 641 self.assertEqual(re.match(r'(a)?a','a').lastindex, None)
520 self.assertEqual(re.match(r'(a)(b)?b','ab').lastindex, 1) 642 self.assertEqual(re.match(r'(a)(b)?b','ab').lastindex, 1)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 def test_bug_764548(self): 730 def test_bug_764548(self):
609 # bug 764548, re.compile() barfs on str/unicode subclasses 731 # bug 764548, re.compile() barfs on str/unicode subclasses
610 class my_unicode(str): pass 732 class my_unicode(str): pass
611 pat = re.compile(my_unicode("abc")) 733 pat = re.compile(my_unicode("abc"))
612 self.assertEqual(pat.match("xyz"), None) 734 self.assertEqual(pat.match("xyz"), None)
613 735
614 def test_finditer(self): 736 def test_finditer(self):
615 iter = re.finditer(r":+", "a:b::c:::d") 737 iter = re.finditer(r":+", "a:b::c:::d")
616 self.assertEqual([item.group(0) for item in iter], 738 self.assertEqual([item.group(0) for item in iter],
617 [":", "::", ":::"]) 739 [":", "::", ":::"])
740
741 pat = re.compile(r":+")
742 iter = pat.finditer("a:b::c:::d", 1, 10)
743 self.assertEqual([item.group(0) for item in iter],
744 [":", "::", ":::"])
745
746 pat = re.compile(r":+")
747 iter = pat.finditer("a:b::c:::d", pos=1, endpos=10)
748 self.assertEqual([item.group(0) for item in iter],
749 [":", "::", ":::"])
750
751 pat = re.compile(r":+")
752 iter = pat.finditer("a:b::c:::d", endpos=10, pos=1)
753 self.assertEqual([item.group(0) for item in iter],
754 [":", "::", ":::"])
755
756 pat = re.compile(r":+")
757 iter = pat.finditer("a:b::c:::d", pos=3, endpos=8)
758 self.assertEqual([item.group(0) for item in iter],
759 ["::", "::"])
618 760
619 def test_bug_926075(self): 761 def test_bug_926075(self):
620 self.assertTrue(re.compile('bug_926075') is not 762 self.assertTrue(re.compile('bug_926075') is not
621 re.compile(b'bug_926075')) 763 re.compile(b'bug_926075'))
622 764
623 def test_bug_931848(self): 765 def test_bug_931848(self):
624 pattern = eval('"[\u002E\u3002\uFF0E\uFF61]"') 766 pattern = eval('"[\u002E\u3002\uFF0E\uFF61]"')
625 self.assertEqual(re.compile(pattern).split("a.b.c"), 767 self.assertEqual(re.compile(pattern).split("a.b.c"),
626 ['a','b','c']) 768 ['a','b','c'])
627 769
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 self.assertRaises(TypeError, re.finditer, "a", {}) 923 self.assertRaises(TypeError, re.finditer, "a", {})
782 self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow] ) 924 self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow] )
783 self.assertRaises(TypeError, _sre.compile, {}, 0, []) 925 self.assertRaises(TypeError, _sre.compile, {}, 0, [])
784 926
785 def test_search_dot_unicode(self): 927 def test_search_dot_unicode(self):
786 self.assertIsNotNone(re.search("123.*-", '123abc-')) 928 self.assertIsNotNone(re.search("123.*-", '123abc-'))
787 self.assertIsNotNone(re.search("123.*-", '123\xe9-')) 929 self.assertIsNotNone(re.search("123.*-", '123\xe9-'))
788 self.assertIsNotNone(re.search("123.*-", '123\u20ac-')) 930 self.assertIsNotNone(re.search("123.*-", '123\u20ac-'))
789 self.assertIsNotNone(re.search("123.*-", '123\U0010ffff-')) 931 self.assertIsNotNone(re.search("123.*-", '123\U0010ffff-'))
790 self.assertIsNotNone(re.search("123.*-", '123\xe9\u20ac\U0010ffff-')) 932 self.assertIsNotNone(re.search("123.*-", '123\xe9\u20ac\U0010ffff-'))
933
934 def test_compile(self):
935 # Test return value when given string and pattern as parameter
936 pattern = re.compile('random pattern')
937 self.assertIsInstance(pattern, re._pattern_type)
938 same_pattern = re.compile(pattern)
939 self.assertIsInstance(same_pattern, re._pattern_type)
940 self.assertIs(same_pattern, pattern)
941 # Test behaviour when not given a string or pattern as parameter
942 self.assertRaises(TypeError, re.compile, 0)
791 943
792 def run_re_tests(): 944 def run_re_tests():
793 from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR 945 from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
794 if verbose: 946 if verbose:
795 print('Running re_tests test suite') 947 print('Running re_tests test suite')
796 else: 948 else:
797 # To save time, only run the first and last 10 tests 949 # To save time, only run the first and last 10 tests
798 #tests = tests[:10] + tests[-10:] 950 #tests = tests[:10] + tests[-10:]
799 pass 951 pass
800 952
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 if result is None: 1068 if result is None:
917 print('=== Fails on unicode-sensitive match', t) 1069 print('=== Fails on unicode-sensitive match', t)
918 1070
919 1071
920 def test_main(): 1072 def test_main():
921 run_unittest(ReTests) 1073 run_unittest(ReTests)
922 run_re_tests() 1074 run_re_tests()
923 1075
924 if __name__ == "__main__": 1076 if __name__ == "__main__":
925 test_main() 1077 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+