2002-07-23 16:04:11 -03:00
|
|
|
from test.test_support import verbose, TestSkipped
|
|
|
|
from test 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
|
2002-04-17 18:34:05 -03:00
|
|
|
if value == output:
|
|
|
|
# if the original is returned make sure that
|
|
|
|
# this doesn't happen with subclasses
|
|
|
|
if value is input:
|
|
|
|
class ssub(str):
|
|
|
|
def __repr__(self):
|
|
|
|
return 'ssub(%r)' % str.__repr__(self)
|
|
|
|
input = ssub(input)
|
|
|
|
try:
|
|
|
|
f = getattr(input, name)
|
|
|
|
value = apply(f, args)
|
|
|
|
except AttributeError:
|
|
|
|
f = getattr(string, name)
|
|
|
|
value = apply(f, (input,) + args)
|
|
|
|
if value is input:
|
|
|
|
if verbose:
|
2002-05-23 12:15:30 -03:00
|
|
|
print 'no'
|
2002-04-17 18:34:05 -03:00
|
|
|
print '*',f, `input`, `output`, `value`
|
|
|
|
return
|
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)
|
2002-08-06 13:58:21 -03:00
|
|
|
string_tests.run_contains_tests(test)
|
2002-08-08 22:37:06 -03:00
|
|
|
string_tests.run_inplace_tests(str)
|
1999-06-10 19:53:10 -03:00
|
|
|
|
|
|
|
string.whitespace
|
|
|
|
string.lowercase
|
|
|
|
string.uppercase
|