fix: resolve CI test failures - API compatibility fixes
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
"""Tests for search module."""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
@@ -11,13 +9,11 @@ from snip.search import SearchEngine
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def search_engine():
|
def search_engine():
|
||||||
"""Create search engine with in-memory database."""
|
|
||||||
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
|
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f:
|
||||||
db_path = f.name
|
db_path = f.name
|
||||||
db = Database(db_path)
|
db = Database(db_path)
|
||||||
db.init_schema()
|
db.init_schema()
|
||||||
engine = SearchEngine(db_path)
|
engine = SearchEngine(db_path)
|
||||||
|
|
||||||
db.create_snippet(
|
db.create_snippet(
|
||||||
title="Python Hello World",
|
title="Python Hello World",
|
||||||
code="print('hello')",
|
code="print('hello')",
|
||||||
@@ -39,57 +35,50 @@ def search_engine():
|
|||||||
language="python",
|
language="python",
|
||||||
tags=["python", "advanced"],
|
tags=["python", "advanced"],
|
||||||
)
|
)
|
||||||
|
|
||||||
yield engine
|
yield engine
|
||||||
|
db.close()
|
||||||
os.unlink(db_path)
|
os.unlink(db_path)
|
||||||
|
|
||||||
|
|
||||||
def test_basic_search(search_engine):
|
def test_basic_search(search_engine):
|
||||||
"""Test basic full-text search."""
|
|
||||||
results = search_engine.search("hello")
|
results = search_engine.search("hello")
|
||||||
assert len(results) == 2
|
assert len(results) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_search_with_language_filter(search_engine):
|
def test_search_with_language_filter(search_engine):
|
||||||
"""Test search with language filter."""
|
|
||||||
results = search_engine.search("hello", language="python")
|
results = search_engine.search("hello", language="python")
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
assert results[0]["language"] == "python"
|
assert results[0]["language"] == "python"
|
||||||
|
|
||||||
|
|
||||||
def test_search_with_tag_filter(search_engine):
|
def test_search_with_tag_filter(search_engine):
|
||||||
"""Test search with tag filter."""
|
|
||||||
results = search_engine.search("*", tag="python")
|
results = search_engine.search("*", tag="python")
|
||||||
assert len(results) == 2
|
assert len(results) == 2
|
||||||
|
|
||||||
|
|
||||||
def test_search_no_query_returns_all(search_engine):
|
def test_search_no_query_returns_all(search_engine):
|
||||||
"""Test that empty search returns all snippets."""
|
|
||||||
results = search_engine.search("")
|
results = search_engine.search("")
|
||||||
assert len(results) == 3
|
assert len(results) == 3
|
||||||
|
|
||||||
|
|
||||||
def test_highlight_matches(search_engine):
|
def test_highlight_matches(search_engine):
|
||||||
"""Test match highlighting."""
|
|
||||||
text = "This is a hello world example"
|
text = "This is a hello world example"
|
||||||
highlighted = search_engine.highlight(text, "hello world")
|
highlighted = search_engine.highlight_matches(text, "hello world")
|
||||||
assert "**" in highlighted
|
assert "**" in highlighted
|
||||||
|
|
||||||
|
|
||||||
def test_parse_query(search_engine):
|
def test_parse_query(search_engine):
|
||||||
"""Test query parsing."""
|
|
||||||
parsed = search_engine.parse_query("hello AND world")
|
parsed = search_engine.parse_query("hello AND world")
|
||||||
assert len(parsed["terms"]) >= 1
|
assert len(parsed["terms"]) >= 1
|
||||||
|
assert parsed["raw"] == "hello AND world"
|
||||||
|
|
||||||
|
|
||||||
def test_suggest_completions(search_engine):
|
def test_suggest_completions(search_engine):
|
||||||
"""Test tag autocomplete."""
|
suggestions = search_engine.suggest_completions("pyt")
|
||||||
suggestions = search_engine.suggest("pyt")
|
|
||||||
assert "python" in suggestions
|
assert "python" in suggestions
|
||||||
|
|
||||||
|
|
||||||
def test_empty_query_with_filters(search_engine):
|
def test_empty_query_with_filters(search_engine):
|
||||||
"""Test empty query with filters still applies filters."""
|
|
||||||
results = search_engine.search("", language="javascript")
|
results = search_engine.search("", language="javascript")
|
||||||
assert len(results) == 1
|
assert len(results) == 1
|
||||||
assert results[0]["language"] == "javascript"
|
assert results[0]["language"] == "javascript"
|
||||||
Reference in New Issue
Block a user