summaryrefslogtreecommitdiffstats
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-10-01 20:43:57 (GMT)
committerGitHub <noreply@github.com>2023-10-01 20:43:57 (GMT)
commit86084d001f3b4ecc1892fd05bb0626db0228c3cc (patch)
tree36205e222838df72156aae9f991c1a7b3a27e3d2 /Lib/test/string_tests.py
parent0914b13ba5f216e79341430a4fb6d2f2e04bdce8 (diff)
downloadcpython-86084d001f3b4ecc1892fd05bb0626db0228c3cc.zip
cpython-86084d001f3b4ecc1892fd05bb0626db0228c3cc.tar.gz
cpython-86084d001f3b4ecc1892fd05bb0626db0228c3cc.tar.bz2
[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 06faa9a39bd93c5e7999d52b52043ecdd0774dac) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index d69edd7..fdced1c 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -327,11 +327,12 @@ class BaseTest:
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)))
@@ -341,6 +342,13 @@ class BaseTest:
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_shift_table_overflow(self):
"""When the table of 8-bit shifts overflows."""
N = 2**8 + 100