Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-110160: Fix flaky test_find_periodic_pattern in string_tests (G…
…H-110170)

(cherry picked from commit 06faa9a)

Co-authored-by: Nikita Sobolev <[email protected]>
  • Loading branch information
sobolevn authored and miss-islington committed Oct 1, 2023
commit 6fe637884b55f0b1fde0e43fda55d01f8c1274e6
14 changes: 11 additions & 3 deletions Lib/test/string_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,12 @@ def reference_find(p, s):
for i in range(len(s)):
if s.startswith(p, i):
return i
if p == '' and s == '':
return 0
return -1

rr = random.randrange
choices = random.choices
for _ in range(1000):
def check_pattern(rr):
choices = random.choices
p0 = ''.join(choices('abcde', k=rr(10))) * rr(10, 20)
p = p0[:len(p0) - rr(10)] # pop off some characters
left = ''.join(choices('abcdef', k=rr(2000)))
Expand All @@ -341,6 +342,13 @@ def reference_find(p, s):
self.checkequal(reference_find(p, text),
text, 'find', p)

rr = random.randrange
for _ in range(1000):
check_pattern(rr)

# Test that empty string always work:
check_pattern(lambda *args: 0)

def test_find_many_lengths(self):
haystack_repeats = [a * 10**e for e in range(6) for a in (1,2,5)]
haystacks = [(n, self.fixtype("abcab"*n + "da")) for n in haystack_repeats]
Expand Down