[Python-checkins] CVS: python/dist/src/Lib/test test_sre.py,1.10,1.11 re_tests.py,1.18,1.19

Fredrik Lundh python-dev@python.org
Sun, 3 Sep 2000 03:43:19 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory slayer.i.sourceforge.net:/tmp/cvs-serv2426/Lib/test

Modified Files:
	test_sre.py re_tests.py 
Log Message:


updated SRE test suite (fixes PEP223 problem, shows syntax errors)

Index: test_sre.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sre.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** test_sre.py	2000/09/03 08:15:19	1.10
--- test_sre.py	2000/09/03 10:43:16	1.11
***************
*** 48,54 ****
  
  for i in [0, 8, 16, 32, 64, 127, 128, 255]:
!     test(r"""sre.match("\%03o" % i, chr(i)) != None""", 1)
!     test(r"""sre.match("\%03o0" % i, chr(i)+"0") != None""", 1)
!     test(r"""sre.match("\%03o8" % i, chr(i)+"8") != None""", 1)
      test(r"""sre.match(r"\x%02x" % i, chr(i)) != None""", 1)
      test(r"""sre.match(r"\x%02x0" % i, chr(i)+"0") != None""", 1)
--- 48,54 ----
  
  for i in [0, 8, 16, 32, 64, 127, 128, 255]:
!     test(r"""sre.match(r"\%03o" % i, chr(i)) != None""", 1)
!     test(r"""sre.match(r"\%03o0" % i, chr(i)+"0") != None""", 1)
!     test(r"""sre.match(r"\%03o8" % i, chr(i)+"8") != None""", 1)
      test(r"""sre.match(r"\x%02x" % i, chr(i)) != None""", 1)
      test(r"""sre.match(r"\x%02x0" % i, chr(i)+"0") != None""", 1)
***************
*** 62,86 ****
      print 'Running tests on sre.search and sre.match'
  
! test(r"""sre.search('x*', 'axx').span(0)""", (0, 0))
! test(r"""sre.search('x*', 'axx').span()""", (0, 0))
! test(r"""sre.search('x+', 'axx').span(0)""", (1, 3))
! test(r"""sre.search('x+', 'axx').span()""", (1, 3))
! test(r"""sre.search('x', 'aaa')""", None)
! 
! test(r"""sre.match('a*', 'xxx').span(0)""", (0, 0))
! test(r"""sre.match('a*', 'xxx').span()""", (0, 0))
! test(r"""sre.match('x*', 'xxxa').span(0)""", (0, 3))
! test(r"""sre.match('x*', 'xxxa').span()""", (0, 3))
! test(r"""sre.match('a+', 'xxx')""", None)
  
  # bug 113254
! test(r"""sre.match('(a)|(b)', 'b').start(1)""", -1)
! test(r"""sre.match('(a)|(b)', 'b').end(1)""", -1)
! test(r"""sre.match('(a)|(b)', 'b').span(1)""", (-1, -1))
  
  if verbose:
      print 'Running tests on sre.sub'
  
! test(r"""sre.sub("(?i)b+", "x", "bbbb BBBB")""", 'x x')
  
  def bump_num(matchobj):
--- 62,86 ----
      print 'Running tests on sre.search and sre.match'
  
! test(r"""sre.search(r'x*', 'axx').span(0)""", (0, 0))
! test(r"""sre.search(r'x*', 'axx').span()""", (0, 0))
! test(r"""sre.search(r'x+', 'axx').span(0)""", (1, 3))
! test(r"""sre.search(r'x+', 'axx').span()""", (1, 3))
! test(r"""sre.search(r'x', 'aaa')""", None)
! 
! test(r"""sre.match(r'a*', 'xxx').span(0)""", (0, 0))
! test(r"""sre.match(r'a*', 'xxx').span()""", (0, 0))
! test(r"""sre.match(r'x*', 'xxxa').span(0)""", (0, 3))
! test(r"""sre.match(r'x*', 'xxxa').span()""", (0, 3))
! test(r"""sre.match(r'a+', 'xxx')""", None)
  
  # bug 113254
! test(r"""sre.match(r'(a)|(b)', 'b').start(1)""", -1)
! test(r"""sre.match(r'(a)|(b)', 'b').end(1)""", -1)
! test(r"""sre.match(r'(a)|(b)', 'b').span(1)""", (-1, -1))
  
  if verbose:
      print 'Running tests on sre.sub'
  
! test(r"""sre.sub(r"(?i)b+", "x", "bbbb BBBB")""", 'x x')
  
  def bump_num(matchobj):
***************
*** 91,178 ****
  test(r"""sre.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3)""", '9.3 -3 23x99y')
  
! test(r"""sre.sub('.', lambda m: r"\n", 'x')""", '\\n')
! test(r"""sre.sub('.', r"\n", 'x')""", '\n')
  
  s = r"\1\1"
  
! test(r"""sre.sub('(.)', s, 'x')""", 'xx')
! test(r"""sre.sub('(.)', sre.escape(s), 'x')""", s)
! test(r"""sre.sub('(.)', lambda m: s, 'x')""", s)
! 
! test(r"""sre.sub('(?P<a>x)', '\g<a>\g<a>', 'xx')""", 'xxxx')
! test(r"""sre.sub('(?P<a>x)', '\g<a>\g<1>', 'xx')""", 'xxxx')
! test(r"""sre.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx')""", 'xxxx')
! test(r"""sre.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx')""", 'xxxx')
! 
! test(r"""sre.sub('a', r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D', 'a')""", '\t\n\v\r\f\a\b\\B\\Z\a\\A\\w\\W\\s\\S\\d\\D')
! test(r"""sre.sub('a', '\t\n\v\r\f\a', 'a')""", '\t\n\v\r\f\a')
! test(r"""sre.sub('a', '\t\n\v\r\f\a', 'a')""", (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)))
  
! test(r"""sre.sub('^\s*', 'X', 'test')""", 'Xtest')
  
  # qualified sub
! test(r"""sre.sub('a', 'b', 'aaaaa')""", 'bbbbb')
! test(r"""sre.sub('a', 'b', 'aaaaa', 1)""", 'baaaa')
  
  if verbose:
      print 'Running tests on symbolic references'
  
! test(r"""sre.sub('(?P<a>x)', '\g<a', 'xx')""", None, sre.error)
! test(r"""sre.sub('(?P<a>x)', '\g<', 'xx')""", None, sre.error)
! test(r"""sre.sub('(?P<a>x)', '\g', 'xx')""", None, sre.error)
! test(r"""sre.sub('(?P<a>x)', '\g<a a>', 'xx')""", None, sre.error)
! test(r"""sre.sub('(?P<a>x)', '\g<1a1>', 'xx')""", None, sre.error)
! test(r"""sre.sub('(?P<a>x)', '\g<ab>', 'xx')""", None, IndexError)
! test(r"""sre.sub('(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')""", None, sre.error)
! test(r"""sre.sub('(?P<a>x)|(?P<b>y)', '\\2', 'xx')""", None, sre.error)
  
  if verbose:
      print 'Running tests on sre.subn'
  
! test(r"""sre.subn("(?i)b+", "x", "bbbb BBBB")""", ('x x', 2))
! test(r"""sre.subn("b+", "x", "bbbb BBBB")""", ('x BBBB', 1))
! test(r"""sre.subn("b+", "x", "xyz")""", ('xyz', 0))
! test(r"""sre.subn("b*", "x", "xyz")""", ('xxxyxzx', 4))
! test(r"""sre.subn("b*", "x", "xyz", 2)""", ('xxxyz', 2))
  
  if verbose:
      print 'Running tests on sre.split'
  
! test(r"""sre.split(":", ":a:b::c")""", ['', 'a', 'b', '', 'c'])
! test(r"""sre.split(":*", ":a:b::c")""", ['', 'a', 'b', 'c'])
! test(r"""sre.split("(:*)", ":a:b::c")""", ['', ':', 'a', ':', 'b', '::', 'c'])
! test(r"""sre.split("(?::*)", ":a:b::c")""", ['', 'a', 'b', 'c'])
! test(r"""sre.split("(:)*", ":a:b::c")""", ['', ':', 'a', ':', 'b', ':', 'c'])
! test(r"""sre.split("([b:]+)", ":a:b::c")""", ['', ':', 'a', ':b::', 'c'])
! test(r"""sre.split("(b)|(:+)", ":a:b::c")""",
       ['', None, ':', 'a', None, ':', '', 'b', None, '', None, '::', 'c'])
! test(r"""sre.split("(?:b)|(?::+)", ":a:b::c")""", ['', 'a', '', '', 'c'])
  
! test(r"""sre.split(":", ":a:b::c", 2)""", ['', 'a', 'b::c'])
! test(r"""sre.split(':', 'a:b:c:d', 2)""", ['a', 'b', 'c:d'])
  
! test(r"""sre.split("(:)", ":a:b::c", 2)""", ['', ':', 'a', ':', 'b::c'])
! test(r"""sre.split("(:*)", ":a:b::c", 2)""", ['', ':', 'a', ':', 'b::c'])
  
  if verbose:
      print "Running tests on sre.findall"
  
! test(r"""sre.findall(":+", "abc")""", [])
! test(r"""sre.findall(":+", "a:b::c:::d")""", [":", "::", ":::"])
! test(r"""sre.findall("(:+)", "a:b::c:::d")""", [":", "::", ":::"])
! test(r"""sre.findall("(:)(:*)", "a:b::c:::d")""",
       [(":", ""), (":", ":"), (":", "::")])
! test(r"""sre.findall("(a)|(b)", "abc")""", [("a", ""), ("", "b")])
  
  if verbose:
      print "Running tests on sre.match"
  
! test(r"""sre.match('a', 'a').groups()""", ())
! test(r"""sre.match('(a)', 'a').groups()""", ('a',))
! test(r"""sre.match('(a)', 'a').group(0)""", 'a')
! test(r"""sre.match('(a)', 'a').group(1)""", 'a')
! test(r"""sre.match('(a)', 'a').group(1, 1)""", ('a', 'a'))
  
! pat = sre.compile('((a)|(b))(c)?')
  test(r"""pat.match('a').groups()""", ('a', 'a', None, None))
  test(r"""pat.match('b').groups()""", ('b', None, 'b', None))
--- 91,178 ----
  test(r"""sre.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3)""", '9.3 -3 23x99y')
  
! test(r"""sre.sub(r'.', lambda m: r"\n", 'x')""", '\\n')
! test(r"""sre.sub(r'.', r"\n", 'x')""", '\n')
  
  s = r"\1\1"
  
! test(r"""sre.sub(r'(.)', s, 'x')""", 'xx')
! test(r"""sre.sub(r'(.)', sre.escape(s), 'x')""", s)
! test(r"""sre.sub(r'(.)', lambda m: s, 'x')""", s)
! 
! test(r"""sre.sub(r'(?P<a>x)', '\g<a>\g<a>', 'xx')""", 'xxxx')
! test(r"""sre.sub(r'(?P<a>x)', '\g<a>\g<1>', 'xx')""", 'xxxx')
! test(r"""sre.sub(r'(?P<unk>x)', '\g<unk>\g<unk>', 'xx')""", 'xxxx')
! test(r"""sre.sub(r'(?P<unk>x)', '\g<1>\g<1>', 'xx')""", 'xxxx')
! 
! test(r"""sre.sub(r'a', r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D', 'a')""", '\t\n\v\r\f\a\b\\B\\Z\a\\A\\w\\W\\s\\S\\d\\D')
! test(r"""sre.sub(r'a', '\t\n\v\r\f\a', 'a')""", '\t\n\v\r\f\a')
! test(r"""sre.sub(r'a', '\t\n\v\r\f\a', 'a')""", (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)))
  
! test(r"""sre.sub(r'^\s*', 'X', 'test')""", 'Xtest')
  
  # qualified sub
! test(r"""sre.sub(r'a', 'b', 'aaaaa')""", 'bbbbb')
! test(r"""sre.sub(r'a', 'b', 'aaaaa', 1)""", 'baaaa')
  
  if verbose:
      print 'Running tests on symbolic references'
  
! test(r"""sre.sub(r'(?P<a>x)', '\g<a', 'xx')""", None, sre.error)
! test(r"""sre.sub(r'(?P<a>x)', '\g<', 'xx')""", None, sre.error)
! test(r"""sre.sub(r'(?P<a>x)', '\g', 'xx')""", None, sre.error)
! test(r"""sre.sub(r'(?P<a>x)', '\g<a a>', 'xx')""", None, sre.error)
! test(r"""sre.sub(r'(?P<a>x)', '\g<1a1>', 'xx')""", None, sre.error)
! test(r"""sre.sub(r'(?P<a>x)', '\g<ab>', 'xx')""", None, IndexError)
! test(r"""sre.sub(r'(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')""", None, sre.error)
! test(r"""sre.sub(r'(?P<a>x)|(?P<b>y)', '\\2', 'xx')""", None, sre.error)
  
  if verbose:
      print 'Running tests on sre.subn'
  
! test(r"""sre.subn(r"(?i)b+", "x", "bbbb BBBB")""", ('x x', 2))
! test(r"""sre.subn(r"b+", "x", "bbbb BBBB")""", ('x BBBB', 1))
! test(r"""sre.subn(r"b+", "x", "xyz")""", ('xyz', 0))
! test(r"""sre.subn(r"b*", "x", "xyz")""", ('xxxyxzx', 4))
! test(r"""sre.subn(r"b*", "x", "xyz", 2)""", ('xxxyz', 2))
  
  if verbose:
      print 'Running tests on sre.split'
  
! test(r"""sre.split(r":", ":a:b::c")""", ['', 'a', 'b', '', 'c'])
! test(r"""sre.split(r":*", ":a:b::c")""", ['', 'a', 'b', 'c'])
! test(r"""sre.split(r"(:*)", ":a:b::c")""", ['', ':', 'a', ':', 'b', '::', 'c'])
! test(r"""sre.split(r"(?::*)", ":a:b::c")""", ['', 'a', 'b', 'c'])
! test(r"""sre.split(r"(:)*", ":a:b::c")""", ['', ':', 'a', ':', 'b', ':', 'c'])
! test(r"""sre.split(r"([b:]+)", ":a:b::c")""", ['', ':', 'a', ':b::', 'c'])
! test(r"""sre.split(r"(b)|(:+)", ":a:b::c")""",
       ['', None, ':', 'a', None, ':', '', 'b', None, '', None, '::', 'c'])
! test(r"""sre.split(r"(?:b)|(?::+)", ":a:b::c")""", ['', 'a', '', '', 'c'])
  
! test(r"""sre.split(r":", ":a:b::c", 2)""", ['', 'a', 'b::c'])
! test(r"""sre.split(r':', 'a:b:c:d', 2)""", ['a', 'b', 'c:d'])
  
! test(r"""sre.split(r"(:)", ":a:b::c", 2)""", ['', ':', 'a', ':', 'b::c'])
! test(r"""sre.split(r"(:*)", ":a:b::c", 2)""", ['', ':', 'a', ':', 'b::c'])
  
  if verbose:
      print "Running tests on sre.findall"
  
! test(r"""sre.findall(r":+", "abc")""", [])
! test(r"""sre.findall(r":+", "a:b::c:::d")""", [":", "::", ":::"])
! test(r"""sre.findall(r"(:+)", "a:b::c:::d")""", [":", "::", ":::"])
! test(r"""sre.findall(r"(:)(:*)", "a:b::c:::d")""",
       [(":", ""), (":", ":"), (":", "::")])
! test(r"""sre.findall(r"(a)|(b)", "abc")""", [("a", ""), ("", "b")])
  
  if verbose:
      print "Running tests on sre.match"
  
! test(r"""sre.match(r'a', 'a').groups()""", ())
! test(r"""sre.match(r'(a)', 'a').groups()""", ('a',))
! test(r"""sre.match(r'(a)', 'a').group(0)""", 'a')
! test(r"""sre.match(r'(a)', 'a').group(1)""", 'a')
! test(r"""sre.match(r'(a)', 'a').group(1, 1)""", ('a', 'a'))
  
! pat = sre.compile(r'((a)|(b))(c)?')
  test(r"""pat.match('a').groups()""", ('a', 'a', None, None))
  test(r"""pat.match('b').groups()""", ('b', None, 'b', None))
***************
*** 181,185 ****
  test(r"""pat.match('bc').groups("")""", ('b', "", 'b', 'c'))
  
! pat = sre.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
  test(r"""pat.match('a').group(1, 2, 3)""", ('a', None, None))
  test(r"""pat.match('b').group('a1', 'b2', 'c3')""", (None, 'b', None))
--- 181,185 ----
  test(r"""pat.match('bc').groups("")""", ('b', "", 'b', 'c'))
  
! pat = sre.compile(r'(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
  test(r"""pat.match('a').group(1, 2, 3)""", ('a', None, None))
  test(r"""pat.match('b').group('a1', 'b2', 'c3')""", (None, 'b', None))
***************
*** 204,208 ****
  try:
      import pickle
!     pat = sre.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
      s = pickle.dumps(pat)
      pat = pickle.loads(s)
--- 204,208 ----
  try:
      import pickle
!     pat = sre.compile(r'a(?:b|(c|e){1,2}?|d)+?(.)')
      s = pickle.dumps(pat)
      pat = pickle.loads(s)
***************
*** 212,216 ****
  try:
      import cPickle
!     pat = sre.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
      s = cPickle.dumps(pat)
      pat = cPickle.loads(s)
--- 212,216 ----
  try:
      import cPickle
!     pat = sre.compile(r'a(?:b|(c|e){1,2}?|d)+?(.)')
      s = cPickle.dumps(pat)
      pat = cPickle.loads(s)
***************
*** 238,244 ****
  # Try nasty case that overflows the straightforward recursive
  # implementation of repeated groups.
! test(r"""sre.match('(x)*', 50000*'x').span()""", (0, 50000), RuntimeError)
! test(r"""sre.match('(x)*y', 50000*'x'+'y').span()""", (0, 50001), RuntimeError)
! test(r"""sre.match('(x)*?y', 50000*'x'+'y').span()""", (0, 50001), RuntimeError)
  
  from re_tests import *
--- 238,247 ----
  # Try nasty case that overflows the straightforward recursive
  # implementation of repeated groups.
! test(r"""sre.match(r'(x)*', 50000*'x').span()""",
!      (0, 50000), RuntimeError)
! test(r"""sre.match(r'(x)*y', 50000*'x'+'y').span()""",
!      (0, 50001), RuntimeError)
! test(r"""sre.match(r'(x)*?y', 50000*'x'+'y').span()""",
!      (0, 50001), RuntimeError)
  
  from re_tests import *
***************
*** 278,283 ****
              print '=== Unexpected exception', t, repr(msg)
          if outcome==SYNTAX_ERROR:
!             # This should have been a syntax error; forget it.
!             pass
          elif outcome==FAIL:
              if result is None: pass   # No match, as expected
--- 281,285 ----
              print '=== Unexpected exception', t, repr(msg)
          if outcome==SYNTAX_ERROR:
!             print '=== Compiled incorrectly', t
          elif outcome==FAIL:
              if result is None: pass   # No match, as expected

Index: re_tests.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/re_tests.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19