2001-01-18 05:51:36 +08:00
|
|
|
from test_support import verbose, TestSkipped
|
2000-07-11 01:08:42 +08:00
|
|
|
import string_tests
|
1999-06-11 06:53:10 +08:00
|
|
|
import string, sys
|
|
|
|
|
1999-06-16 00:49:11 +08:00
|
|
|
# XXX: kludge... short circuit if strings don't have methods
|
|
|
|
try:
|
|
|
|
''.join
|
|
|
|
except AttributeError:
|
2000-08-04 21:34:43 +08:00
|
|
|
raise TestSkipped
|
1999-06-16 00:49:11 +08:00
|
|
|
|
1999-06-11 06:53:10 +08:00
|
|
|
def test(name, input, output, *args):
|
|
|
|
if verbose:
|
|
|
|
print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
|
|
|
|
try:
|
2000-03-11 07:23:21 +08:00
|
|
|
# Prefer string methods over string module functions
|
1999-06-12 01:48:07 +08:00
|
|
|
try:
|
|
|
|
f = getattr(input, name)
|
|
|
|
value = apply(f, args)
|
2000-03-11 07:23:21 +08:00
|
|
|
except AttributeError:
|
|
|
|
f = getattr(string, name)
|
|
|
|
value = apply(f, (input,) + args)
|
1999-06-11 06:53:10 +08:00
|
|
|
except:
|
2000-10-24 01:22:08 +08:00
|
|
|
value = sys.exc_type
|
1999-06-11 06:53:10 +08:00
|
|
|
if value != output:
|
|
|
|
if verbose:
|
|
|
|
print 'no'
|
|
|
|
print f, `input`, `output`, `value`
|
|
|
|
else:
|
|
|
|
if verbose:
|
|
|
|
print 'yes'
|
|
|
|
|
2000-07-11 01:08:42 +08:00
|
|
|
string_tests.run_module_tests(test)
|
|
|
|
string_tests.run_method_tests(test)
|
1999-06-11 06:53:10 +08:00
|
|
|
|
|
|
|
string.whitespace
|
|
|
|
string.lowercase
|
|
|
|
string.uppercase
|