2000-04-03 00:51:50 -03:00
|
|
|
#!/usr/bin/env python
|
2001-02-09 08:00:47 -04:00
|
|
|
import sys
|
2002-07-23 16:04:11 -03:00
|
|
|
from test.test_support import verbose
|
|
|
|
from test import string_tests
|
2000-04-03 00:51:50 -03:00
|
|
|
# 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__":
|
2002-04-12 13:25:39 -03:00
|
|
|
verbose = '-v' in sys.argv
|
2000-04-03 00:51:50 -03:00
|
|
|
|
|
|
|
tested_methods = {}
|
|
|
|
|
2002-04-12 13:25:39 -03:00
|
|
|
def test(methodname, input, output, *args):
|
2000-04-03 00:51:50 -03:00
|
|
|
global tested_methods
|
|
|
|
tested_methods[methodname] = 1
|
|
|
|
if verbose:
|
2002-04-12 13:25:39 -03:00
|
|
|
print '%r.%s(%s)' % (input, methodname, ", ".join(map(repr, args))),
|
2000-04-03 00:51:50 -03:00
|
|
|
u = UserString(input)
|
|
|
|
objects = [input, u, UserString(u)]
|
|
|
|
res = [""] * 3
|
|
|
|
for i in range(3):
|
|
|
|
object = objects[i]
|
|
|
|
try:
|
|
|
|
f = getattr(object, methodname)
|
2002-04-12 13:25:39 -03:00
|
|
|
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:
|
2000-04-03 00:51:50 -03:00
|
|
|
if verbose:
|
|
|
|
print 'yes'
|
|
|
|
else:
|
|
|
|
if verbose:
|
2002-04-12 13:25:39 -03:00
|
|
|
print 'no'
|
|
|
|
print (methodname, input, output, args, res[0], res[1], res[2])
|
2000-04-03 00:51:50 -03:00
|
|
|
|
2000-07-10 14:08:42 -03:00
|
|
|
string_tests.run_method_tests(test)
|