diff options
author | Fredrik Lundh <fredrik@pythonware.com> | 2000-08-08 16:47:42 (GMT) |
---|---|---|
committer | Fredrik Lundh <fredrik@pythonware.com> | 2000-08-08 16:47:42 (GMT) |
commit | 1151a8cd616003e65b88717ed7e612b6b6e71484 (patch) | |
tree | a871e92f77a1be319fe5a82c1c025368000a801b /Lib | |
parent | 8141cf5c76a1a47ccacc14aa4594fcc89499799a (diff) | |
download | cpython-1151a8cd616003e65b88717ed7e612b6b6e71484.zip cpython-1151a8cd616003e65b88717ed7e612b6b6e71484.tar.gz cpython-1151a8cd616003e65b88717ed7e612b6b6e71484.tar.bz2 |
-- whitespace cleanup (more tests to be added in the next commit)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_re.py | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index d096111..fa28417 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -37,20 +37,20 @@ if verbose: try: assert re.sub("(?i)b+", "x", "bbbb BBBB") == 'x x' - + def bump_num(matchobj): int_value = int(matchobj.group(0)) return str(int_value + 1) assert re.sub(r'\d+', bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y' assert re.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3) == '9.3 -3 23x99y' - + assert re.sub('.', lambda m: r"\n", 'x') == '\\n' assert re.sub('.', r"\n", 'x') == '\n' s = r"\1\1" assert re.sub('(.)', s, 'x') == 'xx' - assert re.sub('(.)', re.escape(s), 'x') == s + assert re.sub('(.)', re.escape(s), 'x') == s assert re.sub('(.)', lambda m: s, 'x') == s assert re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx') == 'xxxx' @@ -146,7 +146,7 @@ except AssertionError: if verbose: print 'Running tests on re.split' - + try: assert re.split(":", ":a:b::c") == ['', 'a', 'b', '', 'c'] assert re.split(":*", ":a:b::c") == ['', 'a', 'b', 'c'] @@ -165,7 +165,7 @@ try: assert re.split(':', 'a:b:c:d', 2) == ['a', 'b', 'c:d'] assert re.split("(:)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c'] - assert re.split("(:*)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c'] + assert re.split("(:*)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c'] except AssertionError: raise TestFailed, "qualified re.split" @@ -187,29 +187,29 @@ if verbose: try: # No groups at all - m = re.match('a', 'a') ; assert m.groups() == () + m = re.match('a', 'a') ; assert m.groups() == () # A single group - m = re.match('(a)', 'a') ; assert m.groups() == ('a',) + m = re.match('(a)', 'a') ; assert m.groups() == ('a',) pat = re.compile('((a)|(b))(c)?') - assert pat.match('a').groups() == ('a', 'a', None, None) - assert pat.match('b').groups() == ('b', None, 'b', None) - assert pat.match('ac').groups() == ('a', 'a', None, 'c') - assert pat.match('bc').groups() == ('b', None, 'b', 'c') - assert pat.match('bc').groups("") == ('b', "", 'b', 'c') + assert pat.match('a').groups() == ('a', 'a', None, None) + assert pat.match('b').groups() == ('b', None, 'b', None) + assert pat.match('ac').groups() == ('a', 'a', None, 'c') + assert pat.match('bc').groups() == ('b', None, 'b', 'c') + assert pat.match('bc').groups("") == ('b', "", 'b', 'c') except AssertionError: raise TestFailed, "match .groups() method" try: # A single group - m = re.match('(a)', 'a') - assert m.group(0) == 'a' ; assert m.group(0) == 'a' + m = re.match('(a)', 'a') + assert m.group(0) == 'a' ; assert m.group(0) == 'a' assert m.group(1) == 'a' ; assert m.group(1, 1) == ('a', 'a') pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?') - assert pat.match('a').group(1, 2, 3) == ('a', None, None) - assert pat.match('b').group('a1', 'b2', 'c3') == (None, 'b', None) - assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c') + assert pat.match('a').group(1, 2, 3) == ('a', None, None) + assert pat.match('b').group('a1', 'b2', 'c3') == (None, 'b', None) + assert pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c') except AssertionError: raise TestFailed, "match .group() method" @@ -242,8 +242,8 @@ try: assert re.I == re.IGNORECASE assert re.L == re.LOCALE assert re.M == re.MULTILINE - assert re.S == re.DOTALL - assert re.X == re.VERBOSE + assert re.S == re.DOTALL + assert re.X == re.VERBOSE except AssertionError: raise TestFailed, 're module constants' @@ -260,7 +260,7 @@ if verbose: else: # To save time, only run the first and last 10 tests #tests = tests[:10] + tests[-10:] - pass + pass for t in tests: sys.stdout.flush() @@ -268,7 +268,7 @@ for t in tests: if len(t)==5: pattern, s, outcome, repl, expected = t elif len(t)==3: - pattern, s, outcome = t + pattern, s, outcome = t else: raise ValueError, ('Test tuples should have 3 or 5 fields',t) @@ -276,7 +276,7 @@ for t in tests: obj=re.compile(pattern) except re.error: if outcome==SYNTAX_ERROR: pass # Expected a syntax error - else: + else: print '=== Syntax error:', t except KeyboardInterrupt: raise KeyboardInterrupt except: @@ -330,7 +330,7 @@ for t in tests: # of the match and see if it still succeeds. \B will # break (because it won't match at the end or start of a # string), so we'll ignore patterns that feature it. - + if pattern[:2]!='\\B' and pattern[-2:]!='\\B' and result!=None: obj=re.compile(pattern) result=obj.search(s, result.start(0), result.end(0)+1) |