blob: 3574719df484aaf7fc40f4fd00aa6b18a2b553a9 [file] [log] [blame]
Fredrik Lundhf7850422001-01-17 21:51:36 +00001from test_support import verbose, TestSkipped
Jeremy Hyltonf82b04e2000-07-10 17:08:42 +00002import string_tests
Barry Warsaw50f0e161999-06-10 22:53:10 +00003import string, sys
4
Barry Warsaw6e1d78a1999-06-15 16:49:11 +00005# XXX: kludge... short circuit if strings don't have methods
6try:
7 ''.join
8except AttributeError:
Thomas Woutersb9fa0a82000-08-04 13:34:43 +00009 raise TestSkipped
Barry Warsaw6e1d78a1999-06-15 16:49:11 +000010
Barry Warsaw50f0e161999-06-10 22:53:10 +000011def test(name, input, output, *args):
12 if verbose:
13 print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
Barry Warsaw50f0e161999-06-10 22:53:10 +000014 try:
Guido van Rossuma831cac2000-03-10 23:23:21 +000015 # Prefer string methods over string module functions
Barry Warsaw8a9514a1999-06-11 17:48:07 +000016 try:
Barry Warsaw8a9514a1999-06-11 17:48:07 +000017 f = getattr(input, name)
18 value = apply(f, args)
Guido van Rossuma831cac2000-03-10 23:23:21 +000019 except AttributeError:
20 f = getattr(string, name)
21 value = apply(f, (input,) + args)
Barry Warsaw50f0e161999-06-10 22:53:10 +000022 except:
Fred Drake004d5e62000-10-23 17:22:08 +000023 value = sys.exc_type
Barry Warsaw50f0e161999-06-10 22:53:10 +000024 if value != output:
25 if verbose:
26 print 'no'
27 print f, `input`, `output`, `value`
28 else:
29 if verbose:
30 print 'yes'
31
Jeremy Hyltonf82b04e2000-07-10 17:08:42 +000032string_tests.run_module_tests(test)
33string_tests.run_method_tests(test)
Barry Warsaw50f0e161999-06-10 22:53:10 +000034
35string.whitespace
36string.lowercase
37string.uppercase