mirror of https://github.com/python/cpython.git
[3.11] gh-110160: Fix flaky `test_find_periodic_pattern` in `string_tests` (… (#110183)
gh-110160: Fix flaky `test_find_periodic_pattern` in `string_tests` (#110170)
(cherry picked from commit 06faa9a39b
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
0914b13ba5
commit
86084d001f
|
@ -327,11 +327,12 @@ def reference_find(p, s):
|
||||||
for i in range(len(s)):
|
for i in range(len(s)):
|
||||||
if s.startswith(p, i):
|
if s.startswith(p, i):
|
||||||
return i
|
return i
|
||||||
|
if p == '' and s == '':
|
||||||
|
return 0
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
rr = random.randrange
|
def check_pattern(rr):
|
||||||
choices = random.choices
|
choices = random.choices
|
||||||
for _ in range(1000):
|
|
||||||
p0 = ''.join(choices('abcde', k=rr(10))) * rr(10, 20)
|
p0 = ''.join(choices('abcde', k=rr(10))) * rr(10, 20)
|
||||||
p = p0[:len(p0) - rr(10)] # pop off some characters
|
p = p0[:len(p0) - rr(10)] # pop off some characters
|
||||||
left = ''.join(choices('abcdef', k=rr(2000)))
|
left = ''.join(choices('abcdef', k=rr(2000)))
|
||||||
|
@ -341,6 +342,13 @@ def reference_find(p, s):
|
||||||
self.checkequal(reference_find(p, text),
|
self.checkequal(reference_find(p, text),
|
||||||
text, 'find', p)
|
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_shift_table_overflow(self):
|
def test_find_shift_table_overflow(self):
|
||||||
"""When the table of 8-bit shifts overflows."""
|
"""When the table of 8-bit shifts overflows."""
|
||||||
N = 2**8 + 100
|
N = 2**8 + 100
|
||||||
|
|
Loading…
Reference in New Issue