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