Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_string.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 | e153961f961f |
| rev | line source |
|---|---|
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23521
diff
changeset
|
1 from test.test_support import verbose, TestSkipped |
|
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
23521
diff
changeset
|
2 from test import string_tests |
|
10969
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
3 import string, sys |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
4 |
|
10987
e39a9f129163
Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents:
10981
diff
changeset
|
5 # XXX: kludge... short circuit if strings don't have methods |
|
e39a9f129163
Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents:
10981
diff
changeset
|
6 try: |
|
e39a9f129163
Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents:
10981
diff
changeset
|
7 ''.join |
|
e39a9f129163
Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents:
10981
diff
changeset
|
8 except AttributeError: |
|
13858
99f0413ef795
Raise 'TestSkipped' (from the test_support) module rather than 'ImportError'
Thomas Wouters <thomas@python.org>
parents:
13517
diff
changeset
|
9 raise TestSkipped |
|
10987
e39a9f129163
Added a couple of endswith test cases for bugs reported by Timbot.
Barry Warsaw <barry@python.org>
parents:
10981
diff
changeset
|
10 |
|
10969
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
11 def test(name, input, output, *args): |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
12 if verbose: |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
13 print 'string.%s%s =? %s... ' % (name, (input,) + args, output), |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
14 try: |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
10987
diff
changeset
|
15 # Prefer string methods over string module functions |
|
10974
51969fd73c4a
Harness can now test object methods directly, if they aren't available
Barry Warsaw <barry@python.org>
parents:
10969
diff
changeset
|
16 try: |
|
11992
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
10987
diff
changeset
|
17 f = getattr(input, name) |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
10987
diff
changeset
|
18 value = apply(f, args) |
|
1789fae5f074
Marc-Andre Lemburg: test script for Unicode implementation.
Guido van Rossum <guido@python.org>
parents:
10987
diff
changeset
|
19 except AttributeError: |
|
10974
51969fd73c4a
Harness can now test object methods directly, if they aren't available
Barry Warsaw <barry@python.org>
parents:
10969
diff
changeset
|
20 f = getattr(string, name) |
|
51969fd73c4a
Harness can now test object methods directly, if they aren't available
Barry Warsaw <barry@python.org>
parents:
10969
diff
changeset
|
21 value = apply(f, (input,) + args) |
|
10969
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
22 except: |
|
15305
07f24261c6e6
Make reindent.py happy (convert everything to 4-space indents!).
Fred Drake <fdrake@acm.org>
parents:
13858
diff
changeset
|
23 value = sys.exc_type |
|
21318
bb566f525f12
test(): Avoid a UnboundLocalError when a method is missing from both the string
Finn Bock <bckfnn@worldonline.dk>
parents:
15966
diff
changeset
|
24 f = name |
|
23115
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
25 if value == output: |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
26 # if the original is returned make sure that |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
27 # this doesn't happen with subclasses |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
28 if value is input: |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
29 class ssub(str): |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
30 def __repr__(self): |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
31 return 'ssub(%r)' % str.__repr__(self) |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
32 input = ssub(input) |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
33 try: |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
34 f = getattr(input, name) |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
35 value = apply(f, args) |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
36 except AttributeError: |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
37 f = getattr(string, name) |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
38 value = apply(f, (input,) + args) |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
39 if value is input: |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
40 if verbose: |
|
23521
a90faa5f9417
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
23115
diff
changeset
|
41 print 'no' |
|
23115
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
42 print '*',f, `input`, `output`, `value` |
|
7121d7d572d0
Apply diff3.txt from SF patch http://www.python.org/sf/536241
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
43 return |
|
10969
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
44 if value != output: |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
45 if verbose: |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
46 print 'no' |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
47 print f, `input`, `output`, `value` |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
48 else: |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
49 if verbose: |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
50 print 'yes' |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
51 |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13353
diff
changeset
|
52 string_tests.run_module_tests(test) |
|
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13353
diff
changeset
|
53 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
|
54 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
|
55 string_tests.run_inplace_tests(str) |
|
10969
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
56 |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
57 string.whitespace |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
58 string.lowercase |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
59 string.uppercase |
