Chore: Move the search tests onto the shared indexing fixtures (#14159)

This commit is contained in:
Trenton H authored and GitHub committed 2026-09-17 14:55:13 -07:00
1 parent 20d309a413
commit fdd32b73bb
24 files changed
+410 -606

No files matched your search

+8 -14
View File
@@ -7,22 +7,16 @@ negated leaf keeps its CJK side while losing its fuzzy one.
from __future__ import annotations
import pytest
import whoosh_compat as wc
import whoosh_compat.ast as wc_ast
from documents.search._query import _cjk_alternative
from documents.search._query import _fuzzy_alternative
from documents.search._query import _widen_leaf
from documents.tests.search._ast_helpers import NOTES
from documents.tests.search._ast_helpers import content
pytestmark = pytest.mark.search
_CONTENT = wc.FieldRef("content")
_NOTES = wc.FieldRef("notes", "note")
def _content(text: str) -> wc_ast.Term:
return wc_ast.Term(field=_CONTENT, text=text)
def _widen(
leaf: wc_ast.Term,
@@ -44,7 +38,7 @@ class TestWhichAlternativesAreAdded:
- The Or holds the leaf and the boosted fuzzy alternative,
and nothing else
"""
leaf = _content("invoice")
leaf = content("invoice")
assert _widen(leaf) == wc_ast.Or(
children=(
@@ -63,7 +57,7 @@ class TestWhichAlternativesAreAdded:
- Only the bigram alternative is added, which is exactly what
the CJK work shipped
"""
leaf = _content("東京")
leaf = content("東京")
assert _widen(leaf, fuzzy=False) == wc_ast.Or(
children=(leaf, _cjk_alternative(leaf)),
@@ -81,7 +75,7 @@ class TestWhichAlternativesAreAdded:
any run within one edit of its start, and _cjk_alternative
already supplies the in-run recall
"""
leaf = _content("東京")
leaf = content("東京")
assert _fuzzy_alternative(leaf) is None
assert _widen(leaf) == wc_ast.Or(children=(leaf, _cjk_alternative(leaf)))
@@ -97,7 +91,7 @@ class TestWhichAlternativesAreAdded:
NOT X should exclude what X matches, which needs the bigram
side, but prefix fuzzy matching would exclude far more
"""
leaf = _content("東京")
leaf = content("東京")
assert _widen(leaf, negated=frozenset({id(leaf)})) == wc_ast.Or(
children=(leaf, _cjk_alternative(leaf)),
@@ -113,7 +107,7 @@ class TestWhichAlternativesAreAdded:
- The leaf itself comes back. It qualifies for no alternative
at all, so there is no Or to build
"""
leaf = _content("tax")
leaf = content("tax")
assert _widen(leaf, negated=frozenset({id(leaf)})) is leaf
@@ -128,6 +122,6 @@ class TestWhichAlternativesAreAdded:
- The leaf comes back untouched. Widening is scoped to the
default search fields, as it was for CJK
"""
leaf = wc_ast.Term(field=_NOTES, text="invoice")
leaf = wc_ast.Term(field=NOTES, text="invoice")
assert _widen(leaf) is leaf