[Python-checkins] python/dist/src/Lib/test test_unicode.py,1.47.6.4,1.47.6.5
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Mon, 23 Sep 2002 13:49:45 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv29535
Modified Files:
Tag: release22-maint
test_unicode.py
Log Message:
Backport 1.56 and 1.68 from trunk:
1.56:
Apply diff3.txt from SF patch http://www.python.org/sf/536241
If a str or unicode method returns the original object,
make sure that for str and unicode subclasses the original
will not be returned.
This should prevent SF bug http://www.python.org/sf/460020
from reappearing.
1.68:
Fix SF bug 599128, submitted by Inyeol Lee: .replace() would do the
wrong thing for a unicode subclass when there were zero string
replacements. The example given in the SF bug report was only one way
to trigger this; replacing a string of length >= 2 that's not found is
another. The code would actually write outside allocated memory if
replacement string was longer than the search string.
Index: test_unicode.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_unicode.py,v
retrieving revision 1.47.6.4
retrieving revision 1.47.6.5
diff -C2 -d -r1.47.6.4 -r1.47.6.5
*** test_unicode.py 20 Aug 2002 16:57:56 -0000 1.47.6.4
--- test_unicode.py 23 Sep 2002 20:49:43 -0000 1.47.6.5
***************
*** 51,54 ****
--- 51,73 ----
else:
exc = None
+ if value == output and type(value) is type(output):
+ # if the original is returned make sure that
+ # this doesn't happen with subclasses
+ if value is input:
+ class usub(unicode):
+ def __repr__(self):
+ return 'usub(%r)' % unicode.__repr__(self)
+ input = usub(input)
+ try:
+ f = getattr(input, method)
+ value = apply(f, args)
+ except:
+ value = sys.exc_type
+ exc = sys.exc_info()[:2]
+ if value is input:
+ if verbose:
+ print 'no'
+ print '*',f, `input`, `output`, `value`
+ return
if value != output or type(value) is not type(output):
if verbose:
***************
*** 187,190 ****
--- 206,211 ----
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
+ test('replace', u'abc', u'abc', u'ab', u'--', 0)
+ test('replace', u'abc', u'abc', u'xy', u'--')
test('startswith', u'hello', 1, u'he')