summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-04-12 16:25:39 +0000
committerGuido van Rossum <guido@python.org>2002-04-12 16:25:39 +0000
commitd854f3b3cc1daaab6b9cad00a2e2baf482dde382 (patch)
tree789ed18e51df5db498842083f1ca687877b08268 /Lib/test
parentee48519bc63c2d423bcc267437d26722fbc37c4e (diff)
downloadcpython-git-d854f3b3cc1daaab6b9cad00a2e2baf482dde382.tar.gz
I am mad. This test never worked!
The test function's signature should be test(methodname, input, output, *args) but the output argument was omitted. This caused all tests to fail, because the expected output was passed as the initial argument to the method call. But because of the way the test works (it compares the results for a regular string to the results for a UserString instance with the same value, and it's OK if both raise the same exception) the test never failed! I've fixed this, and also cleaned up a few warts in the verbose output. Finally, I've made it possible to run the test stand-alone in verbose mode by passing -v as a command line argument. Now, the test will report failure related to zfill. That's not my fault, that's a legitimate problem: the string_tests.py file contains a test for the zfill() method (just added) but this method is not implemented. The responsible party will surely fix this soon now.
Diffstat (limited to 'Lib/test')
-rwxr-xr-xLib/test/test_userstring.py30
1 files changed, 14 insertions, 16 deletions
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py
index a8df84d7ba..86997ce374 100755
--- a/Lib/test/test_userstring.py
+++ b/Lib/test/test_userstring.py
@@ -8,15 +8,15 @@ import string_tests
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 @@ def test(methodname, input, *args):
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]:
- if verbose:
- print 'no'
- print `input`, f, `res[1]`, "<>", `res[2]`
else:
if verbose:
- print 'yes'
+ print 'no'
+ print (methodname, input, output, args, res[0], res[1], res[2])
string_tests.run_method_tests(test)