Пример #1
0

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
    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
Пример #2
0
def test(methodname, input, output, *args):
    global tested_methods
    tested_methods[methodname] = 1
    if verbose:
        print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))),
    u = UserString(input)
    objects = [input, u, UserString(u)]
    res = [""] * 3
    for i in range(3):
        object = objects[i]
        try:
            f = getattr(object, methodname)
        except AttributeError:
            f = None
            res[i] = AttributeError
        else:
            try:
                res[i] = apply(f, args)
            except:
                res[i] = sys.exc_type
    if res[0] == res[1] == res[2] == output:
        if verbose:
            print 'yes'
    else:
        if verbose:
            print 'no'
        print (methodname, input, output, args, res[0], res[1], res[2])

string_tests.run_method_tests(test)
Пример #3
0
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)
Пример #4
0
#!/usr/bin/env python
import sys
from test_support import verbose
import string_tests
# UserString is a wrapper around the native builtin string type.
# UserString instances should behave similar to builtin string objects.
# The test cases were in part derived from 'test_string.py'.
from UserString import UserString
if __name__ == "__main__":
    verbose = 0
tested_methods = {}
def test(methodname, input, *args):
    global tested_methods
    tested_methods[methodname] = 1
    if verbose:
        print '%s.%s(%s) ' % (input, methodname, args),
    u = UserString(input)
    objects = [input, u, UserString(u)]
    res = [""] * 3
    for i in range(3):
        object = objects[i]
        try:
            f = getattr(object, methodname)
            res[i] = apply(f, args)
        except:
            res[i] = sys.exc_type
    if res[0] != res[1]:
        if verbose:
            print 'no'
        print `input`, f, `res[0]`, "<>", `res[1]`
Пример #5
0
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'