[Python-checkins] python/dist/src/Lib/test string_tests.py,1.10.16.1,1.10.16.2 test_string.py,1.15,1.15.6.1 test_unicode.py,1.47.6.1,1.47.6.2 test_userstring.py,1.5,1.5.24.1

doerwalter@sourceforge.net doerwalter@sourceforge.net
Mon, 22 Apr 2002 04:57:07 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv17892/Lib/test

Modified Files:
      Tag: release22-maint
	string_tests.py test_string.py test_unicode.py 
	test_userstring.py 
Log Message:
Backport the following changes:

Misc/NEWS 1.387->1.388
Lib/test/string_tests.py 1.10->1.11, 1.12->1.14, 
Lib/test/test_unicode.py 1.50->1.51, 1.53->1.54, 1.55->1.56
Lib/test/test_string.py 1.15->1.16
Lib/string.py 1.61->1.63
Lib/test/test_userstring.py 1.5->1.6, 1.11, 1.12
Objects/stringobject.c 2.156->2.159
Objects/unicodeobject.c 2.137->2.139
Doc/lib/libstdtypes.tec 1.87->1.88

Add a method zfill to str, unicode and UserString 
and change Lib/string.py accordingly 
(see SF patch http://www.python.org/sf/536241)

This also adds Guido's fix to test_userstring.py
and the subinstance checks in test_string.py
and test_unicode.py.


Index: string_tests.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/string_tests.py,v
retrieving revision 1.10.16.1
retrieving revision 1.10.16.2
diff -C2 -d -r1.10.16.1 -r1.10.16.2
*** string_tests.py	18 Apr 2002 05:18:56 -0000	1.10.16.1
--- string_tests.py	22 Apr 2002 11:57:05 -0000	1.10.16.2
***************
*** 228,231 ****
--- 228,244 ----
      test('endswith', 'ab', 0, 'ab', 0, 0)
  
+     test('zfill', '123', '123', 2)
+     test('zfill', '123', '123', 3)
+     test('zfill', '123', '0123', 4)
+     test('zfill', '+123', '+123', 3)
+     test('zfill', '+123', '+123', 4)
+     test('zfill', '+123', '+0123', 5)
+     test('zfill', '-123', '-123', 3)
+     test('zfill', '-123', '-123', 4)
+     test('zfill', '-123', '-0123', 5)
+     test('zfill', '', '000', 3)
+     test('zfill', '34', '34', 1)
+     test('zfill', '34', '0034', 4)
+ 
      # Encoding/decoding
      codecs = [('rot13', 'uryyb jbeyq'),

Index: test_string.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_string.py,v
retrieving revision 1.15
retrieving revision 1.15.6.1
diff -C2 -d -r1.15 -r1.15.6.1
*** test_string.py	9 Dec 2001 16:06:29 -0000	1.15
--- test_string.py	22 Apr 2002 11:57:05 -0000	1.15.6.1
***************
*** 23,26 ****
--- 23,45 ----
          value = sys.exc_type
          f = name
+     if value == output:
+         # if the original is returned make sure that
+         # this doesn't happen with subclasses
+         if value is input:
+             class ssub(str):
+                 def __repr__(self):
+                     return 'ssub(%r)' % str.__repr__(self)
+             input = ssub(input)
+             try:
+                 f = getattr(input, name)
+                 value = apply(f, args)
+             except AttributeError:
+                 f = getattr(string, name)
+                 value = apply(f, (input,) + args)
+             if value is input:
+                 if verbose:
+                    print 'no'
+                 print '*',f, `input`, `output`, `value`
+                 return
      if value != output:
          if verbose:

Index: test_unicode.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_unicode.py,v
retrieving revision 1.47.6.1
retrieving revision 1.47.6.2
diff -C2 -d -r1.47.6.1 -r1.47.6.2
*** test_unicode.py	18 Mar 2002 12:54:51 -0000	1.47.6.1
--- test_unicode.py	22 Apr 2002 11:57:05 -0000	1.47.6.2
***************
*** 7,11 ****
  """#"
  from test_support import verify, verbose, TestFailed
! import sys
  
  if not sys.platform.startswith('java'):
--- 7,11 ----
  """#"
  from test_support import verify, verbose, TestFailed
! import sys, string
  
  if not sys.platform.startswith('java'):
***************
*** 204,207 ****
--- 204,220 ----
      test('capwords', u'abc\tdef\nghi', u'Abc Def Ghi')
      test('capwords', u'abc\t   def  \nghi', u'Abc Def Ghi')
+ 
+ test('zfill', u'123', u'123', 2)
+ test('zfill', u'123', u'123', 3)
+ test('zfill', u'123', u'0123', 4)
+ test('zfill', u'+123', u'+123', 3)
+ test('zfill', u'+123', u'+123', 4)
+ test('zfill', u'+123', u'+0123', 5)
+ test('zfill', u'-123', u'-123', 3)
+ test('zfill', u'-123', u'-123', 4)
+ test('zfill', u'-123', u'-0123', 5)
+ test('zfill', u'', u'000', 3)
+ test('zfill', u'34', u'34', 1)
+ test('zfill', u'34', u'00034', 5)
  
  # Comparisons:

Index: test_userstring.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_userstring.py,v
retrieving revision 1.5
retrieving revision 1.5.24.1
diff -C2 -d -r1.5 -r1.5.24.1
*** test_userstring.py	9 Feb 2001 12:00:47 -0000	1.5
--- test_userstring.py	22 Apr 2002 11:57:05 -0000	1.5.24.1
***************
*** 9,21 ****
  
  if __name__ == "__main__":
!     verbose = 0
  
  tested_methods = {}
  
! def test(methodname, input, *args):
      global tested_methods
      tested_methods[methodname] = 1
      if verbose:
!         print '%s.%s(%s) ' % (input, methodname, args),
      u = UserString(input)
      objects = [input, u, UserString(u)]
--- 9,21 ----
  
  if __name__ == "__main__":
!     verbose = '-v' in sys.argv
  
  tested_methods = {}
  
! def test(methodname, input, output, *args):
      global tested_methods
      tested_methods[methodname] = 1
      if verbose:
!         print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))),
      u = UserString(input)
      objects = [input, u, UserString(u)]
***************
*** 25,45 ****
          try:
              f = getattr(object, methodname)
!             res[i] = apply(f, args)
!         except:
!             res[i] = sys.exc_type
!     if res[0] != res[1]:
!         if verbose:
!             print 'no'
!         print `input`, f, `res[0]`, "<>", `res[1]`
!     else:
          if verbose:
              print 'yes'
-     if res[1] != res[2]:
-         if verbose:
-             print 'no'
-         print `input`, f, `res[1]`, "<>", `res[2]`
      else:
          if verbose:
!             print 'yes'
  
  string_tests.run_method_tests(test)
--- 25,43 ----
          try:
              f = getattr(object, methodname)
!         except AttributeError:
!             f = None
!             res[i] = AttributeError
!         else:
!             try:
!                 res[i] = apply(f, args)
!             except:
!                 res[i] = sys.exc_type
!     if res[0] == res[1] == res[2] == output:
          if verbose:
              print 'yes'
      else:
          if verbose:
!             print 'no'
!         print (methodname, input, output, args, res[0], res[1], res[2])
  
  string_tests.run_method_tests(test)