| 1 |
From: Bénédikt Tran <[email protected]> |
| 2 |
Date: Sun, 7 Jun 2026 11:49:11 +0200 |
| 3 |
Subject: Fix `test_search.py` with long-word splitting (#14474) |
| 4 |
|
| 5 |
(cherry picked from commit c01b0eb640bbc3dbd8141f3ea08df9edaa78ab2c) |
| 6 |
--- |
| 7 |
tests/roots/test-search/index.rst | 1 + |
| 8 |
tests/test_search.py | 7 ++++++- |
| 9 |
2 files changed, 7 insertions(+), 1 deletion(-) |
| 10 |
|
| 11 |
diff --git a/tests/roots/test-search/index.rst b/tests/roots/test-search/index.rst |
| 12 |
index b38fd02..c618633 100644 |
| 13 |
--- a/tests/roots/test-search/index.rst |
| 14 |
+++ b/tests/roots/test-search/index.rst |
| 15 |
@@ -19,6 +19,7 @@ International |
| 16 |
|
| 17 |
.. tip:: |
| 18 |
:class: no-search |
| 19 |
+ |
| 20 |
bat cat |
| 21 |
|
| 22 |
.. toctree:: |
| 23 |
diff --git a/tests/test_search.py b/tests/test_search.py |
| 24 |
index f94ae98..64ec467 100644 |
| 25 |
--- a/tests/test_search.py |
| 26 |
+++ b/tests/test_search.py |
| 27 |
@@ -76,6 +76,11 @@ def is_registered_term(index: Any, keyword: str) -> bool: |
| 28 |
return index['terms'].get(keyword, []) != [] |
| 29 |
|
| 30 |
|
| 31 |
+def is_registered_prefix(index: Any, prefix: str) -> bool: |
| 32 |
+ terms = index['terms'] |
| 33 |
+ return any(k.startswith(prefix) and v != [] for k, v in terms.items()) |
| 34 |
+ |
| 35 |
+ |
| 36 |
FILE_CONTENTS = """\ |
| 37 |
section_title |
| 38 |
============= |
| 39 |
@@ -144,7 +149,7 @@ def test_stemmer(app: SphinxTestApp) -> None: |
| 40 |
searchindex = load_searchindex(app.outdir / 'searchindex.js') |
| 41 |
print(searchindex) |
| 42 |
assert is_registered_term(searchindex, 'findthisstemmedkey') |
| 43 |
- assert is_registered_term(searchindex, 'intern') |
| 44 |
+ assert is_registered_prefix(searchindex, 'intern') |
| 45 |
|
| 46 |
|
| 47 |
@pytest.mark.sphinx('html', testroot='search') |