Closed as duplicate of#110160
Description
A recent test failure:
FAIL: test_find_periodic_pattern (test.test_bytes.ByteArrayAsStringTest.test_find_periodic_pattern) (p='', text='')
Cover the special path for periodic patterns.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/string_tests.py", line 335, in test_find_periodic_pattern
self.checkequal(reference_find(p, text),
File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/string_tests.py", line 60, in checkequal
self.assertEqual(
AssertionError: -1 != 0
The issue is reference_find
:
def reference_find(p, s):
for i in range(len(s)):
if s.startswith(p, i):
return i
return -1
When s == p == ''
, we get for i in range(0)
, and then -1
is returned instead of the actual result which should be 0.