Back to index

python3.2  3.2.2
Public Member Functions
test.test_re.ReTests Class Reference

List of all members.

Public Member Functions

def test_weakref
def test_search_star_plus
def bump_num
def test_basic_re_sub
def test_bug_449964
def test_bug_449000
def test_bug_1661
def test_bug_3629
def test_sub_template_numeric_escape
def test_qualified_re_sub
def test_bug_114660
def test_bug_462270
def test_symbolic_refs
def test_re_subn
def test_re_split
def test_qualified_re_split
def test_re_findall
def test_bug_117612
def test_re_match
def test_re_groupref_exists
def test_re_groupref
def test_groupdict
def test_expand
def test_repeat_minmax
def test_getattr
def test_special_escapes
def test_bigcharset
def test_anyall
def test_non_consuming
def test_ignore_case
def test_category
def test_getlower
def test_not_literal
def test_search_coverage
def assertMatch
def test_re_escape
def test_re_escape_byte
def test_re_escape_non_ascii
def test_re_escape_non_ascii_bytes
def pickle_test
def test_constants
def test_flags
def test_sre_character_literals
def test_sre_character_class_literals
def test_bug_113254
def test_bug_527371
def test_bug_545855
def test_bug_418626
def test_bug_612074
def test_stack_overflow
def test_scanner
def test_bug_448951
def test_bug_725106
def test_bug_725149
def test_bug_764548
def test_finditer
def test_bug_926075
def test_bug_931848
def test_bug_581080
def test_bug_817234
def test_bug_6561
def test_empty_array
def test_inline_flags
def test_dollar_matches_twice
def test_bytes_str_mixing
def test_ascii_and_unicode_flag
def test_bug_6509
def test_dealloc

Detailed Description

Definition at line 17 of file test_re.py.


Member Function Documentation

def test.test_re.ReTests.assertMatch (   self,
  pattern,
  text,
  match = None,
  span = None,
  matcher = re.match 
)

Definition at line 417 of file test_re.py.

00417 
00418                     matcher=re.match):
00419         if match is None and span is None:
00420             # the pattern matches the whole text
00421             match = text
00422             span = (0, len(text))
00423         elif match is None or span is None:
00424             raise ValueError('If match is not None, span should be specified '
00425                              '(and vice versa).')
00426         m = matcher(pattern, text)
00427         self.assertTrue(m)
00428         self.assertEqual(m.group(), match)
00429         self.assertEqual(m.span(), span)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_re.ReTests.bump_num (   self,
  matchobj 
)

Definition at line 37 of file test_re.py.

00037 
00038     def bump_num(self, matchobj):
00039         int_value = int(matchobj.group(0))
00040         return str(int_value + 1)

Here is the caller graph for this function:

def test.test_re.ReTests.pickle_test (   self,
  pickle 
)

Definition at line 473 of file test_re.py.

00473 
00474     def pickle_test(self, pickle):
00475         oldpat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
00476         s = pickle.dumps(oldpat)
00477         newpat = pickle.loads(s)
00478         self.assertEqual(oldpat, newpat)

Here is the call graph for this function:

Definition at line 364 of file test_re.py.

00364 
00365     def test_anyall(self):
00366         self.assertEqual(re.match("a.b", "a\nb", re.DOTALL).group(0),
00367                          "a\nb")
00368         self.assertEqual(re.match("a.*b", "a\n\nb", re.DOTALL).group(0),
00369                          "a\n\nb")

Here is the call graph for this function:

Definition at line 724 of file test_re.py.

00724 
00725     def test_ascii_and_unicode_flag(self):
00726         # String patterns
00727         for flags in (0, re.UNICODE):
00728             pat = re.compile('\xc0', flags | re.IGNORECASE)
00729             self.assertNotEqual(pat.match('\xe0'), None)
00730             pat = re.compile('\w', flags)
00731             self.assertNotEqual(pat.match('\xe0'), None)
00732         pat = re.compile('\xc0', re.ASCII | re.IGNORECASE)
00733         self.assertEqual(pat.match('\xe0'), None)
00734         pat = re.compile('(?a)\xc0', re.IGNORECASE)
00735         self.assertEqual(pat.match('\xe0'), None)
00736         pat = re.compile('\w', re.ASCII)
00737         self.assertEqual(pat.match('\xe0'), None)
00738         pat = re.compile('(?a)\w')
00739         self.assertEqual(pat.match('\xe0'), None)
00740         # Bytes patterns
00741         for flags in (0, re.ASCII):
00742             pat = re.compile(b'\xc0', re.IGNORECASE)
00743             self.assertEqual(pat.match(b'\xe0'), None)
00744             pat = re.compile(b'\w')
00745             self.assertEqual(pat.match(b'\xe0'), None)
00746         # Incompatibilities
00747         self.assertRaises(ValueError, re.compile, b'\w', re.UNICODE)
00748         self.assertRaises(ValueError, re.compile, b'(?u)\w')
00749         self.assertRaises(ValueError, re.compile, '\w', re.UNICODE | re.ASCII)
00750         self.assertRaises(ValueError, re.compile, '(?u)\w', re.ASCII)
00751         self.assertRaises(ValueError, re.compile, '(?a)\w', re.UNICODE)
00752         self.assertRaises(ValueError, re.compile, '(?au)\w')

Here is the call graph for this function:

Definition at line 41 of file test_re.py.

00041 
00042     def test_basic_re_sub(self):
00043         self.assertEqual(re.sub("(?i)b+", "x", "bbbb BBBB"), 'x x')
00044         self.assertEqual(re.sub(r'\d+', self.bump_num, '08.2 -2 23x99y'),
00045                          '9.3 -3 24x100y')
00046         self.assertEqual(re.sub(r'\d+', self.bump_num, '08.2 -2 23x99y', 3),
00047                          '9.3 -3 23x99y')
00048 
00049         self.assertEqual(re.sub('.', lambda m: r"\n", 'x'), '\\n')
00050         self.assertEqual(re.sub('.', r"\n", 'x'), '\n')
00051 
00052         s = r"\1\1"
00053         self.assertEqual(re.sub('(.)', s, 'x'), 'xx')
00054         self.assertEqual(re.sub('(.)', re.escape(s), 'x'), s)
00055         self.assertEqual(re.sub('(.)', lambda m: s, 'x'), s)
00056 
00057         self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx'), 'xxxx')
00058         self.assertEqual(re.sub('(?P<a>x)', '\g<a>\g<1>', 'xx'), 'xxxx')
00059         self.assertEqual(re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx'), 'xxxx')
00060         self.assertEqual(re.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx'), 'xxxx')
00061 
00062         self.assertEqual(re.sub('a',r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D','a'),
00063                          '\t\n\v\r\f\a\b\\B\\Z\a\\A\\w\\W\\s\\S\\d\\D')
00064         self.assertEqual(re.sub('a', '\t\n\v\r\f\a', 'a'), '\t\n\v\r\f\a')
00065         self.assertEqual(re.sub('a', '\t\n\v\r\f\a', 'a'),
00066                          (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)))
00067 
00068         self.assertEqual(re.sub('^\s*', 'X', 'test'), 'Xtest')

Here is the call graph for this function:

Definition at line 358 of file test_re.py.

00358 
00359     def test_bigcharset(self):
00360         self.assertEqual(re.match("([\u2222\u2223])",
00361                                   "\u2222").group(1), "\u2222")
00362         self.assertEqual(re.match("([\u2222\u2223])",
00363                                   "\u2222", re.UNICODE).group(1), "\u2222")

Here is the call graph for this function:

Definition at line 510 of file test_re.py.

00510 
00511     def test_bug_113254(self):
00512         self.assertEqual(re.match(r'(a)|(b)', 'b').start(1), -1)
00513         self.assertEqual(re.match(r'(a)|(b)', 'b').end(1), -1)
00514         self.assertEqual(re.match(r'(a)|(b)', 'b').span(1), (-1, -1))

Here is the call graph for this function:

Definition at line 143 of file test_re.py.

00143 
00144     def test_bug_114660(self):
00145         self.assertEqual(re.sub(r'(\S)\s+(\S)', r'\1 \2', 'hello  there'),
00146                          'hello there')

Here is the call graph for this function:

Definition at line 202 of file test_re.py.

00202 
00203     def test_bug_117612(self):
00204         self.assertEqual(re.findall(r"(a|(b))", "aba"),
00205                          [("a", ""),("b", "b"),("a", "")])

Here is the call graph for this function:

Definition at line 85 of file test_re.py.

00085 
00086     def test_bug_1661(self):
00087         # Verify that flags do not get silently ignored with compiled patterns
00088         pattern = re.compile('.')
00089         self.assertRaises(ValueError, re.match, pattern, 'A', re.I)
00090         self.assertRaises(ValueError, re.search, pattern, 'A', re.I)
00091         self.assertRaises(ValueError, re.findall, pattern, 'A', re.I)
00092         self.assertRaises(ValueError, re.compile, pattern, re.I)

Here is the call graph for this function:

Definition at line 93 of file test_re.py.

00093 
00094     def test_bug_3629(self):
00095         # A regex that triggered a bug in the sre-code validator
00096         re.compile("(?P<quote>)(?(quote))")

Here is the call graph for this function:

Definition at line 528 of file test_re.py.

00528 
00529     def test_bug_418626(self):
00530         # bugs 418626 at al. -- Testing Greg Chapman's addition of op code
00531         # SRE_OP_MIN_REPEAT_ONE for eliminating recursion on simple uses of
00532         # pattern '*?' on a long string.
00533         self.assertEqual(re.match('.*?c', 10000*'ab'+'cd').end(0), 20001)
00534         self.assertEqual(re.match('.*?cd', 5000*'ab'+'c'+5000*'ab'+'cde').end(0),
00535                          20003)
00536         self.assertEqual(re.match('.*?cd', 20000*'abc'+'de').end(0), 60001)
00537         # non-simple '*?' still used to hit the recursion limit, before the
00538         # non-recursive scheme was implemented.
00539         self.assertEqual(re.search('(a|b)*?c', 10000*'ab'+'cd').end(0), 20001)

Here is the call graph for this function:

Definition at line 571 of file test_re.py.

00571 
00572     def test_bug_448951(self):
00573         # bug 448951 (similar to 429357, but with single char match)
00574         # (Also test greedy matches.)
00575         for op in '','?','*':
00576             self.assertEqual(re.match(r'((.%s):)?z'%op, 'z').groups(),
00577                              (None, None))
00578             self.assertEqual(re.match(r'((.%s):)?z'%op, 'a:z').groups(),
00579                              ('a:', 'a'))

Here is the call graph for this function:

Definition at line 74 of file test_re.py.

00074 
00075     def test_bug_449000(self):
00076         # Test for sub() on escaped characters
00077         self.assertEqual(re.sub(r'\r\n', r'\n', 'abc\r\ndef\r\n'),
00078                          'abc\ndef\n')
00079         self.assertEqual(re.sub('\r\n', r'\n', 'abc\r\ndef\r\n'),
00080                          'abc\ndef\n')
00081         self.assertEqual(re.sub(r'\r\n', '\n', 'abc\r\ndef\r\n'),
00082                          'abc\ndef\n')
00083         self.assertEqual(re.sub('\r\n', '\n', 'abc\r\ndef\r\n'),
00084                          'abc\ndef\n')

Here is the call graph for this function:

Definition at line 69 of file test_re.py.

00069 
00070     def test_bug_449964(self):
00071         # fails for group followed by other escape
00072         self.assertEqual(re.sub(r'(?P<unk>x)', '\g<1>\g<1>\\b', 'xx'),
00073                          'xx\bxx\b')

Here is the call graph for this function:

Definition at line 147 of file test_re.py.

00147 
00148     def test_bug_462270(self):
00149         # Test for empty sub() behaviour, see SF bug #462270
00150         self.assertEqual(re.sub('x*', '-', 'abxd'), '-a-b-d-')
00151         self.assertEqual(re.sub('x+', '-', 'abxd'), 'ab-d')

Here is the call graph for this function:

Definition at line 515 of file test_re.py.

00515 
00516     def test_bug_527371(self):
00517         # bug described in patches 527371/672491
00518         self.assertEqual(re.match(r'(a)?a','a').lastindex, None)
00519         self.assertEqual(re.match(r'(a)(b)?b','ab').lastindex, 1)
00520         self.assertEqual(re.match(r'(?P<a>a)(?P<b>b)?b','ab').lastgroup, 'a')
00521         self.assertEqual(re.match("(?P<a>a(b))", "ab").lastgroup, 'a')
00522         self.assertEqual(re.match("((a))", "a").lastindex, 1)

Here is the call graph for this function:

Definition at line 523 of file test_re.py.

00523 
00524     def test_bug_545855(self):
00525         # bug 545855 -- This pattern failed to cause a compile error as it
00526         # should, instead provoking a TypeError.
00527         self.assertRaises(re.error, re.compile, 'foo[a-')

Here is the call graph for this function:

Definition at line 626 of file test_re.py.

00626 
00627     def test_bug_581080(self):
00628         iter = re.finditer(r"\s", "a b")
00629         self.assertEqual(next(iter).span(), (1,2))
00630         self.assertRaises(StopIteration, next, iter)
00631 
00632         scanner = re.compile(r"\s").scanner("a b")
00633         self.assertEqual(scanner.search().span(), (1, 2))
00634         self.assertEqual(scanner.search(), None)

Here is the call graph for this function:

Definition at line 540 of file test_re.py.

00540 
00541     def test_bug_612074(self):
00542         pat="["+re.escape("\u2039")+"]"
00543         self.assertEqual(re.compile(pat) and 1, 1)

Here is the call graph for this function:

Definition at line 753 of file test_re.py.

00753 
00754     def test_bug_6509(self):
00755         # Replacement strings of both types must parse properly.
00756         # all strings
00757         pat = re.compile('a(\w)')
00758         self.assertEqual(pat.sub('b\\1', 'ac'), 'bc')
00759         pat = re.compile('a(.)')
00760         self.assertEqual(pat.sub('b\\1', 'a\u1234'), 'b\u1234')
00761         pat = re.compile('..')
00762         self.assertEqual(pat.sub(lambda m: 'str', 'a5'), 'str')
00763 
00764         # all bytes
00765         pat = re.compile(b'a(\w)')
00766         self.assertEqual(pat.sub(b'b\\1', b'ac'), b'bc')
00767         pat = re.compile(b'a(.)')
00768         self.assertEqual(pat.sub(b'b\\1', b'a\xCD'), b'b\xCD')
00769         pat = re.compile(b'..')
00770         self.assertEqual(pat.sub(lambda m: b'bytes', b'a5'), b'bytes')

Here is the call graph for this function:

Definition at line 641 of file test_re.py.

00641 
00642     def test_bug_6561(self):
00643         # '\d' should match characters in Unicode category 'Nd'
00644         # (Number, Decimal Digit), but not those in 'Nl' (Number,
00645         # Letter) or 'No' (Number, Other).
00646         decimal_digits = [
00647             '\u0037', # '\N{DIGIT SEVEN}', category 'Nd'
00648             '\u0e58', # '\N{THAI DIGIT SIX}', category 'Nd'
00649             '\uff10', # '\N{FULLWIDTH DIGIT ZERO}', category 'Nd'
00650             ]
00651         for x in decimal_digits:
00652             self.assertEqual(re.match('^\d$', x).group(0), x)
00653 
00654         not_decimal_digits = [
00655             '\u2165', # '\N{ROMAN NUMERAL SIX}', category 'Nl'
00656             '\u3039', # '\N{HANGZHOU NUMERAL TWENTY}', category 'Nl'
00657             '\u2082', # '\N{SUBSCRIPT TWO}', category 'No'
00658             '\u32b4', # '\N{CIRCLED NUMBER THIRTY NINE}', category 'No'
00659             ]
00660         for x in not_decimal_digits:
00661             self.assertIsNone(re.match('^\d$', x))

Here is the call graph for this function:

Definition at line 580 of file test_re.py.

00580 
00581     def test_bug_725106(self):
00582         # capturing groups in alternatives in repeats
00583         self.assertEqual(re.match('^((a)|b)*', 'abc').groups(),
00584                          ('b', 'a'))
00585         self.assertEqual(re.match('^(([ab])|c)*', 'abc').groups(),
00586                          ('c', 'b'))
00587         self.assertEqual(re.match('^((d)|[ab])*', 'abc').groups(),
00588                          ('b', None))
00589         self.assertEqual(re.match('^((a)c|[ab])*', 'abc').groups(),
00590                          ('b', None))
00591         self.assertEqual(re.match('^((a)|b)*?c', 'abc').groups(),
00592                          ('b', 'a'))
00593         self.assertEqual(re.match('^(([ab])|c)*?d', 'abcd').groups(),
00594                          ('c', 'b'))
00595         self.assertEqual(re.match('^((d)|[ab])*?c', 'abc').groups(),
00596                          ('b', None))
00597         self.assertEqual(re.match('^((a)c|[ab])*?c', 'abc').groups(),
00598                          ('b', None))

Here is the call graph for this function:

Definition at line 599 of file test_re.py.

00599 
00600     def test_bug_725149(self):
00601         # mark_stack_base restoring before restoring marks
00602         self.assertEqual(re.match('(a)(?:(?=(b)*)c)*', 'abb').groups(),
00603                          ('a', None))
00604         self.assertEqual(re.match('(a)((?!(b)*))*', 'abb').groups(),
00605                          ('a', None, None))

Here is the call graph for this function:

Definition at line 606 of file test_re.py.

00606 
00607     def test_bug_764548(self):
00608         # bug 764548, re.compile() barfs on str/unicode subclasses
00609         class my_unicode(str): pass
00610         pat = re.compile(my_unicode("abc"))
00611         self.assertEqual(pat.match("xyz"), None)

Here is the call graph for this function:

Definition at line 635 of file test_re.py.

00635 
00636     def test_bug_817234(self):
00637         iter = re.finditer(r".*", "asdf")
00638         self.assertEqual(next(iter).span(), (0, 4))
00639         self.assertEqual(next(iter).span(), (4, 4))
00640         self.assertRaises(StopIteration, next, iter)

Here is the call graph for this function:

Definition at line 617 of file test_re.py.

00617 
00618     def test_bug_926075(self):
00619         self.assertTrue(re.compile('bug_926075') is not
00620                      re.compile(b'bug_926075'))

Here is the call graph for this function:

Definition at line 621 of file test_re.py.

00621 
00622     def test_bug_931848(self):
00623         pattern = eval('"[\u002E\u3002\uFF0E\uFF61]"')
00624         self.assertEqual(re.compile(pattern).split("a.b.c"),
00625                          ['a','b','c'])

Here is the call graph for this function:

Definition at line 711 of file test_re.py.

00711 
00712     def test_bytes_str_mixing(self):
00713         # Mixing str and bytes is disallowed
00714         pat = re.compile('.')
00715         bpat = re.compile(b'.')
00716         self.assertRaises(TypeError, pat.match, b'b')
00717         self.assertRaises(TypeError, bpat.match, 'b')
00718         self.assertRaises(TypeError, pat.sub, b'b', 'c')
00719         self.assertRaises(TypeError, pat.sub, 'b', b'c')
00720         self.assertRaises(TypeError, pat.sub, b'b', b'c')
00721         self.assertRaises(TypeError, bpat.sub, b'b', 'c')
00722         self.assertRaises(TypeError, bpat.sub, 'b', b'c')
00723         self.assertRaises(TypeError, bpat.sub, 'b', 'c')

Here is the call graph for this function:

Definition at line 396 of file test_re.py.

00396 
00397     def test_category(self):
00398         self.assertEqual(re.match(r"(\s)", " ").group(1), " ")

Here is the call graph for this function:

Definition at line 479 of file test_re.py.

00479 
00480     def test_constants(self):
00481         self.assertEqual(re.I, re.IGNORECASE)
00482         self.assertEqual(re.L, re.LOCALE)
00483         self.assertEqual(re.M, re.MULTILINE)
00484         self.assertEqual(re.S, re.DOTALL)
00485         self.assertEqual(re.X, re.VERBOSE)

Here is the call graph for this function:

Definition at line 771 of file test_re.py.

00771 
00772     def test_dealloc(self):
00773         # issue 3299: check for segfault in debug build
00774         import _sre
00775         # the overflow limit is different on wide and narrow builds and it
00776         # depends on the definition of SRE_CODE (see sre.h).
00777         # 2**128 should be big enough to overflow on both. For smaller values
00778         # a RuntimeError is raised instead of OverflowError.
00779         long_overflow = 2**128
00780         self.assertRaises(TypeError, re.finditer, "a", {})
00781         self.assertRaises(OverflowError, _sre.compile, "abc", 0, [long_overflow])
00782         self.assertRaises(TypeError, _sre.compile, {}, 0, [])

Here is the call graph for this function:

Definition at line 699 of file test_re.py.

00699 
00700     def test_dollar_matches_twice(self):
00701         "$ matches the end of string, and just before the terminating \n"
00702         pattern = re.compile('$')
00703         self.assertEqual(pattern.sub('#', 'a\nb\n'), 'a\nb#\n#')
00704         self.assertEqual(pattern.sub('#', 'a\nb\nc'), 'a\nb\nc#')
00705         self.assertEqual(pattern.sub('#', '\n'), '#\n#')
00706 
00707         pattern = re.compile('$', re.MULTILINE)
00708         self.assertEqual(pattern.sub('#', 'a\nb\n' ), 'a#\nb#\n#' )
00709         self.assertEqual(pattern.sub('#', 'a\nb\nc'), 'a#\nb#\nc#')
00710         self.assertEqual(pattern.sub('#', '\n'), '#\n#')

Here is the call graph for this function:

Definition at line 662 of file test_re.py.

00662 
00663     def test_empty_array(self):
00664         # SF buf 1647541
00665         import array
00666         for typecode in 'bBuhHiIlLfd':
00667             a = array.array(typecode)
00668             self.assertEqual(re.compile(b"bla").match(a), None)
00669             self.assertEqual(re.compile(b"").match(a).groups(), ())

Here is the call graph for this function:

Definition at line 276 of file test_re.py.

00276 
00277     def test_expand(self):
00278         self.assertEqual(re.match("(?P<first>first) (?P<second>second)",
00279                                   "first second")
00280                                   .expand(r"\2 \1 \g<second> \g<first>"),
00281                          "second first second first")

Here is the call graph for this function:

Definition at line 612 of file test_re.py.

00612 
00613     def test_finditer(self):
00614         iter = re.finditer(r":+", "a:b::c:::d")
00615         self.assertEqual([item.group(0) for item in iter],
00616                          [":", "::", ":::"])

Here is the call graph for this function:

Definition at line 486 of file test_re.py.

00486 
00487     def test_flags(self):
00488         for flag in [re.I, re.M, re.X, re.S, re.L]:
00489             self.assertNotEqual(re.compile('^pattern$', flag), None)

Here is the call graph for this function:

Definition at line 314 of file test_re.py.

00314 
00315     def test_getattr(self):
00316         self.assertEqual(re.compile("(?i)(a)(b)").pattern, "(?i)(a)(b)")
00317         self.assertEqual(re.compile("(?i)(a)(b)").flags, re.I | re.U)
00318         self.assertEqual(re.compile("(?i)(a)(b)").groups, 2)
00319         self.assertEqual(re.compile("(?i)(a)(b)").groupindex, {})
00320         self.assertEqual(re.compile("(?i)(?P<first>a)(?P<other>b)").groupindex,
00321                          {'first': 1, 'other': 2})
00322 
00323         self.assertEqual(re.match("(a)", "a").pos, 0)
00324         self.assertEqual(re.match("(a)", "a").endpos, 1)
00325         self.assertEqual(re.match("(a)", "a").string, "a")
00326         self.assertEqual(re.match("(a)", "a").regs, ((0, 1), (0, 1)))
00327         self.assertNotEqual(re.match("(a)", "a").re, None)

Here is the call graph for this function:

Definition at line 399 of file test_re.py.

00399 
00400     def test_getlower(self):
00401         import _sre
00402         self.assertEqual(_sre.getlower(ord('A'), 0), ord('a'))
00403         self.assertEqual(_sre.getlower(ord('A'), re.LOCALE), ord('a'))
00404         self.assertEqual(_sre.getlower(ord('A'), re.UNICODE), ord('a'))
00405 
00406         self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
00407         self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")

Here is the call graph for this function:

Definition at line 271 of file test_re.py.

00271 
00272     def test_groupdict(self):
00273         self.assertEqual(re.match('(?P<first>first) (?P<second>second)',
00274                                   'first second').groupdict(),
00275                          {'first':'first', 'second':'second'})

Here is the call graph for this function:

Definition at line 384 of file test_re.py.

00384 
00385     def test_ignore_case(self):
00386         self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
00387         self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
00388         self.assertEqual(re.match(r"(a\s[^a])", "a b", re.I).group(1), "a b")
00389         self.assertEqual(re.match(r"(a\s[^a]*)", "a bb", re.I).group(1), "a bb")
00390         self.assertEqual(re.match(r"(a\s[abc])", "a b", re.I).group(1), "a b")
00391         self.assertEqual(re.match(r"(a\s[abc]*)", "a bb", re.I).group(1), "a bb")
00392         self.assertEqual(re.match(r"((a)\s\2)", "a a", re.I).group(1), "a a")
00393         self.assertEqual(re.match(r"((a)\s\2*)", "a aa", re.I).group(1), "a aa")
00394         self.assertEqual(re.match(r"((a)\s(abc|a))", "a a", re.I).group(1), "a a")
00395         self.assertEqual(re.match(r"((a)\s(abc|a)*)", "a aa", re.I).group(1), "a aa")

Here is the call graph for this function:

Definition at line 670 of file test_re.py.

00670 
00671     def test_inline_flags(self):
00672         # Bug #1700
00673         upper_char = chr(0x1ea0) # Latin Capital Letter A with Dot Bellow
00674         lower_char = chr(0x1ea1) # Latin Small Letter A with Dot Bellow
00675 
00676         p = re.compile(upper_char, re.I | re.U)
00677         q = p.match(lower_char)
00678         self.assertNotEqual(q, None)
00679 
00680         p = re.compile(lower_char, re.I | re.U)
00681         q = p.match(upper_char)
00682         self.assertNotEqual(q, None)
00683 
00684         p = re.compile('(?i)' + upper_char, re.U)
00685         q = p.match(lower_char)
00686         self.assertNotEqual(q, None)
00687 
00688         p = re.compile('(?i)' + lower_char, re.U)
00689         q = p.match(upper_char)
00690         self.assertNotEqual(q, None)
00691 
00692         p = re.compile('(?iu)' + upper_char)
00693         q = p.match(lower_char)
00694         self.assertNotEqual(q, None)
00695 
00696         p = re.compile('(?iu)' + lower_char)
00697         q = p.match(upper_char)
00698         self.assertNotEqual(q, None)

Here is the call graph for this function:

Definition at line 370 of file test_re.py.

00370 
00371     def test_non_consuming(self):
00372         self.assertEqual(re.match("(a(?=\s[^a]))", "a b").group(1), "a")
00373         self.assertEqual(re.match("(a(?=\s[^a]*))", "a b").group(1), "a")
00374         self.assertEqual(re.match("(a(?=\s[abc]))", "a b").group(1), "a")
00375         self.assertEqual(re.match("(a(?=\s[abc]*))", "a bc").group(1), "a")
00376         self.assertEqual(re.match(r"(a)(?=\s\1)", "a a").group(1), "a")
00377         self.assertEqual(re.match(r"(a)(?=\s\1*)", "a aa").group(1), "a")
00378         self.assertEqual(re.match(r"(a)(?=\s(abc|a))", "a a").group(1), "a")
00379 
00380         self.assertEqual(re.match(r"(a(?!\s[^a]))", "a a").group(1), "a")
00381         self.assertEqual(re.match(r"(a(?!\s[abc]))", "a d").group(1), "a")
00382         self.assertEqual(re.match(r"(a)(?!\s\1)", "a b").group(1), "a")
00383         self.assertEqual(re.match(r"(a)(?!\s(abc|a))", "a b").group(1), "a")

Here is the call graph for this function:

Definition at line 408 of file test_re.py.

00408 
00409     def test_not_literal(self):
00410         self.assertEqual(re.search("\s([^a])", " b").group(1), "b")
00411         self.assertEqual(re.search("\s([^a]*)", " bb").group(1), "bb")

Here is the call graph for this function:

Definition at line 186 of file test_re.py.

00186 
00187     def test_qualified_re_split(self):
00188         self.assertEqual(re.split(":", ":a:b::c", 2), ['', 'a', 'b::c'])
00189         self.assertEqual(re.split(':', 'a:b:c:d', 2), ['a', 'b', 'c:d'])
00190         self.assertEqual(re.split("(:)", ":a:b::c", 2),
00191                          ['', ':', 'a', ':', 'b::c'])
00192         self.assertEqual(re.split("(:*)", ":a:b::c", 2),
00193                          ['', ':', 'a', ':', 'b::c'])

Here is the call graph for this function:

Definition at line 139 of file test_re.py.

00139 
00140     def test_qualified_re_sub(self):
00141         self.assertEqual(re.sub('a', 'b', 'aaaaa'), 'bbbbb')
00142         self.assertEqual(re.sub('a', 'b', 'aaaaa', 1), 'baaaa')

Here is the call graph for this function:

Definition at line 430 of file test_re.py.

00430 
00431     def test_re_escape(self):
00432         alnum_chars = string.ascii_letters + string.digits
00433         p = ''.join(chr(i) for i in range(256))
00434         for c in p:
00435             if c in alnum_chars:
00436                 self.assertEqual(re.escape(c), c)
00437             elif c == '\x00':
00438                 self.assertEqual(re.escape(c), '\\000')
00439             else:
00440                 self.assertEqual(re.escape(c), '\\' + c)
00441             self.assertMatch(re.escape(c), c)
00442         self.assertMatch(re.escape(p), p)

Here is the call graph for this function:

Definition at line 443 of file test_re.py.

00443 
00444     def test_re_escape_byte(self):
00445         alnum_chars = (string.ascii_letters + string.digits).encode('ascii')
00446         p = bytes(range(256))
00447         for i in p:
00448             b = bytes([i])
00449             if b in alnum_chars:
00450                 self.assertEqual(re.escape(b), b)
00451             elif i == 0:
00452                 self.assertEqual(re.escape(b), b'\\000')
00453             else:
00454                 self.assertEqual(re.escape(b), b'\\' + b)
00455             self.assertMatch(re.escape(b), b)
00456         self.assertMatch(re.escape(p), p)

Here is the call graph for this function:

Definition at line 457 of file test_re.py.

00457 
00458     def test_re_escape_non_ascii(self):
00459         s = 'xxx\u2620\u2620\u2620xxx'
00460         s_escaped = re.escape(s)
00461         self.assertEqual(s_escaped, 'xxx\\\u2620\\\u2620\\\u2620xxx')
00462         self.assertMatch(s_escaped, s)
00463         self.assertMatch('.%s+.' % re.escape('\u2620'), s,
00464                          'x\u2620\u2620\u2620x', (2, 7), re.search)

Here is the call graph for this function:

Definition at line 465 of file test_re.py.

00465 
00466     def test_re_escape_non_ascii_bytes(self):
00467         b = 'y\u2620y\u2620y'.encode('utf-8')
00468         b_escaped = re.escape(b)
00469         self.assertEqual(b_escaped, b'y\\\xe2\\\x98\\\xa0y\\\xe2\\\x98\\\xa0y')
00470         self.assertMatch(b_escaped, b)
00471         res = re.findall(re.escape('\u2620'.encode('utf-8')), b)
00472         self.assertEqual(len(res), 2)

Here is the call graph for this function:

Definition at line 194 of file test_re.py.

00194 
00195     def test_re_findall(self):
00196         self.assertEqual(re.findall(":+", "abc"), [])
00197         self.assertEqual(re.findall(":+", "a:b::c:::d"), [":", "::", ":::"])
00198         self.assertEqual(re.findall("(:+)", "a:b::c:::d"), [":", "::", ":::"])
00199         self.assertEqual(re.findall("(:)(:*)", "a:b::c:::d"), [(":", ""),
00200                                                                (":", ":"),
00201                                                                (":", "::")])

Here is the call graph for this function:

Definition at line 259 of file test_re.py.

00259 
00260     def test_re_groupref(self):
00261         self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', '|a|').groups(),
00262                          ('|', 'a'))
00263         self.assertEqual(re.match(r'^(\|)?([^()]+)\1?$', 'a').groups(),
00264                          (None, 'a'))
00265         self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', 'a|'), None)
00266         self.assertEqual(re.match(r'^(\|)?([^()]+)\1$', '|a'), None)
00267         self.assertEqual(re.match(r'^(?:(a)|c)(\1)$', 'aa').groups(),
00268                          ('a', 'a'))
00269         self.assertEqual(re.match(r'^(?:(a)|c)(\1)?$', 'c').groups(),
00270                          (None, None))

Here is the call graph for this function:

Definition at line 233 of file test_re.py.

00233 
00234     def test_re_groupref_exists(self):
00235         self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', '(a)').groups(),
00236                          ('(', 'a'))
00237         self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', 'a').groups(),
00238                          (None, 'a'))
00239         self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', 'a)'), None)
00240         self.assertEqual(re.match('^(\()?([^()]+)(?(1)\))$', '(a'), None)
00241         self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'ab').groups(),
00242                          ('a', 'b'))
00243         self.assertEqual(re.match('^(?:(a)|c)((?(1)b|d))$', 'cd').groups(),
00244                          (None, 'd'))
00245         self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'cd').groups(),
00246                          (None, 'd'))
00247         self.assertEqual(re.match('^(?:(a)|c)((?(1)|d))$', 'a').groups(),
00248                          ('a', ''))
00249 
00250         # Tests for bug #1177831: exercise groups other than the first group
00251         p = re.compile('(?P<g1>a)(?P<g2>b)?((?(g2)c|d))')
00252         self.assertEqual(p.match('abc').groups(),
00253                          ('a', 'b', 'c'))
00254         self.assertEqual(p.match('ad').groups(),
00255                          ('a', None, 'd'))
00256         self.assertEqual(p.match('abd'), None)
00257         self.assertEqual(p.match('ac'), None)
00258 

Here is the call graph for this function:

Definition at line 206 of file test_re.py.

00206 
00207     def test_re_match(self):
00208         self.assertEqual(re.match('a', 'a').groups(), ())
00209         self.assertEqual(re.match('(a)', 'a').groups(), ('a',))
00210         self.assertEqual(re.match(r'(a)', 'a').group(0), 'a')
00211         self.assertEqual(re.match(r'(a)', 'a').group(1), 'a')
00212         self.assertEqual(re.match(r'(a)', 'a').group(1, 1), ('a', 'a'))
00213 
00214         pat = re.compile('((a)|(b))(c)?')
00215         self.assertEqual(pat.match('a').groups(), ('a', 'a', None, None))
00216         self.assertEqual(pat.match('b').groups(), ('b', None, 'b', None))
00217         self.assertEqual(pat.match('ac').groups(), ('a', 'a', None, 'c'))
00218         self.assertEqual(pat.match('bc').groups(), ('b', None, 'b', 'c'))
00219         self.assertEqual(pat.match('bc').groups(""), ('b', "", 'b', 'c'))
00220 
00221         # A single group
00222         m = re.match('(a)', 'a')
00223         self.assertEqual(m.group(0), 'a')
00224         self.assertEqual(m.group(0), 'a')
00225         self.assertEqual(m.group(1), 'a')
00226         self.assertEqual(m.group(1, 1), ('a', 'a'))
00227 
00228         pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
00229         self.assertEqual(pat.match('a').group(1, 2, 3), ('a', None, None))
00230         self.assertEqual(pat.match('b').group('a1', 'b2', 'c3'),
00231                          (None, 'b', None))
00232         self.assertEqual(pat.match('ac').group(1, 'b2', 3), ('a', None, 'c'))

Here is the call graph for this function:

Definition at line 170 of file test_re.py.

00170 
00171     def test_re_split(self):
00172         self.assertEqual(re.split(":", ":a:b::c"), ['', 'a', 'b', '', 'c'])
00173         self.assertEqual(re.split(":*", ":a:b::c"), ['', 'a', 'b', 'c'])
00174         self.assertEqual(re.split("(:*)", ":a:b::c"),
00175                          ['', ':', 'a', ':', 'b', '::', 'c'])
00176         self.assertEqual(re.split("(?::*)", ":a:b::c"), ['', 'a', 'b', 'c'])
00177         self.assertEqual(re.split("(:)*", ":a:b::c"),
00178                          ['', ':', 'a', ':', 'b', ':', 'c'])
00179         self.assertEqual(re.split("([b:]+)", ":a:b::c"),
00180                          ['', ':', 'a', ':b::', 'c'])
00181         self.assertEqual(re.split("(b)|(:+)", ":a:b::c"),
00182                          ['', None, ':', 'a', None, ':', '', 'b', None, '',
00183                           None, '::', 'c'])
00184         self.assertEqual(re.split("(?:b)|(?::+)", ":a:b::c"),
00185                          ['', 'a', '', '', 'c'])

Here is the call graph for this function:

Definition at line 163 of file test_re.py.

00163 
00164     def test_re_subn(self):
00165         self.assertEqual(re.subn("(?i)b+", "x", "bbbb BBBB"), ('x x', 2))
00166         self.assertEqual(re.subn("b+", "x", "bbbb BBBB"), ('x BBBB', 1))
00167         self.assertEqual(re.subn("b+", "x", "xyz"), ('xyz', 0))
00168         self.assertEqual(re.subn("b*", "x", "xyz"), ('xxxyxzx', 4))
00169         self.assertEqual(re.subn("b*", "x", "xyz", 2), ('xxxyz', 2))

Here is the call graph for this function:

Definition at line 282 of file test_re.py.

00282 
00283     def test_repeat_minmax(self):
00284         self.assertEqual(re.match("^(\w){1}$", "abc"), None)
00285         self.assertEqual(re.match("^(\w){1}?$", "abc"), None)
00286         self.assertEqual(re.match("^(\w){1,2}$", "abc"), None)
00287         self.assertEqual(re.match("^(\w){1,2}?$", "abc"), None)
00288 
00289         self.assertEqual(re.match("^(\w){3}$", "abc").group(1), "c")
00290         self.assertEqual(re.match("^(\w){1,3}$", "abc").group(1), "c")
00291         self.assertEqual(re.match("^(\w){1,4}$", "abc").group(1), "c")
00292         self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
00293         self.assertEqual(re.match("^(\w){3}?$", "abc").group(1), "c")
00294         self.assertEqual(re.match("^(\w){1,3}?$", "abc").group(1), "c")
00295         self.assertEqual(re.match("^(\w){1,4}?$", "abc").group(1), "c")
00296         self.assertEqual(re.match("^(\w){3,4}?$", "abc").group(1), "c")
00297 
00298         self.assertEqual(re.match("^x{1}$", "xxx"), None)
00299         self.assertEqual(re.match("^x{1}?$", "xxx"), None)
00300         self.assertEqual(re.match("^x{1,2}$", "xxx"), None)
00301         self.assertEqual(re.match("^x{1,2}?$", "xxx"), None)
00302 
00303         self.assertNotEqual(re.match("^x{3}$", "xxx"), None)
00304         self.assertNotEqual(re.match("^x{1,3}$", "xxx"), None)
00305         self.assertNotEqual(re.match("^x{1,4}$", "xxx"), None)
00306         self.assertNotEqual(re.match("^x{3,4}?$", "xxx"), None)
00307         self.assertNotEqual(re.match("^x{3}?$", "xxx"), None)
00308         self.assertNotEqual(re.match("^x{1,3}?$", "xxx"), None)
00309         self.assertNotEqual(re.match("^x{1,4}?$", "xxx"), None)
00310         self.assertNotEqual(re.match("^x{3,4}?$", "xxx"), None)
00311 
00312         self.assertEqual(re.match("^x{}$", "xxx"), None)
00313         self.assertNotEqual(re.match("^x{}$", "x{}"), None)

Here is the call graph for this function:

Definition at line 551 of file test_re.py.

00551 
00552     def test_scanner(self):
00553         def s_ident(scanner, token): return token
00554         def s_operator(scanner, token): return "op%s" % token
00555         def s_float(scanner, token): return float(token)
00556         def s_int(scanner, token): return int(token)
00557 
00558         scanner = Scanner([
00559             (r"[a-zA-Z_]\w*", s_ident),
00560             (r"\d+\.\d*", s_float),
00561             (r"\d+", s_int),
00562             (r"=|\+|-|\*|/", s_operator),
00563             (r"\s+", None),
00564             ])
00565 
00566         self.assertNotEqual(scanner.scanner.scanner("").pattern, None)
00567 
00568         self.assertEqual(scanner.scan("sum = 3*foo + 312.50 + bar"),
00569                          (['sum', 'op=', 3, 'op*', 'foo', 'op+', 312.5,
00570                            'op+', 'bar'], ''))

Here is the call graph for this function:

Definition at line 412 of file test_re.py.

00412 
00413     def test_search_coverage(self):
00414         self.assertEqual(re.search("\s(b)", " b").group(1), "b")
00415         self.assertEqual(re.search("a\s", "a ").group(0), "a ")

Here is the call graph for this function:

Definition at line 25 of file test_re.py.

00025 
00026     def test_search_star_plus(self):
00027         self.assertEqual(re.search('x*', 'axx').span(0), (0, 0))
00028         self.assertEqual(re.search('x*', 'axx').span(), (0, 0))
00029         self.assertEqual(re.search('x+', 'axx').span(0), (1, 3))
00030         self.assertEqual(re.search('x+', 'axx').span(), (1, 3))
00031         self.assertEqual(re.search('x', 'aaa'), None)
00032         self.assertEqual(re.match('a*', 'xxx').span(0), (0, 0))
00033         self.assertEqual(re.match('a*', 'xxx').span(), (0, 0))
00034         self.assertEqual(re.match('x*', 'xxxa').span(0), (0, 3))
00035         self.assertEqual(re.match('x*', 'xxxa').span(), (0, 3))
00036         self.assertEqual(re.match('a+', 'xxx'), None)

Here is the call graph for this function:

Definition at line 328 of file test_re.py.

00328 
00329     def test_special_escapes(self):
00330         self.assertEqual(re.search(r"\b(b.)\b",
00331                                    "abcd abc bcd bx").group(1), "bx")
00332         self.assertEqual(re.search(r"\B(b.)\B",
00333                                    "abc bcd bc abxd").group(1), "bx")
00334         self.assertEqual(re.search(r"\b(b.)\b",
00335                                    "abcd abc bcd bx", re.LOCALE).group(1), "bx")
00336         self.assertEqual(re.search(r"\B(b.)\B",
00337                                    "abc bcd bc abxd", re.LOCALE).group(1), "bx")
00338         self.assertEqual(re.search(r"\b(b.)\b",
00339                                    "abcd abc bcd bx", re.UNICODE).group(1), "bx")
00340         self.assertEqual(re.search(r"\B(b.)\B",
00341                                    "abc bcd bc abxd", re.UNICODE).group(1), "bx")
00342         self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc")
00343         self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc")
00344         self.assertEqual(re.search(r"^\Aabc\Z$", "\nabc\n", re.M), None)
00345         self.assertEqual(re.search(r"\b(b.)\b",
00346                                    "abcd abc bcd bx").group(1), "bx")
00347         self.assertEqual(re.search(r"\B(b.)\B",
00348                                    "abc bcd bc abxd").group(1), "bx")
00349         self.assertEqual(re.search(r"^abc$", "\nabc\n", re.M).group(0), "abc")
00350         self.assertEqual(re.search(r"^\Aabc\Z$", "abc", re.M).group(0), "abc")
00351         self.assertEqual(re.search(r"^\Aabc\Z$", "\nabc\n", re.M), None)
00352         self.assertEqual(re.search(r"\d\D\w\W\s\S",
00353                                    "1aa! a").group(0), "1aa! a")
00354         self.assertEqual(re.search(r"\d\D\w\W\s\S",
00355                                    "1aa! a", re.LOCALE).group(0), "1aa! a")
00356         self.assertEqual(re.search(r"\d\D\w\W\s\S",
00357                                    "1aa! a", re.UNICODE).group(0), "1aa! a")

Here is the call graph for this function:

Definition at line 500 of file test_re.py.

00500 
00501     def test_sre_character_class_literals(self):
00502         for i in [0, 8, 16, 32, 64, 127, 128, 255]:
00503             self.assertNotEqual(re.match(r"[\%03o]" % i, chr(i)), None)
00504             self.assertNotEqual(re.match(r"[\%03o0]" % i, chr(i)), None)
00505             self.assertNotEqual(re.match(r"[\%03o8]" % i, chr(i)), None)
00506             self.assertNotEqual(re.match(r"[\x%02x]" % i, chr(i)), None)
00507             self.assertNotEqual(re.match(r"[\x%02x0]" % i, chr(i)), None)
00508             self.assertNotEqual(re.match(r"[\x%02xz]" % i, chr(i)), None)
00509         self.assertRaises(re.error, re.match, "[\911]", "")

Here is the call graph for this function:

Definition at line 490 of file test_re.py.

00490 
00491     def test_sre_character_literals(self):
00492         for i in [0, 8, 16, 32, 64, 127, 128, 255]:
00493             self.assertNotEqual(re.match(r"\%03o" % i, chr(i)), None)
00494             self.assertNotEqual(re.match(r"\%03o0" % i, chr(i)+"0"), None)
00495             self.assertNotEqual(re.match(r"\%03o8" % i, chr(i)+"8"), None)
00496             self.assertNotEqual(re.match(r"\x%02x" % i, chr(i)), None)
00497             self.assertNotEqual(re.match(r"\x%02x0" % i, chr(i)+"0"), None)
00498             self.assertNotEqual(re.match(r"\x%02xz" % i, chr(i)+"z"), None)
00499         self.assertRaises(re.error, re.match, "\911", "")

Here is the call graph for this function:

Definition at line 544 of file test_re.py.

00544 
00545     def test_stack_overflow(self):
00546         # nasty cases that used to overflow the straightforward recursive
00547         # implementation of repeated groups.
00548         self.assertEqual(re.match('(x)*', 50000*'x').group(1), 'x')
00549         self.assertEqual(re.match('(x)*y', 50000*'x'+'y').group(1), 'x')
00550         self.assertEqual(re.match('(x)*?y', 50000*'x'+'y').group(1), 'x')

Here is the call graph for this function:

Definition at line 97 of file test_re.py.

00097 
00098     def test_sub_template_numeric_escape(self):
00099         # bug 776311 and friends
00100         self.assertEqual(re.sub('x', r'\0', 'x'), '\0')
00101         self.assertEqual(re.sub('x', r'\000', 'x'), '\000')
00102         self.assertEqual(re.sub('x', r'\001', 'x'), '\001')
00103         self.assertEqual(re.sub('x', r'\008', 'x'), '\0' + '8')
00104         self.assertEqual(re.sub('x', r'\009', 'x'), '\0' + '9')
00105         self.assertEqual(re.sub('x', r'\111', 'x'), '\111')
00106         self.assertEqual(re.sub('x', r'\117', 'x'), '\117')
00107 
00108         self.assertEqual(re.sub('x', r'\1111', 'x'), '\1111')
00109         self.assertEqual(re.sub('x', r'\1111', 'x'), '\111' + '1')
00110 
00111         self.assertEqual(re.sub('x', r'\00', 'x'), '\x00')
00112         self.assertEqual(re.sub('x', r'\07', 'x'), '\x07')
00113         self.assertEqual(re.sub('x', r'\08', 'x'), '\0' + '8')
00114         self.assertEqual(re.sub('x', r'\09', 'x'), '\0' + '9')
00115         self.assertEqual(re.sub('x', r'\0a', 'x'), '\0' + 'a')
00116 
00117         self.assertEqual(re.sub('x', r'\400', 'x'), '\0')
00118         self.assertEqual(re.sub('x', r'\777', 'x'), '\377')
00119 
00120         self.assertRaises(re.error, re.sub, 'x', r'\1', 'x')
00121         self.assertRaises(re.error, re.sub, 'x', r'\8', 'x')
00122         self.assertRaises(re.error, re.sub, 'x', r'\9', 'x')
00123         self.assertRaises(re.error, re.sub, 'x', r'\11', 'x')
00124         self.assertRaises(re.error, re.sub, 'x', r'\18', 'x')
00125         self.assertRaises(re.error, re.sub, 'x', r'\1a', 'x')
00126         self.assertRaises(re.error, re.sub, 'x', r'\90', 'x')
00127         self.assertRaises(re.error, re.sub, 'x', r'\99', 'x')
00128         self.assertRaises(re.error, re.sub, 'x', r'\118', 'x') # r'\11' + '8'
00129         self.assertRaises(re.error, re.sub, 'x', r'\11a', 'x')
00130         self.assertRaises(re.error, re.sub, 'x', r'\181', 'x') # r'\18' + '1'
00131         self.assertRaises(re.error, re.sub, 'x', r'\800', 'x') # r'\80' + '0'
00132 
00133         # in python2.3 (etc), these loop endlessly in sre_parser.py
00134         self.assertEqual(re.sub('(((((((((((x)))))))))))', r'\11', 'x'), 'x')
00135         self.assertEqual(re.sub('((((((((((y))))))))))(.)', r'\118', 'xyz'),
00136                          'xz8')
00137         self.assertEqual(re.sub('((((((((((y))))))))))(.)', r'\11a', 'xyz'),
00138                          'xza')

Here is the call graph for this function:

Definition at line 152 of file test_re.py.

00152 
00153     def test_symbolic_refs(self):
00154         self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a', 'xx')
00155         self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<', 'xx')
00156         self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g', 'xx')
00157         self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<a a>', 'xx')
00158         self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<1a1>', 'xx')
00159         self.assertRaises(IndexError, re.sub, '(?P<a>x)', '\g<ab>', 'xx')
00160         self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
00161         self.assertRaises(re.error, re.sub, '(?P<a>x)|(?P<b>y)', '\\2', 'xx')
00162         self.assertRaises(re.error, re.sub, '(?P<a>x)', '\g<-1>', 'xx')

Here is the call graph for this function:

Definition at line 19 of file test_re.py.

00019 
00020     def test_weakref(self):
00021         s = 'QabbbcR'
00022         x = re.compile('ab+c')
00023         y = proxy(x)
00024         self.assertEqual(x.findall('QabbbcR'), y.findall('QabbbcR'))

Here is the call graph for this function:


The documentation for this class was generated from the following file: