annotate Lib/test/test_userstring.py @ 17322:bd110eadc19a legacy-trunk

One-liner critical fix from Jim Fulton: Eric's string-method crusade got the order backwards in a line (for .find()).
author Tim Peters <tim.peters@gmail.com>
date Thu, 05 Apr 2001 22:26:23 +0000
parents b3d923a66152
children 0b1e20c34c8e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12214
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
1 #!/usr/bin/env python
16518
b3d923a66152 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 15966
diff changeset
2 import sys
15966
e59b835ad89a a bold attempt to fix things broken by MAL's verify patch: import
Fredrik Lundh <fredrik@pythonware.com>
parents: 15957
diff changeset
3 from test_support import verbose
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12214
diff changeset
4 import string_tests
12214
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
5 # UserString is a wrapper around the native builtin string type.
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
6 # UserString instances should behave similar to builtin string objects.
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
7 # The test cases were in part derived from 'test_string.py'.
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
8 from UserString import UserString
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
9
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
10 if __name__ == "__main__":
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
11 verbose = 0
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
12
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
13 tested_methods = {}
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
14
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
15 def test(methodname, input, *args):
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
16 global tested_methods
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
17 tested_methods[methodname] = 1
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
18 if verbose:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
19 print '%s.%s(%s) ' % (input, methodname, args),
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
20 u = UserString(input)
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
21 objects = [input, u, UserString(u)]
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
22 res = [""] * 3
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
23 for i in range(3):
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
24 object = objects[i]
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
25 try:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
26 f = getattr(object, methodname)
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
27 res[i] = apply(f, args)
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
28 except:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
29 res[i] = sys.exc_type
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
30 if res[0] != res[1]:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
31 if verbose:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
32 print 'no'
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
33 print `input`, f, `res[0]`, "<>", `res[1]`
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
34 else:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
35 if verbose:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
36 print 'yes'
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
37 if res[1] != res[2]:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
38 if verbose:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
39 print 'no'
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
40 print `input`, f, `res[1]`, "<>", `res[2]`
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
41 else:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
42 if verbose:
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
43 print 'yes'
a216fe79ae00 UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff changeset
44
13517
4f110441db39 factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12214
diff changeset
45 string_tests.run_method_tests(test)