mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-19 01:03:18 +00:00
test(search): promote query_index to a single module-scoped fixture
Three classes in test_query.py each defined an identical query_index fixture. None of these tests write documents to the index, so consolidate into one module-level, module-scoped fixture (mirroring conftest.py's index fixture rationale) instead of three copies to keep in sync. Deliberately NOT merged with conftest.py's own index fixture: that one registers tokenizers with "english" (stemming on), while these tests rely on "" (stemming off) - a real behavioral difference, not incidental.
This commit is contained in:
@@ -24,16 +24,19 @@ if TYPE_CHECKING:
|
||||
pytestmark = pytest.mark.search
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def query_index() -> tantivy.Index:
|
||||
"""An in-memory, unstemmed index shared read-only across this module's
|
||||
parse-only tests (none of them index documents)."""
|
||||
schema = build_schema()
|
||||
idx = tantivy.Index(schema, path=None)
|
||||
register_tokenizers(idx, "")
|
||||
return idx
|
||||
|
||||
|
||||
class TestParseUserQuery:
|
||||
"""parse_user_query runs the full preprocessing pipeline."""
|
||||
|
||||
@pytest.fixture
|
||||
def query_index(self) -> tantivy.Index:
|
||||
schema = build_schema()
|
||||
idx = tantivy.Index(schema, path=None)
|
||||
register_tokenizers(idx, "")
|
||||
return idx
|
||||
|
||||
def test_returns_tantivy_query(self, query_index: tantivy.Index) -> None:
|
||||
assert isinstance(parse_user_query(query_index, "invoice", UTC), tantivy.Query)
|
||||
|
||||
@@ -156,13 +159,6 @@ class TestParseUserQuery:
|
||||
class TestParseSimpleTextHighlightQuery:
|
||||
"""parse_simple_text_highlight_query must not raise on natural-language queries."""
|
||||
|
||||
@pytest.fixture
|
||||
def query_index(self) -> tantivy.Index:
|
||||
schema = build_schema()
|
||||
idx = tantivy.Index(schema, path=None)
|
||||
register_tokenizers(idx, "")
|
||||
return idx
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"raw_query",
|
||||
[
|
||||
@@ -333,13 +329,6 @@ class TestEmitErrorContract:
|
||||
SearchQueryError (HTTP 400), with library-internal wording stripped
|
||||
from the message."""
|
||||
|
||||
@pytest.fixture
|
||||
def query_index(self) -> tantivy.Index:
|
||||
schema = build_schema()
|
||||
idx = tantivy.Index(schema, path=None)
|
||||
register_tokenizers(idx, "")
|
||||
return idx
|
||||
|
||||
def test_query_emit_error_maps_to_search_query_error(
|
||||
self,
|
||||
query_index: tantivy.Index,
|
||||
|
||||
Reference in New Issue
Block a user