mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Misc/NEWS 1.387->1.388 Lib/test/string_tests.py 1.10->1.11, 1.12->1.14, Lib/test/test_unicode.py 1.50->1.51, 1.53->1.54, 1.55->1.56 Lib/test/test_string.py 1.15->1.16 Lib/string.py 1.61->1.63 Lib/test/test_userstring.py 1.5->1.6, 1.11, 1.12 Objects/stringobject.c 2.156->2.159 Objects/unicodeobject.c 2.137->2.139 Doc/lib/libstdtypes.tec 1.87->1.88 Add a method zfill to str, unicode and UserString and change Lib/string.py accordingly (see SF patch http://www.python.org/sf/536241) This also adds Guido's fix to test_userstring.py and the subinstance checks in test_string.py and test_unicode.py.
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
from test_support import verbose, TestSkipped
|
|
import string_tests
|
|
import string, sys
|
|
|
|
# XXX: kludge... short circuit if strings don't have methods
|
|
try:
|
|
''.join
|
|
except AttributeError:
|
|
raise TestSkipped
|
|
|
|
def test(name, input, output, *args):
|
|
if verbose:
|
|
print 'string.%s%s =? %s... ' % (name, (input,) + args, output),
|
|
try:
|
|
# Prefer string methods over string module functions
|
|
try:
|
|
f = getattr(input, name)
|
|
value = apply(f, args)
|
|
except AttributeError:
|
|
f = getattr(string, name)
|
|
value = apply(f, (input,) + args)
|
|
except:
|
|
value = sys.exc_type
|
|
f = name
|
|
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:
|
|
print 'no'
|
|
print '*',f, `input`, `output`, `value`
|
|
return
|
|
if value != output:
|
|
if verbose:
|
|
print 'no'
|
|
print f, `input`, `output`, `value`
|
|
else:
|
|
if verbose:
|
|
print 'yes'
|
|
|
|
string_tests.run_module_tests(test)
|
|
string_tests.run_method_tests(test)
|
|
|
|
string.whitespace
|
|
string.lowercase
|
|
string.uppercase
|