File size: 736 Bytes
8c3e275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from unittest.mock import MagicMock

import pytest


@pytest.fixture
def mock_search(monkeypatch: pytest.MonkeyPatch):
    mock_store = MagicMock()
    mock_store.get_records.return_value = [
        {"id": 1, "type": "task", "content": "Buy milk", "priority": "high"},
        {"id": 2, "type": "task", "content": "Walk dog", "priority": "low"},
    ]
    monkeypatch.setattr("pageparse.search.Store", lambda: mock_store)

    from pageparse.search import SemanticSearch

    return SemanticSearch()


def test_search_returns_results(mock_search):
    results = mock_search.search("milk")
    assert len(results) == 2


def test_search_top_k(mock_search):
    results = mock_search.search("milk", top_k=1)
    assert len(results) == 1