Skip to content

gh-160501: Cover the UCS4 adaptive search path in test_str - #160502

Open
scrieve wants to merge 1 commit into
python:mainfrom
scrieve:gh-160501-adaptive-ucs4
Open

scrieve wants to merge 1 commit into
python:mainfrom
scrieve:gh-160501-adaptive-ucs4

Conversation

@scrieve

@scrieve scrieve commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Adds a test beside test_find in Lib/test/test_str.py that drives the
adaptive search path with non-BMP characters.

Objects/stringlib/fastsearch.h compiles adaptive_find once per character
width, and only the ASCII and UCS1 copies ran under the whole suite:

Function 'ucs4lib_adaptive_find'   Lines executed:0.00% of 39
Function 'ucs2lib_adaptive_find'   Lines executed:66.67% of 39
Function 'ucs1lib_adaptive_find'   Lines executed:71.79% of 39
Function 'asciilib_adaptive_find'  Lines executed:79.49% of 39

The adaptive branch needs a haystack of at least 2500 characters, a needle of at
least 100, and a needle at least a third of the haystack. test_adaptive_find
meets all three with 'a' and 'b', so the UCS4 instantiation stayed cold.

The new test repeats that shape with '\U0001d11e' and '\U0001d11f', checking
both a miss and a hit, through find and count. With it,
ucs4lib_adaptive_find goes from 0.00% to 89.74% of 39 lines; the branches left
are the count and reverse-search modes, which are separate entry points and are
covered elsewhere.

Test-only change, no behaviour change, so no NEWS entry.

./python -m test test_str -m "*adaptive*" passes. The new test adds about
0.85 s to test_str on a -O0 --coverage build, which is slower than a normal
one; the whole module runs in roughly 14 s there.

@bedevere-app

bedevere-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@scrieve

scrieve commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

No NEWS entry needed here: the guide lists "test changes" as exempt in "Changes that require NEWS entries" (devguide, pull-request-lifecycle). This PR only adds a test.

@scrieve

scrieve commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

The ASan job fails in test_profiling, not in anything this PR touches:

FAIL: test_sampling_with_collapsed_export (...)
AssertionError: ':' not found in '<unreadable frame>'

That is the same assertion and the same line as gh-160334, which records it as an ASan-only flake: since gh-154194 the profiler degrades a frame it cannot read to <unreadable frame> with no location, so the collapsed export line carries no colon. gh-160542 is already working on the profiler checks.

This PR only adds coverage in test_str for the UCS4 adaptive search path, so it is unrelated. I cannot rerun the job from a fork, so a maintainer rerun or gh-160542 landing should clear it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants