Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_userstring.py @ 25135:0f0016632be4 legacy-trunk
_formatparam(), set_param(): RFC 2231 encoding support by Oleg
Broytmann in SF patch #600096. Specifically, the former function now
encodes the triplets, while the latter adds optional charset and
language arguments.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Fri, 06 Sep 2002 03:55:04 +0000 |
| parents | 274e42a691e0 |
| children | fe10ece8ba68 |
| 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 |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23000
diff
changeset
|
3 from test.test_support import verbose |
|
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23000
diff
changeset
|
4 from test 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__": |
|
23000
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
11 verbose = '-v' in sys.argv |
|
12214
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 |
|
23000
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
15 def test(methodname, input, output, *args): |
|
12214
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: |
|
23000
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
19 print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))), |
|
12214
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) |
|
23000
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
27 except AttributeError: |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
28 f = None |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
29 res[i] = AttributeError |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
30 else: |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
31 try: |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
32 res[i] = apply(f, args) |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
33 except: |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
34 res[i] = sys.exc_type |
|
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
35 if res[0] == res[1] == res[2] == output: |
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 if verbose: |
|
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 print 'yes' |
|
23000
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
38 else: |
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 if verbose: |
|
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 print 'no' |
|
23000
0b1e20c34c8e
I am mad. This test never worked!
Guido van Rossum <guido@python.org>
parents:
16518
diff
changeset
|
41 print (methodname, input, output, args, res[0], res[1], res[2]) |
|
12214
a216fe79ae00
UserString class from Peter Funk <pf@artcom-gmbh.de>.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
42 |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12214
diff
changeset
|
43 string_tests.run_method_tests(test) |
|
24598
12e146171f3d
Committing patch #591250 which provides "str1 in str2" when str1 is a
Barry Warsaw <barry@python.org>
parents:
24364
diff
changeset
|
44 string_tests.run_contains_tests(test) |
|
24684
274e42a691e0
Moved inplace add and multiply methods from UserString to MutableString.
Raymond Hettinger <python@rcn.com>
parents:
24598
diff
changeset
|
45 string_tests.run_inplace_tests(UserString) |
