Updated for 2.1b2 distribution.
[python/dscho.git] / Lib / test / test_string.py
blob3574719df484aaf7fc40f4fd00aa6b18a2b553a9
1 from test_support import verbose, TestSkipped
2 import string_tests
3 import string, sys
5 # XXX: kludge... short circuit if strings don't have methods
6 try:
7 ''.join
8 except AttributeError:
9 raise TestSkipped
11 def test(name, input, output, *args):
12 if verbose:
13 print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
14 try:
15 # Prefer string methods over string module functions
16 try:
17 f = getattr(input, name)
18 value = apply(f, args)
19 except AttributeError:
20 f = getattr(string, name)
21 value = apply(f, (input,) + args)
22 except:
23 value = sys.exc_type
24 if value != output:
25 if verbose:
26 print 'no'
27 print f, `input`, `output`, `value`
28 else:
29 if verbose:
30 print 'yes'
32 string_tests.run_module_tests(test)
33 string_tests.run_method_tests(test)
35 string.whitespace
36 string.lowercase
37 string.uppercase