annotate Lib/test/test_userstring.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 b08b51dce264
children aa0d2d51fbde
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__":
23219
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
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
23219
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
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:
23219
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
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)
23219
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
27 except AttributeError:
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
28 f = None
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
29 res[i] = AttributeError
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
30 else:
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
31 try:
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
32 res[i] = apply(f, args)
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
33 except:
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
parents: 16518
diff changeset
34 res[i] = sys.exc_type
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
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'
23219
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
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'
23219
b08b51dce264 Backport the following changes:
Walter Dörwald <walter@livinglogic.de>
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)