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