Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 0832165c43cc059ca2d8de0bef09990f6ebdcae0 authored by cvs2svn on 18 March 2002, 16:47:35 UTC
This commit was manufactured by cvs2svn to create tag 'r221c1'.
Tip revision: 0832165
test_string.py
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 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
back to top