blob: 5492f2e526d23122c686106d68cc71d008267d5b [file] [log] [blame]
Fred Drakea22b5762000-04-03 03:51:50 +00001#!/usr/bin/env python
Eric S. Raymond2846b0a2001-02-09 12:00:47 +00002import sys
Barry Warsaw04f357c2002-07-23 19:04:11 +00003from test.test_support import verbose
4from test import string_tests
Fred Drakea22b5762000-04-03 03:51:50 +00005# UserString is a wrapper around the native builtin string type.
6# UserString instances should behave similar to builtin string objects.
7# The test cases were in part derived from 'test_string.py'.
8from UserString import UserString
9
10if __name__ == "__main__":
Guido van Rossumd854f3b2002-04-12 16:25:39 +000011 verbose = '-v' in sys.argv
Fred Drakea22b5762000-04-03 03:51:50 +000012
13tested_methods = {}
14
Guido van Rossumd854f3b2002-04-12 16:25:39 +000015def test(methodname, input, output, *args):
Fred Drakea22b5762000-04-03 03:51:50 +000016 global tested_methods
17 tested_methods[methodname] = 1
18 if verbose:
Guido van Rossumd854f3b2002-04-12 16:25:39 +000019 print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))),
Fred Drakea22b5762000-04-03 03:51:50 +000020 u = UserString(input)
21 objects = [input, u, UserString(u)]
22 res = [""] * 3
23 for i in range(3):
24 object = objects[i]
25 try:
26 f = getattr(object, methodname)
Guido van Rossumd854f3b2002-04-12 16:25:39 +000027 except AttributeError:
28 f = None
29 res[i] = AttributeError
30 else:
31 try:
32 res[i] = apply(f, args)
33 except:
34 res[i] = sys.exc_type
35 if res[0] == res[1] == res[2] == output:
Fred Drakea22b5762000-04-03 03:51:50 +000036 if verbose:
37 print 'yes'
Fred Drakea22b5762000-04-03 03:51:50 +000038 else:
39 if verbose:
Guido van Rossumd854f3b2002-04-12 16:25:39 +000040 print 'no'
41 print (methodname, input, output, args, res[0], res[1], res[2])
Fred Drakea22b5762000-04-03 03:51:50 +000042
Jeremy Hyltonf82b04e2000-07-10 17:08:42 +000043string_tests.run_method_tests(test)
Barry Warsaw817918c2002-08-06 16:58:21 +000044string_tests.run_contains_tests(test)