diff Lib/test/test_userstring.py @ 23219:b08b51dce264 2.2

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.
author Walter Dörwald <walter@livinglogic.de>
date Mon, 22 Apr 2002 11:57:06 +0000
parents b3d923a66152
children aa0d2d51fbde
line wrap: on
line diff
--- a/Lib/test/test_userstring.py	Mon Apr 22 11:21:59 2002 +0000
+++ b/Lib/test/test_userstring.py	Mon Apr 22 11:57:06 2002 +0000
@@ -8,15 +8,15 @@
 from UserString import UserString
 
 if __name__ == "__main__":
-    verbose = 0
+    verbose = '-v' in sys.argv
 
 tested_methods = {}
 
-def test(methodname, input, *args):
+def test(methodname, input, output, *args):
     global tested_methods
     tested_methods[methodname] = 1
     if verbose:
-        print '%s.%s(%s) ' % (input, methodname, args),
+        print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))),
     u = UserString(input)
     objects = [input, u, UserString(u)]
     res = [""] * 3
@@ -24,22 +24,20 @@
         object = objects[i]
         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:
+        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'
-    if res[1] != res[2]:
+    else:
         if verbose:
             print 'no'
-        print `input`, f, `res[1]`, "<>", `res[2]`
-    else:
-        if verbose:
-            print 'yes'
+        print (methodname, input, output, args, res[0], res[1], res[2])
 
 string_tests.run_method_tests(test)