diff options
Diffstat (limited to 'Lib/test/string_tests.py')
| -rw-r--r-- | Lib/test/string_tests.py | 31 | 
1 files changed, 29 insertions, 2 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)  | 
