Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_string.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | a0005d26773d |
| children | b30fe4dcc697 aa0d2d51fbde |
| rev | line source |
|---|---|
|
15966
e59b835ad89a
a bold attempt to fix things broken by MAL's verify patch: import
Fredrik Lundh <fredrik@pythonware.com>
parents:
15957
diff
changeset
|
1 from test_support import verbose, TestSkipped |
|
13517
4f110441db39
factor out test definitions to string_tests module
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
13353
diff
changeset
|
2 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 |
|
23219
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
25 if value == output: |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
26 # if the original is returned make sure that |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
27 # this doesn't happen with subclasses |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
28 if value is input: |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
29 class ssub(str): |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
30 def __repr__(self): |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
31 return 'ssub(%r)' % str.__repr__(self) |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
32 input = ssub(input) |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
33 try: |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
34 f = getattr(input, name) |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
35 value = apply(f, args) |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
36 except AttributeError: |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
37 f = getattr(string, name) |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
38 value = apply(f, (input,) + args) |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
39 if value is input: |
|
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
40 if verbose: |
|
25622
a0005d26773d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
23219
diff
changeset
|
41 print 'no' |
|
23219
b08b51dce264
Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents:
21318
diff
changeset
|
42 print '*',f, `input`, `output`, `value` |
|
b08b51dce264
Backport the following changes:
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) |
|
10969
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
54 |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
55 string.whitespace |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
56 string.lowercase |
|
e1407d6320cb
Regression test for the new string methods.
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
57 string.uppercase |
