summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/string_tests.py31
-rw-r--r--Lib/test/test_unicode.py5
2 files changed, 33 insertions, 3 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index caff3d4..988372d 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -230,6 +230,31 @@ class CommonTest(unittest.TestCase):
self.checkraises(TypeError, 'hello', 'rfind')
self.checkraises(TypeError, 'hello', 'rfind', 42)
+ # For a variety of combinations,
+ # verify that str.rfind() matches __contains__
+ # and that the found substring is really at that location
+ charset = ['', 'a', 'b', 'c']
+ digits = 5
+ base = len(charset)
+ teststrings = set()
+ for i in xrange(base ** digits):
+ entry = []
+ for j in xrange(digits):
+ i, m = divmod(i, base)
+ entry.append(charset[m])
+ teststrings.add(''.join(entry))
+ teststrings = list(teststrings)
+ for i in teststrings:
+ i = self.fixtype(i)
+ for j in teststrings:
+ loc = i.rfind(j)
+ r1 = (loc != -1)
+ r2 = j in i
+ if r1 != r2:
+ self.assertEqual(r1, r2)
+ if loc != -1:
+ self.assertEqual(i[loc:loc+len(j)], j)
+
def test_index(self):
self.checkequal(0, 'abcdefghiabc', 'index', '')
self.checkequal(3, 'abcdefghiabc', 'index', 'def')
@@ -686,8 +711,10 @@ class CommonTest(unittest.TestCase):
EQ("bobobXbobob", "bobobobXbobobob", "replace", "bobob", "bob")
EQ("BOBOBOB", "BOBOBOB", "replace", "bob", "bobby")
- ba = buffer('a')
- bb = buffer('b')
+ # Silence Py3k warning
+ with test_support.check_warnings():
+ ba = buffer('a')
+ bb = buffer('b')
EQ("bbc", "abc", "replace", ba, bb)
EQ("aac", "abc", "replace", bb, ba)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 31bceb3..d67a2e1 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -499,9 +499,12 @@ class UnicodeTest(
)
if not sys.platform.startswith('java'):
+ # Silence Py3k warning
+ with test_support.check_warnings():
+ buf = buffer('character buffers are decoded to unicode')
self.assertEqual(
unicode(
- buffer('character buffers are decoded to unicode'),
+ buf,
'utf-8',
'strict'
),