(self)
| 328 | self.assertRaises(ValueError, i.index, j) |
| 329 | |
| 330 | def test_rindex(self): |
| 331 | self.checkequal(12, 'abcdefghiabc', 'rindex', '') |
| 332 | self.checkequal(3, 'abcdefghiabc', 'rindex', 'def') |
| 333 | self.checkequal(9, 'abcdefghiabc', 'rindex', 'abc') |
| 334 | self.checkequal(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1) |
| 335 | |
| 336 | self.checkraises(ValueError, 'abcdefghiabc', 'rindex', 'hib') |
| 337 | self.checkraises(ValueError, 'defghiabc', 'rindex', 'def', 1) |
| 338 | self.checkraises(ValueError, 'defghiabc', 'rindex', 'abc', 0, -1) |
| 339 | self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, 8) |
| 340 | self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, -1) |
| 341 | |
| 342 | # to check the ability to pass None as defaults |
| 343 | self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a') |
| 344 | self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4) |
| 345 | self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6) |
| 346 | self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None) |
| 347 | self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6) |
| 348 | |
| 349 | self.checkraises(TypeError, 'hello', 'rindex') |
| 350 | |
| 351 | if self.contains_bytes: |
| 352 | self.checkraises(ValueError, 'hello', 'rindex', 42) |
| 353 | else: |
| 354 | self.checkraises(TypeError, 'hello', 'rindex', 42) |
| 355 | |
| 356 | # For a variety of combinations, |
| 357 | # verify that str.rindex() matches __contains__ |
| 358 | # and that the found substring is really at that location |
| 359 | teststrings = self._get_teststrings(['', 'a', 'b', 'c'], 5) |
| 360 | for i in teststrings: |
| 361 | for j in teststrings: |
| 362 | if j in i: |
| 363 | loc = i.rindex(j) |
| 364 | self.assertGreaterEqual(loc, 0) |
| 365 | self.assertEqual(i[loc:loc+len(j)], j) |
| 366 | else: |
| 367 | self.assertRaises(ValueError, i.rindex, j) |
| 368 | |
| 369 | def test_find_periodic_pattern(self): |
| 370 | """Cover the special path for periodic patterns.""" |
nothing calls this directly
no test coverage detected